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
Running up against what might be a bug in the VB API when using Excel.
This is simply trying to get the PTC-provided example listSubAssemblyComponent to function in Excel VBA rather than its original VB. I intended to make this the basis of code to extract the model tree into an Excel spreadsheet for internal engineering management purposes - old way we do this is to save the model tree from Creo, and import it into a spreadsheet via VBA macros, but I want a more streamlined way to do it. (This ain't necessarily it, and I'm open to better alternatives.)
It appears to allocate something to currentPath (typing ?currentPath is Nothing in the immediate window returns false). But it hangs up every time on the line with currentPath.Leaf, returning the message:
Run-time error '-2147352567 (80020009)':
pfcExceptions::XToolkitGeneral Error
I don't see any useful explanation of this error. I've fiddled around with everything I can think up on how to get around it, but I'm starting to believe it's a bug or else something available in VB but not VBA for some reason.
Ideas? What am I missing?
Sub listSubAssemblyComponent(ByVal currentLevel As Cintseq)
'======================================================================
'Function : listEachLeafComponent
'Purpose : This function This method is used to recursively visit
' all levels of the assembly structure.
'======================================================================
Dim currentComponent As IpfcSolid
Dim currentPath As IpfcComponentPath
Dim level As Integer
Dim subComponents As IpfcFeatures
Dim i, id As Integer
Dim componentFeat As IpfcFeature
level = currentLevel.Count
Set currentPath = Nothing
Dim dummyModel As IpfcModel
'======================================================================
'Special case, level is 0 for the top level assembly.
'======================================================================
If (level > 0) Then
Set muhAssy1 = New CMpfcAssembly ' *** original PTC VB code had this step inline with currentPath, but that won't work with Excel VBA
Set currentPath = muhAssy1.CreateComponentPath(asm, currentLevel) ' *** was originally = (New CMpfcAssembly).CreateComponentPath(asm, currentLevel)
Set currentComponent = currentPath.Leaf ' *** this is where the failure occurs ***
Else
Set currentComponent = asm
End If
Set dummyModel = currentComponent ' *** as above, added this step because in Excel VBA, currentComponent's type (IpfcSolid) doesn't allow the .Type property)
If (dummyModel.Type = EpfcModelType.EpfcMDL_PART) And (level > 0) Then
' *** code below is original PTC example, just changed from VB to VBA syntax in Excel ***
pathArray.Add currentPath
Else
'==================================================================
'Find all component features in the current component object.
'Visit each (adjusting the component id paths accordingly).
'==================================================================
Set subComponents = currentComponent.ListFeaturesByType(True, EpfcFeatureType.EpfcFEATTYPE_COMPONENT)
For i = 0 To subComponents.Count - 1
Set componentFeat = subComponents.item(i)
id = componentFeat.Number
currentLevel.Set level, id
listSubAssemblyComponent currentLevel
Next
End If
'======================================================================
'Clean up current level of component ids before returning up one level.
'======================================================================
If Not level = 0 Then
currentLevel.Remove level - 1, level
End If
Return
End Sub