Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X
Hi, i've been trying to use ListFeaturesByType in VBA in Excel but didn't succeed.
Sub FixParts()
On Error GoTo Error
' put your code here
Dim model As IpfcModel
Set model = session.CurrentModel
'creating Fix Constraint
Dim constraint As IpfcComponentConstraint
Dim constructorOfConstraints As CCpfcComponentConstraint
Set constructorOfConstraints = New CCpfcComponentConstraint
Set constraint = constructorOfConstraints.Create(EpfcASM_CONSTRAINT_FIX)
'component path
Dim solid As IpfcSolid
Dim features As IpfcFeatures
solid = CType(model, IpfcSolid)
features = solid.ListFeaturesByType(True, EpfcFeatureType.EpfcFEATTYPE_COMPONENT)
'applying constraints
' end your code here
Done:
Exit Sub
Error:
Debug.Print Err.Description
conn.Disconnect (5)
Debug.Print "Disconnected"
End Sub
First thing. All examples that i've found using CType() function which is a converter from IpfcModel to IpfcSolid. But VBA doesn't have CType() functionality that's why it never succeeded.
How can i get IpfcSolid from IpfcModel and use ListFeaturesByType() function?
(whole purpose of this script is learing about functionaity of VBA API for Creo it has to apply fix constraint to each part in assembly)
Solved! Go to Solution.
Hello,
CType function is not supported in VBA. When you need to typecast to inherit methods you have use the line
set x = y
in your example, replace the line with CType with :
set solid = model
On the subject of method inheritance, it's a bit out of subject, but something I discovered that I think may be useful to know :
Some child class methods of IpfcModelItem that use ModelItem objects as input need that object NOT DECLARED (like no Dim)
I had this with trying to add items to a layer, the model item required in IpfcLayer.AddItem (ModelItem) needs to be set without being declared.
I hope this helps you, good luck with vba, I'm in the middle of learning it too 🙂
Laetitia M
I use Tcl, if your current model is an assembly this one code line will return all active Feature IDs if the feature is a Component :
set FIDS [ps_visit type COMPONENT]
Do you really want to do your requests in Excel?
If you later need the component name in the current assembly (Top Level) provide the Feature ID:
set MDL_NAME [ps_assy component $FID ]
Have Fun with VBA
Hello,
CType function is not supported in VBA. When you need to typecast to inherit methods you have use the line
set x = y
in your example, replace the line with CType with :
set solid = model
On the subject of method inheritance, it's a bit out of subject, but something I discovered that I think may be useful to know :
Some child class methods of IpfcModelItem that use ModelItem objects as input need that object NOT DECLARED (like no Dim)
I had this with trying to add items to a layer, the model item required in IpfcLayer.AddItem (ModelItem) needs to be set without being declared.
I hope this helps you, good luck with vba, I'm in the middle of learning it too 🙂
Laetitia M