Skip to main content
12-Amethyst
August 21, 2023
Question

EXCEL VBA

  • August 21, 2023
  • 1 reply
  • 3006 views

*** "IpfcAssembly.AssembleByCopy" *** ask for use
This function copies existing parts in assembly and automatically assembles new copied parts.

This is the code i made. there is an error
'///////////////////////////////////////////////////////////////////////////////////////////////////////

Dim Solid As IpfcSolid
Dim Assembly As IpfcAssembly
Dim ComponentFeat As IpfcComponentFeat


Dim CreateModelDescriptor As New CCpfcModelDescriptor
Dim ModelDescriptor As IpfcModelDescriptor

'// Load model from "rod_nut.prt" file into Session
Set ModelDescriptor = CreateModelDescriptor.CreateFromFileName("rod_nut.prt")
Set Solid = session.RetrieveModel(ModelDescriptor)


Set Assembly = model
Set ComponentFeat = Assembly.AssembleByCopy("C:\PTC\WORK90\JP100.PRT", Solid, True)

'///////////////////////////////////////////////////////////////////////////////////////////////////////
the code that gives the error

Set ComponentFeat = Assembly.AssembleByCopy("C:\PTC\WORK90\JP100.PRT", Solid, True)

please correct

e-mail : korealionkk@gmail.com 

 

 

 

 

1 reply

24-Ruby III
August 21, 2023

Try this one: `Set Assembly = Model`.

cko12-AmethystAuthor
12-Amethyst
August 22, 2023

This is the full vba code

'///////////////////////////////////////////////////////////////////////////////////////////////////////

Public asynconn As New pfcls.CCpfcAsyncConnection
Public conn As pfcls.IpfcAsyncConnection
Public session As pfcls.IpfcBaseSession
Public model As pfcls.IpfcModel


Sub model_session()
'// Displays the name of the model in the current session
Set conn = asynconn.Connect("", "", ".", 5)
Set session = conn.session
Set model = session.CurrentModel

On Error GoTo E01

If model Is Nothing Then

Err.Raise 5001, , "▶ No models are currently active ◀"

End If

Exit Sub

E01:

MsgBox "Error Number: " & Err.Number & vbNewLine & _
"Error Description: " & Err.Description
Err.Clear

End Sub

'///////////////////////////////////////////////////////////////////////////////////////////////////////

Sub componentcopy()

'// current session connection
file_name.model_session

Dim Solid As IpfcSolid
Dim Assembly As IpfcAssembly
Dim componentFeat As IpfcComponentFeat


Dim CreateModelDescriptor As New CCpfcModelDescriptor
Dim ModelDescriptor As IpfcModelDescriptor

'// Load model from "rod_nut.prt" file into Session
Set ModelDescriptor = CreateModelDescriptor.CreateFromFileName("rod_nut.prt")
Set Solid = session.RetrieveModel(ModelDescriptor)


Set Assembly = model
Set componentFeat = Assembly.AssembleByCopy("C:\PTC\WORK90\JP100.PRT", Solid, True)


'Cleanup
Set asynconn = Nothing
Set conn = Nothing
Set session = Nothing
Set model = Nothing


End Sub

'///////////////////////////////////////////////////////////////////////////////////////////////////////

 

 

Public model As pfcls.IpfcModel
Set model = session.CurrentModel
Dim Assembly As IpfcAssembly
Set Assembly = model

. The "model" variable holds information about the currently active assembler file
. Assigned "model" information to "Assembly" variable

Dim componentFeat As IpfcComponentFeat
Set componentFeat = Assembly.AssembleByCopy("C:\PTC\WORK90\JP100.PRT", Solid, True)

. I am getting an error in the code above
. "C:\PTC\WORK90\JP100.PRT", I also tried typing "JP100.PRT"
. I also tried changing the file name to lower case.
.  I am not a program development expert. I am making a simple program with the help of chatgtp.
   The creo vba code provided by chatgtp cannot be used. But I'll give you a hint.
.  mapkey cannot be configured with chatgtp  ^_^

please correct

e-mail : korealionkk@gmail.com 

17-Peridot
August 22, 2023

Assembly = CType(model, IpfcAssembly)

 

ps: some examples ..\Creo x.0.x.0\Common Files\vbapi\vbapi_examples