Continue to Site

Welcome to MCAD Central

Join our MCAD Central community forums, the largest resource for MCAD (Mechanical Computer-Aided Design) professionals, including files, forums, jobs, articles, calendar, and more.

Export model to STEP (CREO VBA API)

braynpower

New member
Hello,

So I am pulling my hairs out at the minute as I am incapable of getting my export command to work. I have copied and pasted methods from wherever I can find them... Thing is, nothing works, and there really isnt much information out there. Anyway, I have pasted a bit of my script below... basically, there is a syntax error, or an unset variable... God only knows...

The documentation says I have to call the 'Is x supported' things before making the export command, so I try do that... not sure I have that bit right either. Im taking pot shots in the dark here...

Is there a CREO VBA API mastermind out there who could lend me a hand? This is one of the final hurdles I am facing (there are a couple of other ones too... but hey, baby steps), and If I can get this to work, I would happily buy whoever works it out a beer!


Dim ICS As Boolean
Dim IGRS As Boolean
Dim GeoFlag As IpfcGeometryFlags
Dim Step3D As IpfcSTEP3DExportInstructions
Dim Export3D As IpfcExport3DInstructions
Dim Export As IpfcExportInstructions

Set GeoFlag = New CCpfcGeometryFlags

ICS = session.IsConfigurationSupported(EpfcExportType.EpfcEXPORT_STEP, EpfcAssemblyConfiguration.EpfcEXPORT_ASM_FLAT_FILE)

IGRS = session.IsGeometryRepSupported(EpfcExportType.EpfcEXPORT_STEP, GeoFlag)

GeoFlag.AsSolids = True

Set Step3D = New CCpfcSTEP3DExportInstructions
Set Export3D = Step3D
Set Export = Export3D

Model1.Export ("D:\AJBS\Script_Test\JBA_TEST.stp", export)
 
So I'm cleaning up my code, and understanding the things that work in VBA vs VB... Can be tricky... but basically i am still falling at the last hurdle.

Here is my updated code, which as far as i can see, is almost there...

but I cannot get the design.export("test.prt", xxxx) part of the code to finish... I get a compile error, or a missing = or any other result...

It's a right PITA... Doesn't anyone have a nugget of wisdom to impart...?



Dim Design As IpfcModel
Dim DDes As IpfcModelDescriptor
Dim cDDes As CCpfcModelDescriptor
Dim DesEx As IpfcExportInstructions
Dim Des3DEx As IpfcExport3DInstructions
Dim DesExStep As IpfcSTEP3DExportInstructions
Dim cDesExStep As CCpfcSTEP3DExportInstructions
Dim DesFlags As IpfcGeometryFlags
Dim cDesFlags As CCpfcGeometryFlags
Dim DesG As Boolean
Dim DesC As Boolean

Set cDDes = New CCpfcModelDescriptor
Set DDes = cDDes.Create(EpfcModelType.EpfcMDL_PART, "Design", "JBA_TEST")

session.OpenFile(DDes).Activate

Dim DesSolid As pfcls.IpfcSolid

If session.CurrentModel.Type = EpfcModelType.EpfcMDL_PART Then
Set DesSolid = session.CurrentModel
DesSolid.Regenerate (zero)

End If

Set Design = session.CurrentModel

Set cDesFlags = New CCpfcGeometryFlags
Set DesFlags = cDesFlags.Create

DesC = pfc.session.IsConfigurationSupported(EpfcExportType.EpfcEXPORT_STEP, EpfcAssemblyConfiguration.EpfcEXPORT_ASM_SINGLE_FILE)

DesG = pfc.session.IsGeometryRepSupported(EpfcExportType.EpfcEXPORT_STEP, DesFlags)
DesFlags.AsSolids = True

Set cDesExStep = New CCpfcSTEP3DExportInstructions
Set DesExStep = cDesExStep.Create(EpfcModelType.EpfcMDL_PART, DesFlags)
Set Des3DEx = DesExStep
Set DesEx = Des3DEx

-----What goes here?-----------

and then once this works it's beer o'clock...
 
Somehow this worked.... (so if you're struggling with it too, maybe it'll help... It is now officially beer o'clock).

Sub Button3_Click()

'-----------------------------------------------------------------------------------------------------
'------------------------------------ Connect to CREO-----------------------------------------------
'-----------------------------------------------------------------------------------------------------

Dim asyncConnection As IpfcAsyncConnection
Dim cAC As CCpfcAsyncConnection
Dim session As IpfcBaseSession

Set cAC = New CCpfcAsyncConnection
Set asyncConnection = cAC.Connect(dbnull, dbnull, dbnull, dbnull)
Set session = asyncConnection.session

'-----------------------------------------------------------------------------------------------------
'------------------------------------ Set Working Directory --------------------------------------
'-----------------------------------------------------------------------------------------------------
Dim Workdir As String


Workdir = ActiveWorkbook.FullName
position = InStrRev(Workdir, "\")
Workdir = Left(Workdir, position)

session.ChangeDirectory (Workdir)

'MsgBox ("Working Directory = " & Workdir)
'-----------------------------------------------------------------------------------------------------
'------------------------------------ Load Project Master --------------------------------------
'-----------------------------------------------------------------------------------------------------

'Dim MaDes As IpfcModelDescriptor
'Dim cMaDes As CCpfcModelDescriptor
'Dim MaModel As IpfcModel

'Set cMaDes = New CCpfcModelDescriptor
'Set MaDes = cMaDes.Create(EpfcModelType.EpfcMDL_PART, "JBA_TEST", "JBA_TEST")

'session.OpenFile(MaDes).Activate

Set MaModel = session.GetActiveModel

'MaModel.Copy ("Master.PRT")


'-----------------------------------------------------------------------------------------------------
'----------------------------------- Break to Design ------------------------------------------
'-----------------------------------------------------------------------------------------------------

Dim Design As IpfcModel
Dim DDes As IpfcModelDescriptor
Dim cDDes As CCpfcModelDescriptor
Dim DesEx As IpfcExportInstructions
Dim Des3DEx As IpfcExport3DInstructions
Dim DesExStep As IpfcSTEP3DExportInstructions
Dim cDesExStep As CCpfcSTEP3DExportInstructions
Dim DesFlags As IpfcGeometryFlags
Dim cDesFlags As CCpfcGeometryFlags
Dim DesG As Boolean
Dim DesC As Boolean

Set cDDes = New CCpfcModelDescriptor
Set DDes = cDDes.Create(EpfcModelType.EpfcMDL_ASSEMBLY, "HJBA", "HJBA")

session.OpenFile(DDes).Activate

Dim DesSolid As pfcls.IpfcSolid

If session.CurrentModel.Type = EpfcModelType.EpfcMDL_ASSEMBLY Then
Set DesSolid = session.CurrentModel
DesSolid.Regenerate (UpdateInstances)
DesSolid.Regenerate (zero)

End If

Set Design = session.CurrentModel

Set cDesFlags = New CCpfcGeometryFlags
Set DesFlags = cDesFlags.Create
DesFlags.AsSolids = True

DesC = session.IsConfigurationSupported(EpfcExportType.EpfcEXPORT_STEP, EpfcAssemblyConfiguration.EpfcEXPORT_ASM_MULTI_FILES)

MsgBox ("DesC = " & DesC)

DesG = session.IsGeometryRepSupported(EpfcExportType.EpfcEXPORT_STEP, DesFlags)

MsgBox ("DesG = " & DesG)

Set cDesExStep = New CCpfcSTEP3DExportInstructions
Set DesExStep = cDesExStep.Create(EpfcAssemblyConfiguration.EpfcEXPORT_ASM_MULTI_FILES, DesFlags)
Set Des3DEx = DesExStep
Set DesEx = Des3DEx

If session.CurrentModel.Type = EpfcModelType.EpfcMDL_ASSEMBLY Then
Set Design = session.CurrentModel
Design.export "d:\AJBS\Script_Test\Test.STP", DesEx
End If
 
Hello,

thx, the step export works!
I also want to export STL, but i dont get it running:
step3DIGES = (New CCpfcTriangulationInstructions).Create(0.5, 0.5) fails when i export it

and when i want to check the configuration i get a fail: not supported
tc = Session.IsConfigurationSupported(EpfcExportType.EpfcEXPORT_STL_BINARY, EpfcAssemblyConfiguration.EpfcEXPORT_ASM_FLAT_FILE)

Has anybody a working export for STL?

It would help a lot!
 

Sponsor

Articles From 3DCAD World

Back
Top