cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

EXCEL VBA

cko
12-Amethyst
12-Amethyst

EXCEL VBA

*** "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 

 

 

 

 

6 REPLIES 6
VladimirN
24-Ruby II
(To:cko)

Try this one: `Set Assembly = Model`.

cko
12-Amethyst
12-Amethyst
(To:VladimirN)

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 

YaroslavSin
17-Peridot
(To:cko)

Assembly = CType(model, IpfcAssembly)

 

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

cko
12-Amethyst
12-Amethyst
(To:YaroslavSin)

Assembly = CType(model, IpfcAssembly)

 - This is the VB.NET program code

C:\PTC\Creo 9.0.4.0\Common Files\vbapi\vbapi_examples
- This folder contains only VB.NET code.

EXCEL VBA code examples are not provided in the PTC folder

We hope that PTC has provided many EXCEL VBA example codes and functions. No separate compilation function is required. You can connect with the database through EXCEL. General EXCEL VBA code is created by ChatGTP. Anyone can easily create an automated one with EXCEL VBA

YaroslavSin
17-Peridot
(To:cko)


@cko wrote:

Assembly = CType(model, IpfcAssembly)

 - This is the VB.NET program code


Yes, you are correct! My mistake.

 

Take a look at me_Example.xls

I have a trouble to load a model using RetrieveModel. So need to open PRT manually and I'm use a method GetModelFromDescr to get a part from a session.

 

PS: I'm not sure that is possible to easily create an automation with ChatGPT. Need to understand the source code that you writing. Try to read "Overview of the VB API" chapter from VB API manual for better understanding.

cko
12-Amethyst
12-Amethyst
(To:YaroslavSin)

thank you
I'll test it

We are testing whether VB.NET files in C:\PTC\Creo 9.0.4.0\Common Files\vbapi\vbapi_examples can be converted from ChatGPT to EXCEL VBA code. CREO users who are interested in EXCEL VBA, try coding with ChatGPT

Announcements


Top Tags