Community Tip - You can change your system assigned username to something more personal in your community settings. X
Hi I need help with method on how to set drawing format (eg. a3_landscape.frm, a2_portrait.frm) via visual studio or excel.
Do I use IpfcSheetOwner.SetSheetFormat() ???
How would I use it?
Maybe an example with a button that when clicked would setup a current active session .drw file with a a2_portrait.frm format. That would help a lot
Thanks anyone.
Solved! Go to Solution.
Notice that the javascript example uses a different syntax when creating the model descriptor for the format:
var frmDescr = pfcCreate("pfcModelDescriptor").CreateFromFileName(frmName);
var format = session.RetrieveModel(frmDescr);
I was not able to get the pfcCreate method to work in my vb code for whatever reason....
Here is a vb.net sub i use for replacing the format in my active drawing:
Sub RepFormat(ByVal active_drawing As IpfcDrawing, ByVal NewFormatName As String, ByVal NewFormatSheetNo As Integer, ByVal sheetno As Integer
)
' Create model descriptor
Dim frmDescr As
IpfcModelDescriptor
frmDescr = (
New CCpfcModelDescriptor
).CreateFromFileName(NewFormatName)
Try
' Retrieve format
Dim format As
IpfcDrawingFormat
format = session.RetrieveModel(frmDescr)
'The sheet number of the format is specified by the FormatSheetNumber parameter. This number ranges from 1
'to the number of sheets in the format. Pass the value of this parameter as null to use the first format sheet.
' Replace format
active_drawing.SetSheetFormat(sheetno, format, NewFormatSheetNo,
Nothing
)
Catch ex As
Exception
MsgBox(ex.Message.ToString + Chr(13) + ex.StackTrace.ToString)
End
Try
End
Sub
Hi,
Thanks for the reply.This helps alot accept my program fails on
"frmDescr = (New CCpfcModelDescriptor).CreateFromFileName(NewFormatName)
Error message states: Unable to cast COM object of type 'System._ComObject' to class type 'System.Object[]'. Instances of types COM components cannot be cast to types that do not represent COM components; however they can be castto interface as long as the underlying COM components supports QueryInterface calls for the IID of the interface
For NewFormatName I set in to "a0_portrait.frm"
Any help why this happens?
Regards
Lourens du Toit
Hi
Are you sure that your vb.net project is set up correctly with in terms of references to the VB type library (com)?
Have you created other Creo vb applications that work on your PC?
Hugo
Hi,
Yes I'm busy writing a custom API for my company. About 10000 lines of code at this stage. verything works thus far.
I'm programming in Microsoft Visual Studio 2005.
On this form I'm able to create parts and drawings succesfuly already. I'm just not able to change the Format succesfully on active drawing file. I recon it's something simple.
If I set frmDescr like this to read the .frm file directly it should also work right?:
frmDescr = (New CCpfcModelDescriptor).CreateFromFileName("a3_portrait.frm")
Lourens
Yes, your code should work as long as it is able to find the format.
Make sure that the format is located in the folder specified in the "pro_format_dir" config.pro setting.
If not, then i think you need to use the full path.
Hugo
the pro_format_dir points to a central server location. The Format "a3_portrait.frm" is located in the folder. I was thinking that maybe because it is a central server location it is giving problems to access?
So then I tried setting a full path to a local location as follows:
frmDescr = (New CCpfcModelDescriptor).CreateFromFileName("C:\PTC\PLMapi\formats\a0_landscape.frm)"
It still gives me the same error. Would you be able to maybe test setting the full path to local location?
Is the full path string setup correctly?
Thanks for the help!!!
From looking at your error message i dont think the problem is related to finding the format.
Here is a link to a great document that talks about Creo programming and using formats.
The examples are done in Java script but you should be able to translate it to vb (as i did 🙂
http://inversionconsulting.blogspot.no/2009/10/proe-weblink-replace-drawing-formats.html
Notice that the javascript example uses a different syntax when creating the model descriptor for the format:
var frmDescr = pfcCreate("pfcModelDescriptor").CreateFromFileName(frmName);
var format = session.RetrieveModel(frmDescr);
I was not able to get the pfcCreate method to work in my vb code for whatever reason....
Oh my greatness!!!! I'm going to kick myself!!
I declared frmDescr as an Array as follows: Dim frmDescr As IpfcModelDescriptor
Well Visual studio added it for me somehow when I copied your script and I had to sort out the lines of code. So that was why I got that error message!!
Man I'm glad its working now!!!!
Thanks very much for your time and effort Hugo!!!!
Regards
Lourens du Toit
Hi Guys,
I need to change Drawing Sheet format Using VB.NET, I tried with below coding and I am getting error while "fdescr = (New CCpfcModelDescriptor)."
Please help to solve.
Coding:
If Not lmoddoc Is Nothing Then
Dim x As Integer
Dim sheets As Integer
Dim sheetdata As IpfcSheetData
Dim sheetformat As IpfcDrawingFormat
Dim drwonr As IpfcSheetOwner
Dim fdescr As IpfcModelDescriptor
Dim drw As pfcls.IpfcDrawing
Dim drwl As IpfcLayout
Dim bsession As IpfcBaseSession
Dim drawing As IpfcDrawing
lmoddoc.Display()
session.CurrentWindow.Activate()
model = session.CurrentModel
drawing = CType(model, IpfcDrawing)
fdescr = (New CCpfcModelDescriptor).CreateFromFileName("C:\Program Files\PTC\Creo 2.0\Common Files\F000\creo_standards\formats\a4_format.frm")
Dim fmt As IpfcDrawingFormat
fmt = session.RetrieveModel(fdescr)
drwonr = CType(drawing, IpfcSheetOwner)
drwonr.SetSheetFormat(1, fmt, 1, Nothing)
End If
Error: