Skip to main content
10-Marble
October 22, 2013
Solved

Creo API Set Drawing Format

  • October 22, 2013
  • 1 reply
  • 6754 views

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.

Best answer by huggre

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....

1 reply

1-Visitor
October 22, 2013

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

ldutoit10-MarbleAuthor
10-Marble
October 23, 2013

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

1-Visitor
October 23, 2013

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