Hi there,
With iLogic, for a Part, how can I retrieve/iterate all underlying feature items, like Sketches, Bends, Corners etc.?
Is it possible/necessary to loop the features recursively?
I know how to get/loop 'For each Object' things but don't know how to get them for that specific feature.
I'm trying to rename the Features, Sketches etc. in the order as they appear in the browser.
I've got:
Dim oFeature As PartFeature Dim oFeatures As PartFeatures oFeatures = ThisDoc.Document.ComponentDefinition.Features For Each oFeature In oFeatures oWrite.WriteLine(oFeature.Name) oFeature.Name = "Test " & oFeature.Name Next
Thanks in advance.
Hello
You can traverse each of these objects the same way you do with the features. Sketches have it's own node under the PartComponentDefinition.
Can you explain your naming scheme? Is it simple sketch01, sketch02, Bend01, Bend02, and so on or something different?
Thanks Krieg for your reaction,
I would like to use the standard 'Inventor' naming scheme like Sketch1, Sketch2, Bend1, Bend2 etc.
The 'only' thing I want is to do is order them numerically in case we used an old template which did not start at Solid1, Sketch1 etc. and/or in case you switched features in the orders to have it more logical.
When you traverse the Sketch object they appear in the order they were created, which is a bit difficult te rename them in the order they represent in the browser tree.
In my opinion, traverse each of these object means that they all needs to be called in the macro regardless of whether they exist or not.
That's why I would like to explore the feature to get the underlying features from them.
Greetings!
Please note that 'For-Each'-loops do NOT necessarily follow the order in which features have been placed. That's why they are usually faster than going through all features by using an index.
Please note that the feature order in the model browser is NOT necessarily the order in which they were added to the document (you can manually re-order them, within limits).
Hello
As far as I could see the features in ThisDoc.Document.ComponentDefinition.Features are in the same order as they appear in model browser and the order changed while re-order in model browser. The behaviour of sketches in ThisDoc.Document.ComponentDefinition.Sketches seems to be the same.
We can try to simpel rename the features while walking through indexed feature/sketch collection.
Because renaming fails if there is another feature with the same name, I found no other option than rename all features and sketches to a temp name and then rename it the correct name in a second run.
Maybe I forgot some features, but all unknown features are shown with a message, so we can add it. WorkFeatures are not included so far. Are they needed?
Please try
Dim iAliasFreeform As Integer
Dim iBend As Integer
Dim iBoss As Integer
Dim iBoundaryPatch As Integer
Dim iChamfer As Integer
Dim iCircularpattern As Integer
Dim iClient As Integer
Dim iCoil As Integer
Dim iCombine As Integer
Dim iCoreCavity As Integer
Dim iDecal As Integer
Dim iDeleteFace As Integer
Dim iDirectEdit As Integer
Dim iEmboss As Integer
Dim iExtend As Integer
Dim iExtrude As Integer
Dim iFaceDraft As Integer
Dim iFaceOffset As Integer
Dim iFillet As Integer
Dim iFreeform As Integer
Dim iGrill As Integer
Dim iHole As Integer
Dim iKnit As Integer
Dim iLip As Integer
Dim iLoft As Integer
Dim iMidsurface As Integer
Dim iMirror As Integer
Dim iMoveFace As Integer
Dim iMove As Integer
'NonParametricBaseFeature
'NonParametricBaseFeatures
Dim iRectangularPattern As Integer
'Reference
Dim iReplaceFace As Integer
Dim iRest As Integer
Dim iRevolve As Integer
Dim iRib As Integer
Dim iRuledSurface As Integer
Dim iRuleFillet As Integer
Dim iSculpt As Integer
Dim iShell As Integer
Dim iSketchDrivenPattern As Integer
Dim iSnapFit As Integer
Dim iSplit As Integer
Dim iSweep As Integer
Dim iThicken As Integer
Dim iThread As Integer
Dim iTrim As Integer
Dim iUnwrap As Integer
Dim oPartDoc As PartDocument= ThisDoc.Document
Dim oFeatures As PartFeatures = oPartDoc.ComponentDefinition.Features
Dim i As Integer
For i = 1 To oFeatures.Count
oFeatures(i).Name = "f" & i
Next
For i = 1 To oFeatures.Count
Select Case oFeatures(i).Type
Case ObjectTypeEnum.kAliasFreeformFeatureObject:
iAliasFreeform = iAliasFreeform + 1
oFeatures(i).Name = "AliasFreeform" & CStr(iAliasFreeform)
Case ObjectTypeEnum.kBendFeatureObject:
iBend = iBend + 1
oFeatures(i).Name = "Bend" & CStr(iBend)
Case ObjectTypeEnum.kBossFeatureObject:
iBoss = iBoss + 1
oFeatures(i).Name = "Boss" & CStr(iBoss)
Case ObjectTypeEnum.kBoundaryPatchFeatureObject:
iBoundaryPatch = iBoundaryPatch + 1
oFeatures(i).Name = "BoundaryPatch" & CStr(iBoundaryPatch)
Case ObjectTypeEnum.kChamferFeatureObject:
iChamfer = iChamfer + 1
oFeatures(i).Name = "Chamfer" & CStr(iChamfer)
Case ObjectTypeEnum.kCircularPatternFeatureObject:
iCircularpattern = iCircularpattern + 1
oFeatures(i).Name = "CircularPattern" & CStr(iCircularpattern)
Case ObjectTypeEnum.kClientFeatureObject:
iClient = iClient + 1
oFeatures(i).Name = "Client" & CStr(iClient)
Case ObjectTypeEnum.kCoilFeatureObject:
iCoil = iCoil + 1
oFeatures(i).Name = "Coil" & CStr(iCoil)
Case ObjectTypeEnum.kCombineFeatureObject:
iCombine = iCombine + 1
oFeatures(i).Name = "Combine" & CStr(iCombine)
Case ObjectTypeEnum.kCoreCavityFeatureObject:
iCoreCavity = iCoreCavity + 1
oFeatures(i).Name = "CoreCavity" & CStr(iCoreCavity)
Case ObjectTypeEnum.kDecalFeatureObject:
iDecal = iDecal + 1
oFeatures(i).Name = "Decal" & CStr(iDecal)
Case ObjectTypeEnum.kDeleteFaceFeatureObject:
iDeleteFace = iDeleteFace + 1
oFeatures(i).Name = "DeleteFace" & CStr(iDeleteFace)
Case ObjectTypeEnum.kDirectEditFeatureObject:
iDirectEdit = iDirectEdit + 1
oFeatures(i).Name = "DirectEdit" & CStr(iDirectEdit)
Case ObjectTypeEnum.kEmbossFeatureObject:
iEmboss = iEmboss + 1
oFeatures(i).Name = "Emboss" & CStr(iEmboss)
Case ObjectTypeEnum.kExtendFeatureObject:
iExtend = iExtend + 1
oFeatures(i).Name = "Extend" & CStr(iExtend)
Case ObjectTypeEnum.kExtrudeFeatureObject:
iExtrude = iExtrude + 1
oFeatures(i).Name = "Extrude" & CStr(iExtrude)
Case ObjectTypeEnum.kFaceDraftFeatureObject:
iFaceDraft = iFaceDraft + 1
oFeatures(i).Name = "FaceDraft" & CStr(iFaceDraft)
Case ObjectTypeEnum.kFaceOffsetFeatureObject:
iFaceOffset = iFaceOffset + 1
oFeatures(i).Name = "FaceOffset" & CStr(iFaceOffset)
Case ObjectTypeEnum.kFilletFeatureObject:
iFillet = iFillet + 1
oFeatures(i).Name = "Fillet" & CStr(iFillet)
Case ObjectTypeEnum.kFreeformFeatureObject:
iFreeform = iFreeform + 1
oFeatures(i).Name = "Freeform" & CStr(iFreeform)
Case ObjectTypeEnum.kGrillFeatureObject:
iGrill = iGrill + 1
oFeatures(i).Name = "Grill" & CStr(iGrill)
Case ObjectTypeEnum.kHoleFeatureObject:
iHole = iHole + 1
oFeatures(i).Name = "Hole" & CStr(iHole)
Case ObjectTypeEnum.kKnitFeatureObject:
iKnit = iKnit + 1
oFeatures(i).Name = "Knit" & CStr(iKnit)
Case ObjectTypeEnum.kLipFeatureObject:
iLip = iLip + 1
oFeatures(i).Name = "Lip" & CStr(iLip)
Case ObjectTypeEnum.kLoftFeatureObject:
iLoft = iLoft + 1
oFeatures(i).Name = "Loft" & CStr(iLoft)
Case ObjectTypeEnum.kMidSurfaceFeatureObject:
iMidsurface = iMidsurface + 1
oFeatures(i).Name = "Midsurface" & CStr(iMidsurface)
Case ObjectTypeEnum.kMirrorFeatureObject:
iMirror = iMirror + 1
oFeatures(i).Name = "Mirror" & CStr(iMirror)
Case ObjectTypeEnum.kMoveFaceFeatureObject:
iMoveFace = iMoveFace + 1
oFeatures(i).Name = "MoveFace" & CStr(iMoveFace)
Case ObjectTypeEnum.kMoveFeatureObject:
iMove = iMove + 1
oFeatures(i).Name = "Move" & CStr(iMove)
Case ObjectTypeEnum.kRectangularPatternFeatureObject:
iRectangularPattern = iRectangularPattern + 1
oFeatures(i).Name = "RectangularPattern" & CStr(iRectangularPattern)
Case ObjectTypeEnum.kReplaceFaceFeatureObject:
iReplaceFace = iReplaceFace + 1
oFeatures(i).Name = "ReplaceFace" & CStr(iReplaceFace)
Case ObjectTypeEnum.kRestFeatureObject:
iRest = iRest + 1
oFeatures(i).Name = "Rest" & CStr(iRest)
Case ObjectTypeEnum.kRevolveFeatureObject:
iRevolve = iRevolve + 1
oFeatures(i).Name = "Revolve" & CStr(iRevolve)
Case ObjectTypeEnum.kRibFeatureObject:
iRib = iRib + 1
oFeatures(i).Name = "Rib" & CStr(iRib)
Case ObjectTypeEnum.kRuledSurfaceFeatureObject:
iRuledSurface = iRuledSurface + 1
oFeatures(i).Name = "RuledSurface" & CStr(iRuledSurface)
Case ObjectTypeEnum.kRuleFilletFeatureObject:
iRuleFillet = iRuleFillet + 1
oFeatures(i).Name = "RuleFillet" & CStr(iRuleFillet)
Case ObjectTypeEnum.kSculptFeatureObject:
iSculpt = iSculpt + 1
oFeatures(i).Name = "Sculpt" & CStr(iSculpt)
Case ObjectTypeEnum.kShellFeatureObject:
iShell = iShell + 1
oFeatures(i).Name = "Shell" & CStr(iShell)
Case ObjectTypeEnum.kSketchDrivenPatternFeatureObject:
iSketchDrivenPattern = iSketchDrivenPattern + 1
oFeatures(i).Name = "SketchDrivenPattern" & CStr(iSketchDrivenPattern)
Case ObjectTypeEnum.kSnapFitFeatureObject:
iSnapFit = iSnapFit + 1
oFeatures(i).Name = "SnapFit" & CStr(iSnapFit)
Case ObjectTypeEnum.kSplitFeatureObject:
iSplit = iSplit + 1
oFeatures(i).Name = "Split" & CStr(iSplit)
Case ObjectTypeEnum.kSweepFeatureObject:
iSweep = iSweep + 1
oFeatures(i).Name = "Sweep" & CStr(iSweep)
Case ObjectTypeEnum.kThickenFeatureObject:
iThicken = iThicken + 1
oFeatures(i).Name = "Thicken" & CStr(iThicken)
Case ObjectTypeEnum.kThreadFeatureObject:
iThread = iThread + 1
oFeatures(i).Name = "Thread" & CStr(iThread)
Case ObjectTypeEnum.kTrimFeatureObject:
iTrim = iTrim + 1
oFeatures(i).Name = "Trim" & CStr(iTrim)
Case ObjectTypeEnum.kUnwrapFeatureObject:
iUnwrap = iUnwrap + 1
oFeatures(i).Name = "Unwrap" & CStr(iUnwrap)
Case Else:
MsgBox ("Unknown feature detected: " & CStr(oFeatures(i).Type))
End Select
Next
Dim oSketch As Sketch
For i = 1 To oPartDoc.ComponentDefinition.Sketches.Count
oPartDoc.ComponentDefinition.Sketches(i).Name = "tmpskt" & i
Next
For i = 1 To oPartDoc.ComponentDefinition.Sketches.Count
oPartDoc.ComponentDefinition.Sketches(i).Name = "Sketch" & i
Next
MsgBox("Done",,"iLogic")
Wow, thanks Krieg, very helpful,
Never thought of the Select Case approach, looks good.
As far as I can see/checked, Sketches iterate in the order they were created, how should you solve that? I thought of comparing two lists, one with the browser order and the other with the created order, check for differences and rename if necessary.
Renaming twice, temporary and final, was my solution too, an option could be to examine if renaming is necessary, maybe here also lists could be helpfull?
Work Features would also be useful, if you removed some of them and re-created them later, the order remains.
Basically I would like to see everything sorted and sequenced, also in an assembly with regard to constraints and component sequence numbers.
Without being bothered by too much knowledge:
Please take a look at the picture attached, is it possible to iterate over all the underlying items of oFeatures? And, for example, if there is something inside it looks like the Count>0, could that be a trigger for an action? Could that be an alternative instead of declaring all items like in your code?
Greetings!
Hello
You can iterate through the items of the different feature types, but not through the list in your screenshot.
The problem renumbering only items that are "outdated", if an other item with same name exist, it fails. So you must first rename this colliding item with it's new number (what if this new number also collides with an existing?). Or if feature "f1" must be renamed to "f5" and feature "f5" must be renamed to "f1".
The sketches appear not in the correct order. Wonder why I didn't seen that in my tests. *???*
The only correct order seems to be in the model browser itself. The BrowserPane object can accessed through Document.BrowserPanes and you can iterate through the BrowserNodes and pick up the NativeObjects, which should be the features, sketches, workfeatures and other types you have to filter out. You could collect them this way in a single collection and rename them.
You can use AssemblyDocument.AllReferencedDocuments to get a list of all files. You can iterate this list, grap the partfile and process it's BrowserPane object like described above. Assembly files can have assembly features. They can processed and renamed the same (or a very similar) way.
"also in an assembly with regard to constraints and component sequence numbers."
What do you mean? Do you also want to rename your files and subassemblys?
Hello Krieg,
Thanks for your reaction.
Too bad that list cannot be edited. I'm going to try to rename the sketches neatly using lists, I'll try to keep you informed.
Could you tell me how to recursively iterate a browser pane? Now i do it manually by repeating the code for the layers I would like to search, not so professional.
Also, could you tell me how to pick up the Native Object for the Full Path browser node I've got?
I've added Work Features, they are working now, see attached code.
I do not want to rename files and sub assemblies, I meant the sequence of the constraint-numbering (Mate1, Mate2 etc.) and the quantity number of parts / sub assemblies (Part101: 1 / Part101: 2 etc.). Same approach as the features / sketches in a part, if you move / remove and / or re-add them there is a gap in the numbering I would like to solve.
Greetings!
'----------------------------------------------------------------------------------------------------
' Features
Dim iAliasFreeform As Integer
Dim iBend As Integer
Dim iBoss As Integer
Dim iBoundaryPatch As Integer
Dim iChamfer As Integer
Dim iCircularpattern As Integer
Dim iClient As Integer
Dim iCoil As Integer
Dim iCombine As Integer
Dim iCoreCavity As Integer
Dim iCornerRoundFeatureObject As Integer
Dim iCutFeatureObject As Integer
Dim iDecal As Integer
Dim iDeleteFace As Integer
Dim iDirectEdit As Integer
Dim iEmboss As Integer
Dim iExtend As Integer
Dim iExtrude As Integer
Dim iFaceDraft As Integer
Dim iFace As Integer
Dim iFaceOffset As Integer
Dim iFillet As Integer
Dim iFreeform As Integer
Dim iGrill As Integer
Dim iHole As Integer
Dim iKnit As Integer
Dim iLip As Integer
Dim iLoft As Integer
Dim iMidsurface As Integer
Dim iMirror As Integer
Dim iMoveFace As Integer
Dim iMove As Integer
'NonParametricBaseFeature
'NonParametricBaseFeatures
Dim kPunchToolFeatureObject As Integer
Dim iRectangularPattern As Integer
'Reference
Dim iReplaceFace As Integer
Dim iRest As Integer
Dim iRevolve As Integer
Dim iRib As Integer
Dim iRuledSurface As Integer
Dim iRuleFillet As Integer
Dim iSculpt As Integer
Dim iShell As Integer
Dim iSketchDrivenPattern As Integer
Dim iSnapFit As Integer
Dim iSplit As Integer
Dim kSurfaceBodyObject As Integer
Dim iSweep As Integer
Dim iThicken As Integer
Dim iThread As Integer
Dim iTrim As Integer
Dim iUnwrap As Integer
'----------------------------------------------------------------------------------------------------
' Date and Time variable
Dim strDateAndTime = DateTime.Now.ToString(("yyyy-MM-dd HHmmss"))
'----------------------------------------------------------------------------------------------------
Dim i As Integer
'----------------------------------------------------------------------------------------------------
Dim oPartDoc As PartDocument = ThisDoc.Document
Dim oFeatures As PartFeatures = oPartDoc.ComponentDefinition.Features
Dim oDef As PartComponentDefinition = oPartDoc.ComponentDefinition
'----------------------------------------------------------------------------------------------------
' Rename Solid Bodies
Dim iSolidCount As Integer
Dim oSolid As SurfaceBody
For Each oSolid In oDef.SurfaceBodies
iSolidCount = iSolidCount + 1
oSolid.Name = "Solid" & iSolidCount.ToString & " " & strDateAndTime
Next
iSolidsCount = 0
For Each oSolid In oDef.SurfaceBodies
iSolidsCount = iSolidCount + 1
oSolid.Name = "Solid" & iSolidCount.ToString
Next
'----------------------------------------------------------------------------------------------------
' Work Features
Dim iWorkPlane As Integer
Dim iWorkPoint As Integer
Dim iWorkAxis As Integer
Dim iWorkSurface As Integer
'----------------------------------------------------------------------------------------------------
' Rename Work Features:
'----------------------------------------------------------------------------------------------------
' Rename Work Planes
For Each oWorkPlane In oDef.WorkPlanes
If oWorkPlane.IsCoordinateSystemElement = False Then
iWorkPlane = iWorkPlane + 1
oWorkPlane.Name = "Work Plane" & iWorkPlane.ToString & " " & strDateAndTime
End If
Next
iWorkPlane = 0
For Each oWorkPlane In oDef.WorkPlanes
If oWorkPlane.IsCoordinateSystemElement = False Then
iWorkPlane = iWorkPlane + 1
oWorkPlane.Name = "Work Plane" & iWorkPlane.ToString
End If
Next
'----------------------------------------------------------------------------------------------------
' Rename Work Points
For Each oWorkPoint In oDef.WorkPoints
If oWorkPoint.IsCoordinateSystemElement = False Then
iWorkPoint = iWorkPoint + 1
oWorkPoint.Name = "Work Point" & iWorkPoint.ToString & " " & strDateAndTime
End If
Next
iWorkPoint = 0
For Each oWorkPoint In oDef.WorkPoints
If oWorkPoint.IsCoordinateSystemElement = False Then
iWorkPoint = iWorkPoint + 1
oWorkPoint.Name = "Work Point" & iWorkPoint.ToString
End If
Next
'----------------------------------------------------------------------------------------------------
' Rename Work Axis
For Each oWorkAxis In oDef.WorkAxes
If oWorkAxis.IsCoordinateSystemElement = False Then
iWorkAxis = iWorkAxis + 1
oWorkAxis.Name = "Work Axis" & iWorkAxis.ToString & " " & strDateAndTime
End If
Next
iWorkAxis = 0
For Each oWorkAxis In oDef.WorkAxes
If oWorkAxis.IsCoordinateSystemElement = False Then
iWorkAxis = iWorkAxis + 1
oWorkAxis.Name = "Work Axis" & iWorkAxis.ToString
End If
Next
'----------------------------------------------------------------------------------------------------
' Rename Work Surface
For Each oWorkSurface In oDef.WorkSurfaces
iWorkSurface = iWorkSurface + 1
oWorkSurface.Name = "Work Surface" & iWorkSurface.ToString & " " & strDateAndTime
Next
iWorkSurface = 0
For Each oWorkSurface In oDef.WorkSurfaces
iWorkSurface = iWorkSurface + 1
oWorkSurface.Name = "Work Surface" & iWorkSurface.ToString
Next
'----------------------------------------------------------------------------------------------------
'Rename Features
For i = 1 To oFeatures.Count
oFeatures(i).Name = "f" & i
Next
For i = 1 To oFeatures.Count
Select Case oFeatures(i).Type
Case ObjectTypeEnum.kAliasFreeformFeatureObject:
iAliasFreeform = iAliasFreeform + 1
oFeatures(i).Name = "AliasFreeform" & CStr(iAliasFreeform)
Case ObjectTypeEnum.kBendFeatureObject:
iBend = iBend + 1
oFeatures(i).Name = "Bend" & CStr(iBend)
Case ObjectTypeEnum.kBossFeatureObject:
iBoss = iBoss + 1
oFeatures(i).Name = "Boss" & CStr(iBoss)
Case ObjectTypeEnum.kBoundaryPatchFeatureObject:
iBoundaryPatch = iBoundaryPatch + 1
oFeatures(i).Name = "BoundaryPatch" & CStr(iBoundaryPatch)
Case ObjectTypeEnum.kChamferFeatureObject:
iChamfer = iChamfer + 1
oFeatures(i).Name = "Chamfer" & CStr(iChamfer)
Case ObjectTypeEnum.kCircularPatternFeatureObject:
iCircularpattern = iCircularpattern + 1
oFeatures(i).Name = "CircularPattern" & CStr(iCircularpattern)
Case ObjectTypeEnum.kClientFeatureObject:
iClient = iClient + 1
oFeatures(i).Name = "Client" & CStr(iClient)
Case ObjectTypeEnum.kCoilFeatureObject:
iCoil = iCoil + 1
oFeatures(i).Name = "Coil" & CStr(iCoil)
Case ObjectTypeEnum.kCombineFeatureObject:
iCombine = iCombine + 1
oFeatures(i).Name = "Combine" & CStr(iCombine)
Case ObjectTypeEnum.kCoreCavityFeatureObject:
iCoreCavity = iCoreCavity + 1
oFeatures(i).Name = "CoreCavity" & CStr(iCoreCavity)
Case ObjectTypeEnum.kCornerRoundFeatureObject:
iCornerRound = iCornerRound + 1
oFeatures(i).Name = "CornerRound" & CStr(iCornerRound)
Case ObjectTypeEnum.kCutFeatureObject:
iCut = iCut + 1
oFeatures(i).Name = "Cut" & CStr(iCut)
Case ObjectTypeEnum.kDecalFeatureObject :
iDecal = iDecal + 1
oFeatures(i).Name = "Decal" & CStr(iDecal)
Case ObjectTypeEnum.kDeleteFaceFeatureObject:
iDeleteFace = iDeleteFace + 1
oFeatures(i).Name = "DeleteFace" & CStr(iDeleteFace)
Case ObjectTypeEnum.kDirectEditFeatureObject:
iDirectEdit = iDirectEdit + 1
oFeatures(i).Name = "DirectEdit" & CStr(iDirectEdit)
Case ObjectTypeEnum.kEmbossFeatureObject:
iEmboss = iEmboss + 1
oFeatures(i).Name = "Emboss" & CStr(iEmboss)
Case ObjectTypeEnum.kExtendFeatureObject:
iExtend = iExtend + 1
oFeatures(i).Name = "Extend" & CStr(iExtend)
Case ObjectTypeEnum.kExtrudeFeatureObject:
iExtrude = iExtrude + 1
oFeatures(i).Name = "Extrude" & CStr(iExtrude)
Case ObjectTypeEnum.kFaceDraftFeatureObject:
iFaceDraft = iFaceDraft + 1
oFeatures(i).Name = "FaceDraft" & CStr(iFaceDraft)
Case ObjectTypeEnum.kFaceFeatureObject:
iFace = iFace + 1
oFeatures(i).Name = "Face" & CStr(iFace)
Case ObjectTypeEnum.kFaceOffsetFeatureObject :
iFaceOffset = iFaceOffset + 1
oFeatures(i).Name = "FaceOffset" & CStr(iFaceOffset)
Case ObjectTypeEnum.kFilletFeatureObject:
iFillet = iFillet + 1
oFeatures(i).Name = "Fillet" & CStr(iFillet)
Case ObjectTypeEnum.kFreeformFeatureObject:
iFreeform = iFreeform + 1
oFeatures(i).Name = "Freeform" & CStr(iFreeform)
Case ObjectTypeEnum.kGrillFeatureObject:
iGrill = iGrill + 1
oFeatures(i).Name = "Grill" & CStr(iGrill)
Case ObjectTypeEnum.kHoleFeatureObject:
iHole = iHole + 1
oFeatures(i).Name = "Hole" & CStr(iHole)
Case ObjectTypeEnum.kKnitFeatureObject:
iKnit = iKnit + 1
oFeatures(i).Name = "Knit" & CStr(iKnit)
Case ObjectTypeEnum.kLipFeatureObject:
iLip = iLip + 1
oFeatures(i).Name = "Lip" & CStr(iLip)
Case ObjectTypeEnum.kLoftFeatureObject:
iLoft = iLoft + 1
oFeatures(i).Name = "Loft" & CStr(iLoft)
Case ObjectTypeEnum.kMidSurfaceFeatureObject:
iMidsurface = iMidsurface + 1
oFeatures(i).Name = "Midsurface" & CStr(iMidsurface)
Case ObjectTypeEnum.kMirrorFeatureObject:
iMirror = iMirror + 1
oFeatures(i).Name = "Mirror" & CStr(iMirror)
Case ObjectTypeEnum.kMoveFaceFeatureObject:
iMoveFace = iMoveFace + 1
oFeatures(i).Name = "MoveFace" & CStr(iMoveFace)
Case ObjectTypeEnum.kMoveFeatureObject:
iMove = iMove + 1
oFeatures(i).Name = "Move" & CStr(iMove)
Case ObjectTypeEnum.kPunchToolFeatureObject:
iPunchToolFeature = iPunchToolFeature + 1
oFeatures(i).Name = "PunchToolFeature" & CStr(iPunchToolFeature)
Case ObjectTypeEnum.kRectangularPatternFeatureObject:
iRectangularPattern = iRectangularPattern + 1
oFeatures(i).Name = "RectangularPattern" & CStr(iRectangularPattern)
Case ObjectTypeEnum.kReplaceFaceFeatureObject:
iReplaceFace = iReplaceFace + 1
oFeatures(i).Name = "ReplaceFace" & CStr(iReplaceFace)
Case ObjectTypeEnum.kRestFeatureObject:
iRest = iRest + 1
oFeatures(i).Name = "Rest" & CStr(iRest)
Case ObjectTypeEnum.kRevolveFeatureObject:
iRevolve = iRevolve + 1
oFeatures(i).Name = "Revolve" & CStr(iRevolve)
Case ObjectTypeEnum.kRibFeatureObject:
iRib = iRib + 1
oFeatures(i).Name = "Rib" & CStr(iRib)
Case ObjectTypeEnum.kRuledSurfaceFeatureObject:
iRuledSurface = iRuledSurface + 1
oFeatures(i).Name = "RuledSurface" & CStr(iRuledSurface)
Case ObjectTypeEnum.kRuleFilletFeatureObject:
iRuleFillet = iRuleFillet + 1
oFeatures(i).Name = "RuleFillet" & CStr(iRuleFillet)
Case ObjectTypeEnum.kSculptFeatureObject:
iSculpt = iSculpt + 1
oFeatures(i).Name = "Sculpt" & CStr(iSculpt)
Case ObjectTypeEnum.kShellFeatureObject:
iShell = iShell + 1
oFeatures(i).Name = "Shell" & CStr(iShell)
Case ObjectTypeEnum.kSketchDrivenPatternFeatureObject:
iSketchDrivenPattern = iSketchDrivenPattern + 1
oFeatures(i).Name = "SketchDrivenPattern" & CStr(iSketchDrivenPattern)
Case ObjectTypeEnum.kSnapFitFeatureObject:
iSnapFit = iSnapFit + 1
oFeatures(i).Name = "SnapFit" & CStr(iSnapFit)
Case ObjectTypeEnum.kSplitFeatureObject:
iSplit = iSplit + 1
oFeatures(i).Name = "Split" & CStr(iSplit)
Case ObjectTypeEnum.kSurfaceBodyObject:
ikSurfaceBodyObject = ikSurfaceBodyObject + 1
oFeatures(i).Name = "Solid" & CStr(ikSurfaceBodyObject)
Case ObjectTypeEnum.kSweepFeatureObject:
iSweep = iSweep + 1
oFeatures(i).Name = "Sweep" & CStr(iSweep)
Case ObjectTypeEnum.kThickenFeatureObject:
iThicken = iThicken + 1
oFeatures(i).Name = "Thicken" & CStr(iThicken)
Case ObjectTypeEnum.kThreadFeatureObject:
iThread = iThread + 1
oFeatures(i).Name = "Thread" & CStr(iThread)
Case ObjectTypeEnum.kTrimFeatureObject:
iTrim = iTrim + 1
oFeatures(i).Name = "Trim" & CStr(iTrim)
Case ObjectTypeEnum.kUnwrapFeatureObject:
iUnwrap = iUnwrap + 1
oFeatures(i).Name = "Unwrap" & CStr(iUnwrap)
Case Else:
MsgBox ("Unknown feature detected: " & CStr(oFeatures(i).Type))
End Select
Next
' Rename Sketches
Dim oSketch As Sketch
For i = 1 To oPartDoc.ComponentDefinition.Sketches.Count
oPartDoc.ComponentDefinition.Sketches(i).Name = "tmpskt" & i
Next
For i = 1 To oPartDoc.ComponentDefinition.Sketches.Count
oPartDoc.ComponentDefinition.Sketches(i).Name = "Sketch" & i
Next
'MsgBox("Done",,"iLogic")
'----------------------------------------------------------------------------------------------------
Hello
Sorry for the late reply. After hours of trying to get a stable way to sort all browsernodes for renumbering without success, I started thinking about a complete new approach.
Starting from an assembly we don't traverse through the structure. We get the AllReferencedDocuments Collection. This way we can prior processing check if the current document is protected (e.g. Contentcenter, Vault - not implemented so far). Each of this documents has it's own BrowserPane object we can use. We don't need to traverse through the whole tree structure. The numbering is independent for every document.
I separated first the handling of assembly and part browser panes. Presentations and Drawings are not handled so far, but could be added if this way works as expected. Then I separated the handling of BrowserNodes for Constraints, SurfaceBodies, WorkSurfaces and so on. There are now some parts of code duplicated for easier debugging. If it's stable it could be joined again. For the rest of BrowserNodes (occurrences in an assembly and so on) I just collect them all in one collection in order they appear in tree. After that, I run through the collection and rename all the collected nodes with a temp name. In a second run through this collection I make a simple try and error with renumbering. Starting by 1, I try to renumber the current node. If it fails, I try it with 2, 3, ... until it succeeds. I think this is not slower than check if this number always exist and it avoids of keeping the last used number of all of this features, occurrences, ...
It's currently all written in VBA.
Option Explicit
Private Const sEOP As String = "Elementenende" '"End of Features"
Private Const sEOF As String = "Elementenende" 'End of Features
'Private Const sEOP As String = "Bauteilende" 'EndOfPart
Private Const sConstraints As String = "Beziehungen" 'Constraints
Private Const siMates As String = "iMates" 'iMates
Private Const sRepresentations As String = "Darstellungen" 'Representations
Private Const sOrigin As String = "Ursprung" 'Origin
Private Const sPosRep As String = "Positionsdarstellungen" 'PositionalRepresentations
Private Const sBlocks As String = "Blöcke" 'Blocks
Private Const sSurfaceBodies As String = "Volumenkörper(" 'SurfaceBodies(
Private Const sWorkSurfaces As String = "Flächenkörper(" 'WorkSurfaces
Private Const sDesignView As String = "Ansicht:" 'DesignView:
Private Sub main()
Dim oApp As Inventor.Application
Set oApp = ThisApplication
Dim oDoc As Document
Dim oPartDoc As PartDocument
Dim oAssDoc As AssemblyDocument
If oApp.ActiveDocumentType = kAssemblyDocumentObject Then
Set oAssDoc = oApp.ActiveDocument
Call ProcessAssBrowserPane(oAssDoc)
For Each oDoc In oAssDoc.AllReferencedDocuments
If oDoc.DocumentType = kPartDocumentObject Then
Call ProcessPartBrowserPane(oDoc)
ElseIf oDoc.DocumentType = kAssemblyDocumentObject Then
Call ProcessAssBrowserPane(oDoc)
End If
Next
ElseIf oApp.ActiveDocumentType = kPartDocumentObject Then
Set oPartDoc = oApp.ActiveDocument
Call ProcessPartBrowserPane(oPartDoc)
Else
MsgBox ("Part or Assembly, nothing else.")
End If
End Sub
Private Sub ProcessPartBrowserPane(ByVal oPartDoc As PartDocument)
Dim oBrowserPane As BrowserPane
For Each oBrowserPane In oPartDoc.BrowserPanes
If oBrowserPane.InternalName = "PmDefault" Then Exit For
Next
If Not oBrowserPane Is Nothing Then
Dim oTopNode As BrowserNode
Set oTopNode = oBrowserPane.TopNode
'SheetMetal parts have an additional node for folded model and flat pattern
Dim oStartNode As BrowserNode
If oPartDoc.DocumentSubType.DocumentSubTypeID = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Then 'part
Set oStartNode = oTopNode
ElseIf oPartDoc.DocumentSubType.DocumentSubTypeID = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'sheetmteal part
Set oStartNode = oTopNode.BrowserNodes.Item(1)
Else
MsgBox ("Unknown PartDocumentType detected for file: " & vbCrLf & oPartDoc.FullDocumentName)
Exit Sub
End If
Dim i As Integer
Dim j As Integer
Dim oObjColl As ObjectCollection
Set oObjColl = ThisApplication.TransientObjects.CreateObjectCollection
For i = 1 To oStartNode.BrowserNodes.Count
If isInternalNode(oStartNode.BrowserNodes.Item(i)) = False Then
Select Case oStartNode.BrowserNodes.Item(i).NativeObject.Type
Case kComponentOccurrenceObject:
Call oObjColl.Add(oStartNode.BrowserNodes.Item(i).NativeObject)
Case kCircularOccurrencePatternObject:
Dim oCPatternOccs As ObjectCollection
Set oCPatternOccs = ThisApplication.TransientObjects.CreateObjectCollection
Set oCPatternOccs = GetPatternElements(oStartNode.BrowserNodes.Item(i).BrowserNodes)
If Not oCPatternOccs Is Nothing Then
For j = 1 To oCPatternOccs.Count
Call oObjColl.Add(oCPatternOccs.Item(j))
Next
End If
Case kRectangularOccurrencePatternObject:
Dim oRPatternOccs As ObjectCollection
Set oRPatternOccs = ThisApplication.TransientObjects.CreateObjectCollection
Set oRPatternOccs = GetPatternElements(oStartNode.BrowserNodes.Item(i).BrowserNodes)
If Not oRPatternOccs Is Nothing Then
For j = 1 To oRPatternOccs.Count
Call oObjColl.Add(oRPatternOccs.Item(j))
Next
End If
Case kFeatureBasedOccurrencePatternObject:
Dim oFBPatternOccs As ObjectCollection
Set oFBPatternOccs = ThisApplication.TransientObjects.CreateObjectCollection
Set oFBPatternOccs = GetPatternElements(oStartNode.BrowserNodes.Item(i).BrowserNodes)
If Not oFBPatternOccs Is Nothing Then
For j = 1 To oFBPatternOccs.Count
Call oObjColl.Add(oFBPatternOccs.Item(j))
Next
End If
Case kPlanarSketchObject:
Call oObjColl.Add(oStartNode.BrowserNodes.Item(i).NativeObject)
Case kDerivedPartComponentObject:
'ignore derived components
Case kDerivedAssemblyComponentObject:
'ignore derived components
Case Else: 'anything else should be an assemblyfeature *?*
Call oObjColl.Add(oStartNode.BrowserNodes.Item(i).NativeObject)
'Search for non-shared Sketches
Dim oSketch As PlanarSketch
Set oSketch = GetBaseSketch(oStartNode.BrowserNodes.Item(i).BrowserNodes)
If Not oSketch Is Nothing Then
Call oObjColl.Add(oSketch)
End If
Dim oSketch3D As Sketch3D
Set oSketch3D = GetBaseSketch3D(oTopNode.BrowserNodes.Item(i).BrowserNodes)
If Not oSketch3D Is Nothing Then
Call oObjColl.Add(oSketch3D)
End If
End Select
End If
Next
'Setting temporary names
On Error Resume Next
For j = 1 To oObjColl.Count
oObjColl.Item(j).Name = "tmp_" & oObjColl.Item(j).Name
Next
Dim iExit As Integer
Dim sName As String
For i = 1 To oObjColl.Count
iExit = 1
Do
sName = StripTrailingNumbers(oObjColl.Item(i).Name)
If sName = "" Then Exit Do
sName = sName & iExit
oObjColl.Item(i).Name = sName
'Emergency Exit 999
If iExit > 999 Then Exit Do
iExit = iExit + 1
Loop While oObjColl.Item(i).Name <> sName
Next
On Error GoTo 0
End If
End Sub
Private Sub ProcessAssBrowserPane(ByVal oAssDoc As AssemblyDocument)
Dim oBrowserPane As BrowserPane
For Each oBrowserPane In oAssDoc.BrowserPanes
If oBrowserPane.InternalName = "AmBrowserArrangement" Then Exit For
Next
If Not oBrowserPane Is Nothing Then
Dim oTopNode As BrowserNode
Set oTopNode = oBrowserPane.TopNode
Dim i As Integer
Dim j As Integer
Dim oObjColl As ObjectCollection
Set oObjColl = ThisApplication.TransientObjects.CreateObjectCollection
Dim oSketchColl As ObjectCollection
Set oSketchColl = ThisApplication.TransientObjects.CreateObjectCollection
For i = 1 To oTopNode.BrowserNodes.Count
If isInternalNode(oTopNode.BrowserNodes.Item(i)) = False Then
Select Case oTopNode.BrowserNodes.Item(i).NativeObject.Type
Case kComponentOccurrenceObject:
Call oObjColl.Add(oTopNode.BrowserNodes.Item(i).NativeObject)
Case kCircularOccurrencePatternObject:
Dim oCPatternOccs As ObjectCollection
Set oCPatternOccs = ThisApplication.TransientObjects.CreateObjectCollection
Set oCPatternOccs = GetPatternElements(oTopNode.BrowserNodes.Item(i).BrowserNodes)
If Not oCPatternOccs Is Nothing Then
For j = 1 To oCPatternOccs.Count
Call oObjColl.Add(oCPatternOccs.Item(j))
Next
End If
Case kRectangularOccurrencePatternObject:
Dim oRPatternOccs As ObjectCollection
Set oRPatternOccs = ThisApplication.TransientObjects.CreateObjectCollection
Set oRPatternOccs = GetPatternElements(oTopNode.BrowserNodes.Item(i).BrowserNodes)
If Not oRPatternOccs Is Nothing Then
For j = 1 To oRPatternOccs.Count
Call oObjColl.Add(oRPatternOccs.Item(j))
Next
End If
Case kFeatureBasedOccurrencePatternObject:
Dim oFBPatternOccs As ObjectCollection
Set oFBPatternOccs = ThisApplication.TransientObjects.CreateObjectCollection
Set oFBPatternOccs = GetPatternElements(oTopNode.BrowserNodes.Item(i).BrowserNodes)
If Not oFBPatternOccs Is Nothing Then
For j = 1 To oFBPatternOccs.Count
Call oObjColl.Add(oFBPatternOccs.Item(j))
Next
End If
Case kPlanarSketchObject:
Call oSketchColl.Add(oTopNode.BrowserNodes.Item(i).NativeObject)
Case Else: 'anything else should be an assemblyfeature *?*
Call oObjColl.Add(oTopNode.BrowserNodes.Item(i).NativeObject)
'Search for non-shared Sketches
Dim oSketch As PlanarSketch
Set oSketch = GetBaseSketch(oTopNode.BrowserNodes.Item(i).BrowserNodes)
If Not oSketch Is Nothing Then
Call oSketchColl.Add(oSketch)
End If
End Select
End If
Next
'Setting temporary names
For j = 1 To oObjColl.Count
oObjColl.Item(j).Name = "tmp_" & oObjColl.Item(j).Name
Next
Dim iExit As Integer
Dim sName As String
On Error Resume Next
For j = 1 To oObjColl.Count
iExit = 1
If InStr(oObjColl.Item(j).Name, ":") Then
Do
Err.Clear
oObjColl.Item(j).Name = Mid(Left(oObjColl.Item(j).Name, InStrRev(oObjColl.Item(j).Name, ":") - 1), 5) & ":" & iExit
'Emergency Exit 999
If iExit > 999 Then Exit Do
iExit = iExit + 1
Loop While Err.Number <> 0
Else
Do
sName = StripTrailingNumbers(oObjColl.Item(j).Name)
If sName = "" Then Exit Do
sName = sName & iExit
oObjColl.Item(j).Name = sName
'Notausstieg bei 999
If iExit > 999 Then Exit Do
iExit = iExit + 1
Loop While oObjColl.Item(j).Name <> sName
End If
Next
'Sketches can all have the same name, no need to temp rename them
'Is this a bug in assembly sketches???
For j = 1 To oSketchColl.Count
sName = StripTrailingNumbers(oSketchColl.Item(j).Name)
If Not sName = "" Then
oSketchColl.Item(j).Name = sName & j
End If
Next
On Error GoTo 0
End If
End Sub
Private Function GetPatternElements(ByVal oNodes As BrowserNodesEnumerator) As ObjectCollection
Dim oElementsColl As ObjectCollection
Set oElementsColl = ThisApplication.TransientObjects.CreateObjectCollection
Dim oNode As BrowserNode
For Each oNode In oNodes
If Not oNode.NativeObject Is Nothing Then
If oNode.NativeObject.Type = kComponentOccurrenceObject Then
Call oElementsColl.Add(oNode.NativeObject)
Else
Dim oSubElementsColl As ObjectCollection
Set oSubElementsColl = ThisApplication.TransientObjects.CreateObjectCollection
Set oSubElementsColl = GetPatternElements(oNode.BrowserNodes)
If Not oSubElementsColl Is Nothing Then
Dim i As Integer
For i = 1 To oSubElementsColl.Count
Call oElementsColl.Add(oSubElementsColl.Item(i))
Next
End If
End If
End If
Next
Set GetPatternElements = oElementsColl
End Function
Private Function GetBaseSketch(ByVal oNodes As BrowserNodesEnumerator) As PlanarSketch
Dim oNode As BrowserNode
For Each oNode In oNodes
If Not oNode.NativeObject Is Nothing Then
If oNode.NativeObject.Type = kPlanarSketchObject Then
Set GetBaseSketch = oNode.NativeObject
Exit For
End If
End If
Next
End Function
Private Function GetBaseSketch3D(ByVal oNodes As BrowserNodesEnumerator) As Sketch3D
Dim oNode As BrowserNode
For Each oNode In oNodes
If Not oNode.NativeObject Is Nothing Then
If oNode.NativeObject.Type = kSketch3DObject Then
Set GetBaseSketch3D = oNode.NativeObject
Exit For
End If
End If
Next
End Function
Private Sub RenumberSurfaceBodies(ByVal oNodes As BrowserNodesEnumerator)
On Error Resume Next
Dim i As Integer
For i = 1 To oNodes.Count
oNodes(i).NativeObject.Name = "tmp_" & oNodes(i).NativeObject.Name
Next
Dim sName As String
Dim iExit As Integer
For i = 1 To oNodes.Count
iExit = 1
Do
sName = StripTrailingNumbers(oNodes.Item(i).NativeObject.Name)
If sName = "" Then Exit Do
sName = sName & iExit
oNodes.Item(i).NativeObject.Name = sName
'Notausstieg bei 999
If iExit > 999 Then Exit Do
iExit = iExit + 1
Loop While oNodes(i).NativeObject.Name <> sName
Next
On Error GoTo 0
End Sub
Private Sub RenumberWorkSurfaces(ByVal oNodes As BrowserNodesEnumerator)
On Error Resume Next
Dim i As Integer
For i = 1 To oNodes.Count
oNodes(i).NativeObject.Name = "tmp_" & oNodes(i).NativeObject.Name
Next
Dim sName As String
Dim iExit As Integer
For i = 1 To oNodes.Count
iExit = 1
Do
sName = StripTrailingNumbers(oNodes.Item(i).NativeObject.Name)
If sName = "" Then Exit Do
sName = sName & iExit
oNodes.Item(i).NativeObject.Name = sName
'Notausstieg bei 999
If iExit > 999 Then Exit Do
iExit = iExit + 1
Loop While oNodes(i).NativeObject.Name <> sName
Next
On Error GoTo 0
End Sub
Private Sub RenumberConstraints(ByVal oNodes As BrowserNodesEnumerator)
Dim i As Integer
For i = 1 To oNodes.Count
oNodes(i).NativeObject.Name = "tmp_" & oNodes(i).NativeObject.Name
Next
For i = 1 To oNodes.Count
Dim iExit As Integer
iExit = 1
On Error Resume Next
Do
Err.Clear
oNodes.Item(i).NativeObject.Name = Mid(Left(oNodes.Item(i).NativeObject.Name, InStrRev(oNodes.Item(i).NativeObject.Name, ":") - 1), 5) & ":" & iExit
'Notausstieg bei 999
If iExit > 999 Then Exit Do
iExit = iExit + 1
Loop While Err.Number <> 0
Next
End Sub
Private Function StripTrailingNumbers(ByVal sName As String) As String
If Left(sName, 4) = "tmp_" Then
sName = Mid(sName, 5)
End If
Do While IsNumeric(Right(sName, 1)) = True
sName = Left(sName, Len(sName) - 1)
Loop
StripTrailingNumbers = sName
End Function
Private Function isInternalNode(ByVal oNode As BrowserNode) As Boolean
If oNode.Visible = False Then
isInternalNode = True
Exit Function
End If
Select Case True
Case oNode.BrowserNodeDefinition.Label = "Beziehungen":
isInternalNode = True
Call RenumberConstraints(oNode.BrowserNodes)
Case oNode.BrowserNodeDefinition.Label = "iMates": 'NativeObject=Part / AssemblyComponentDefinition
isInternalNode = True
Case oNode.BrowserNodeDefinition.Label = "Darstellungen":
isInternalNode = True
Case oNode.BrowserNodeDefinition.Label = "Ursprung":
isInternalNode = True
Case InStr(oNode.BrowserNodeDefinition.Label, "Positionsdarstellungen"):
isInternalNode = True
Case oNode.BrowserNodeDefinition.Label = "Elementenende":
isInternalNode = True
Case oNode.BrowserNodeDefinition.Label = "Blöcke": 'NativeObject=Nothing
isInternalNode = True
Case Left(oNode.BrowserNodeDefinition.Label, 14) = "Volumenkörper(":
If oNode.NativeObject Is Nothing Then
Call RenumberSurfaceBodies(oNode.BrowserNodes)
isInternalNode = True
End If
Case Left(oNode.BrowserNodeDefinition.Label, 14) = "Flächenkörper(":
If oNode.NativeObject Is Nothing Then
Call RenumberWorkSurfaces(oNode.BrowserNodes)
isInternalNode = True
End If
Case Left(oNode.BrowserNodeDefinition.Label, 😎 = "Ansicht:": 'NativeObject.type=kDesignViewRepresentationobject
If oNode.NativeObject.Type = ObjectTypeEnum.kDesignViewRepresentationObject Then
isInternalNode = True
End If
Case oNode.BrowserNodeDefinition.Label = "Bauteilende": 'NativeObject.type=kendoffeaturesobject
isInternalNode = True
Case Else:
isInternalNode = False
End Select
End Function
Wow Krieg!! This is really mind blowing! Its doing almost everything I dreamed off!
And, even in VBA, it's working super fast, within seconds a whole assembly is ordered, I am really amazed!
To get it running here I've add 'On Error Resume Next' in 'GetBaseSketch' and 'GetBaseSketch3D', because of : 'NativeObject : <Application-defined or object-defined error>' .
Regarding Sketch order, when I try in new parts to swap Sketches, Features etc. it looks like the macro is handling these very well and reorder them according the Browser order. At some older parts for unclear reason some Sketches won't reorder. When I try with the 'old' macro (Sort Browser, see attached) the Sketches reorder as expected. Note the text file output within the 'Sort Browser' rule to check some things.
Regarding the behaviour of sketches in assembly's, I do not know for now.
Sketches in Drawings, it looks like for every Drawing View the sketches start at 'Sketch1'.
About reordering Drawing Views I am curious whether the node order can be maintained here.
Under 'Contour FlangeX' there are the 'BendX' and 'CornerX' features which I would like to include in the renaming. I still can see their presence under the Native Object but do not know how how to access them.
Maybe the renaming sessions can be limited a bit further, if now a first attempt fails in the middle of the session, a part has already been renamed which leads to unwanted results.
Overall, a very promising piece of code!
Greetings!
Option Explicit
Private Const sEOP As String = "End of Features"
Private Const sEOF As String = "End of Features"
'Private Const sEOP As String = "End Of Part"
Private Const sConstraints As String = "Constraints"
Private Const siMates As String = "iMates" 'iMates
Private Const sRepresentations As String = "Representations"
Private Const sOrigin As String = "Origin"
Private Const sPosRep As String = "PositionalRepresentations"
Private Const sBlocks As String = "Blocks"
Private Const sSurfaceBodies As String = "SurfaceBodies"
Private Const sWorkSurfaces As String = "WorkSurfaces"
Private Const sDesignView As String = "DesignView:"
'Private Const sEOP As String = "Elementenende" '"End of Features"
'Private Const sEOF As String = "Elementenende" 'End of Features
''Private Const sEOP As String = "Bauteilende" 'EndOfPart
'Private Const sConstraints As String = "Beziehungen" 'Constraints
'Private Const siMates As String = "iMates" 'iMates
'Private Const sRepresentations As String = "Darstellungen" 'Representations
'Private Const sOrigin As String = "Ursprung" 'Origin
'Private Const sPosRep As String = "Positionsdarstellungen" 'PositionalRepresentations
'Private Const sBlocks As String = "Blöcke" 'Blocks
'Private Const sSurfaceBodies As String = "Volumenkörper(" 'SurfaceBodies(
'Private Const sWorkSurfaces As String = "Flächenkörper(" 'WorkSurfaces
'Private Const sDesignView As String = "Ansicht:" 'DesignView:
Private Sub Main_Krieg_Idea()
Dim oApp As Inventor.Application
Set oApp = ThisApplication
Dim oDoc As Document
Dim oPartDoc As PartDocument
Dim oAssDoc As AssemblyDocument
If oApp.ActiveDocumentType = kAssemblyDocumentObject Then
Set oAssDoc = oApp.ActiveDocument
Call ProcessAssBrowserPane(oAssDoc)
For Each oDoc In oAssDoc.AllReferencedDocuments
If oDoc.DocumentType = kPartDocumentObject Then
Call ProcessPartBrowserPane(oDoc)
ElseIf oDoc.DocumentType = kAssemblyDocumentObject Then
Call ProcessAssBrowserPane(oDoc)
End If
Next
ElseIf oApp.ActiveDocumentType = kPartDocumentObject Then
Set oPartDoc = oApp.ActiveDocument
Call ProcessPartBrowserPane(oPartDoc)
Else
MsgBox ("Part or Assembly, nothing else.")
End If
End Sub
Private Sub ProcessPartBrowserPane(ByVal oPartDoc As PartDocument)
Dim oBrowserPane As BrowserPane
For Each oBrowserPane In oPartDoc.BrowserPanes
If oBrowserPane.InternalName = "PmDefault" Then Exit For
Next
If Not oBrowserPane Is Nothing Then
Dim oTopNode As BrowserNode
Set oTopNode = oBrowserPane.TopNode
'SheetMetal parts have an additional node for folded model and flat pattern
Dim oStartNode As BrowserNode
If oPartDoc.DocumentSubType.DocumentSubTypeID = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Then 'part
Set oStartNode = oTopNode
ElseIf oPartDoc.DocumentSubType.DocumentSubTypeID = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'sheetmetal part
Set oStartNode = oTopNode.BrowserNodes.Item(1)
Else
MsgBox ("Unknown PartDocumentType detected for file: " & vbCrLf & oPartDoc.FullDocumentName)
Exit Sub
End If
Dim i As Integer
Dim j As Integer
Dim oObjColl As ObjectCollection
Set oObjColl = ThisApplication.TransientObjects.CreateObjectCollection
For i = 1 To oStartNode.BrowserNodes.Count
If isInternalNode(oStartNode.BrowserNodes.Item(i)) = False Then
'Debug.Print oStartNode.BrowserNodes.Item(i).NativeObject.Name
Select Case oStartNode.BrowserNodes.Item(i).NativeObject.Type
Case kComponentOccurrenceObject:
Call oObjColl.Add(oStartNode.BrowserNodes.Item(i).NativeObject)
Case kCircularOccurrencePatternObject:
Dim oCPatternOccs As ObjectCollection
Set oCPatternOccs = ThisApplication.TransientObjects.CreateObjectCollection
Set oCPatternOccs = GetPatternElements(oStartNode.BrowserNodes.Item(i).BrowserNodes)
If Not oCPatternOccs Is Nothing Then
For j = 1 To oCPatternOccs.Count
Call oObjColl.Add(oCPatternOccs.Item(j))
Next
End If
Case kRectangularOccurrencePatternObject:
Dim oRPatternOccs As ObjectCollection
Set oRPatternOccs = ThisApplication.TransientObjects.CreateObjectCollection
Set oRPatternOccs = GetPatternElements(oStartNode.BrowserNodes.Item(i).BrowserNodes)
If Not oRPatternOccs Is Nothing Then
For j = 1 To oRPatternOccs.Count
Call oObjColl.Add(oRPatternOccs.Item(j))
Next
End If
Case kFeatureBasedOccurrencePatternObject:
Dim oFBPatternOccs As ObjectCollection
Set oFBPatternOccs = ThisApplication.TransientObjects.CreateObjectCollection
Set oFBPatternOccs = GetPatternElements(oStartNode.BrowserNodes.Item(i).BrowserNodes)
If Not oFBPatternOccs Is Nothing Then
For j = 1 To oFBPatternOccs.Count
Call oObjColl.Add(oFBPatternOccs.Item(j))
Next
End If
Case kPlanarSketchObject:
Call oObjColl.Add(oStartNode.BrowserNodes.Item(i).NativeObject)
Case kDerivedPartComponentObject:
'ignore derived components
Case kDerivedAssemblyComponentObject:
'ignore derived components
'Case kBrowserNodeObject: 'By CheckCheck.Master
'?????
Case Else: 'anything else should be an assemblyfeature *?*
Call oObjColl.Add(oStartNode.BrowserNodes.Item(i).NativeObject)
'Search for non-shared Sketches
Dim oSketch As PlanarSketch
Set oSketch = GetBaseSketch(oStartNode.BrowserNodes.Item(i).BrowserNodes)
If Not oSketch Is Nothing Then
Call oObjColl.Add(oSketch)
End If
Dim oSketch3D As Sketch3D
Set oSketch3D = GetBaseSketch3D(oStartNode.BrowserNodes.Item(i).BrowserNodes) 'By CheckCheck.Master
'Set oSketch3D = GetBaseSketch3D(oTopNode.BrowserNodes.Item(i).BrowserNodes)
If Not oSketch3D Is Nothing Then
Call oObjColl.Add(oSketch3D)
End If
End Select
End If
Next
'Setting temporary names
On Error Resume Next
For j = 1 To oObjColl.Count
oObjColl.Item(j).Name = "tmp_" & oObjColl.Item(j).Name
Next
Dim iExit As Integer
Dim sName As String
For i = 1 To oObjColl.Count
iExit = 1
Do
sName = StripTrailingNumbers(oObjColl.Item(i).Name)
If sName = "" Then Exit Do
sName = sName & iExit
oObjColl.Item(i).Name = sName
'Emergency Exit 999
If iExit > 999 Then Exit Do
iExit = iExit + 1
Loop While oObjColl.Item(i).Name <> sName
Next
On Error GoTo 0
End If
End Sub
Private Sub ProcessAssBrowserPane(ByVal oAssDoc As AssemblyDocument)
Dim oBrowserPane As BrowserPane
For Each oBrowserPane In oAssDoc.BrowserPanes
If oBrowserPane.InternalName = "AmBrowserArrangement" Then Exit For
Next
If Not oBrowserPane Is Nothing Then
Dim oTopNode As BrowserNode
Set oTopNode = oBrowserPane.TopNode
Dim i As Integer
Dim j As Integer
Dim oObjColl As ObjectCollection
Set oObjColl = ThisApplication.TransientObjects.CreateObjectCollection
Dim oSketchColl As ObjectCollection
Set oSketchColl = ThisApplication.TransientObjects.CreateObjectCollection
For i = 1 To oTopNode.BrowserNodes.Count
If isInternalNode(oTopNode.BrowserNodes.Item(i)) = False Then
Select Case oTopNode.BrowserNodes.Item(i).NativeObject.Type
Case kComponentOccurrenceObject:
Call oObjColl.Add(oTopNode.BrowserNodes.Item(i).NativeObject)
Case kCircularOccurrencePatternObject:
Dim oCPatternOccs As ObjectCollection
Set oCPatternOccs = ThisApplication.TransientObjects.CreateObjectCollection
Set oCPatternOccs = GetPatternElements(oTopNode.BrowserNodes.Item(i).BrowserNodes)
If Not oCPatternOccs Is Nothing Then
For j = 1 To oCPatternOccs.Count
Call oObjColl.Add(oCPatternOccs.Item(j))
Next
End If
Case kRectangularOccurrencePatternObject:
Dim oRPatternOccs As ObjectCollection
Set oRPatternOccs = ThisApplication.TransientObjects.CreateObjectCollection
Set oRPatternOccs = GetPatternElements(oTopNode.BrowserNodes.Item(i).BrowserNodes)
If Not oRPatternOccs Is Nothing Then
For j = 1 To oRPatternOccs.Count
Call oObjColl.Add(oRPatternOccs.Item(j))
Next
End If
Case kFeatureBasedOccurrencePatternObject:
Dim oFBPatternOccs As ObjectCollection
Set oFBPatternOccs = ThisApplication.TransientObjects.CreateObjectCollection
Set oFBPatternOccs = GetPatternElements(oTopNode.BrowserNodes.Item(i).BrowserNodes)
If Not oFBPatternOccs Is Nothing Then
For j = 1 To oFBPatternOccs.Count
Call oObjColl.Add(oFBPatternOccs.Item(j))
Next
End If
Case kPlanarSketchObject:
Call oSketchColl.Add(oTopNode.BrowserNodes.Item(i).NativeObject)
Case Else: 'Anything else should be an assemblyfeature *?*
Call oObjColl.Add(oTopNode.BrowserNodes.Item(i).NativeObject)
'Search for non-shared Sketches
Dim oSketch As PlanarSketch
Set oSketch = GetBaseSketch(oTopNode.BrowserNodes.Item(i).BrowserNodes)
If Not oSketch Is Nothing Then
Call oSketchColl.Add(oSketch)
End If
End Select
End If
Next
'Setting temporary names
For j = 1 To oObjColl.Count
On Error Resume Next 'By CheckCheck.Master
oObjColl.Item(j).Name = "tmp_" & oObjColl.Item(j).Name
Next
Dim iExit As Integer
Dim sName As String
On Error Resume Next
For j = 1 To oObjColl.Count
iExit = 1
If InStr(oObjColl.Item(j).Name, ":") Then
Do
Err.Clear
oObjColl.Item(j).Name = Mid(Left(oObjColl.Item(j).Name, InStrRev(oObjColl.Item(j).Name, ":") - 1), 5) & ":" & iExit
'Emergency Exit 999
If iExit > 999 Then Exit Do
iExit = iExit + 1
Loop While Err.Number <> 0
Else
Do
sName = StripTrailingNumbers(oObjColl.Item(j).Name)
If sName = "" Then Exit Do
sName = sName & iExit
oObjColl.Item(j).Name = sName
'Notausstieg bei 999
If iExit > 999 Then Exit Do
iExit = iExit + 1
Loop While oObjColl.Item(j).Name <> sName
End If
Next
'Sketches can all have the same name, no need to temp rename them
'Is this a bug in assembly sketches???
For j = 1 To oSketchColl.Count
sName = StripTrailingNumbers(oSketchColl.Item(j).Name)
If Not sName = "" Then
oSketchColl.Item(j).Name = sName & j
End If
Next
On Error GoTo 0
End If
End Sub
Private Function GetPatternElements(ByVal oNodes As BrowserNodesEnumerator) As ObjectCollection
Dim oElementsColl As ObjectCollection
Set oElementsColl = ThisApplication.TransientObjects.CreateObjectCollection
Dim oNode As BrowserNode
For Each oNode In oNodes
If Not oNode.NativeObject Is Nothing Then
If oNode.NativeObject.Type = kComponentOccurrenceObject Then
Call oElementsColl.Add(oNode.NativeObject)
Else
Dim oSubElementsColl As ObjectCollection
Set oSubElementsColl = ThisApplication.TransientObjects.CreateObjectCollection
Set oSubElementsColl = GetPatternElements(oNode.BrowserNodes)
If Not oSubElementsColl Is Nothing Then
Dim i As Integer
For i = 1 To oSubElementsColl.Count
Call oElementsColl.Add(oSubElementsColl.Item(i))
Next
End If
End If
End If
Next
Set GetPatternElements = oElementsColl
End Function
Private Function GetBaseSketch(ByVal oNodes As BrowserNodesEnumerator) As PlanarSketch
Dim oNode As BrowserNode
For Each oNode In oNodes
On Error Resume Next 'By CheckCheck.Master
If Not oNode.NativeObject Is Nothing Then
If oNode.NativeObject.Type = kPlanarSketchObject Then
Set GetBaseSketch = oNode.NativeObject
Exit For
End If
End If
Next
End Function
Private Function GetBaseSketch3D(ByVal oNodes As BrowserNodesEnumerator) As Sketch3D
Dim oNode As BrowserNode
For Each oNode In oNodes
On Error Resume Next 'By CheckCheck.Master
If Not oNode.NativeObject Is Nothing Then
If oNode.NativeObject.Type = kSketch3DObject Then
Set GetBaseSketch3D = oNode.NativeObject
Exit For
End If
End If
Next
End Function
Private Sub RenumberSurfaceBodies(ByVal oNodes As BrowserNodesEnumerator)
On Error Resume Next
Dim i As Integer
For i = 1 To oNodes.Count
oNodes(i).NativeObject.Name = "tmp_" & oNodes(i).NativeObject.Name
Next
Dim sName As String
Dim iExit As Integer
For i = 1 To oNodes.Count
iExit = 1
Do
sName = StripTrailingNumbers(oNodes.Item(i).NativeObject.Name)
If sName = "" Then Exit Do
sName = sName & iExit
oNodes.Item(i).NativeObject.Name = sName
'Notausstieg bei 999
If iExit > 999 Then Exit Do
iExit = iExit + 1
Loop While oNodes(i).NativeObject.Name <> sName
Next
On Error GoTo 0
End Sub
Private Sub RenumberWorkSurfaces(ByVal oNodes As BrowserNodesEnumerator)
On Error Resume Next
Dim i As Integer
For i = 1 To oNodes.Count
oNodes(i).NativeObject.Name = "tmp_" & oNodes(i).NativeObject.Name
Next
Dim sName As String
Dim iExit As Integer
For i = 1 To oNodes.Count
iExit = 1
Do
sName = StripTrailingNumbers(oNodes.Item(i).NativeObject.Name)
If sName = "" Then Exit Do
sName = sName & iExit
oNodes.Item(i).NativeObject.Name = sName
'Notausstieg bei 999
If iExit > 999 Then Exit Do
iExit = iExit + 1
Loop While oNodes(i).NativeObject.Name <> sName
Next
On Error GoTo 0
End Sub
Private Sub RenumberConstraints(ByVal oNodes As BrowserNodesEnumerator)
Dim i As Integer
For i = 1 To oNodes.Count
oNodes(i).NativeObject.Name = "tmp_" & oNodes(i).NativeObject.Name
Next
For i = 1 To oNodes.Count
Dim iExit As Integer
iExit = 1
On Error Resume Next
Do
Err.Clear
oNodes.Item(i).NativeObject.Name = Mid(Left(oNodes.Item(i).NativeObject.Name, InStrRev(oNodes.Item(i).NativeObject.Name, ":") - 1), 5) & ":" & iExit
'Notausstieg bei 999
If iExit > 999 Then Exit Do
iExit = iExit + 1
Loop While Err.Number <> 0
Next
End Sub
Private Function StripTrailingNumbers(ByVal sName As String) As String
If Left(sName, 4) = "tmp_" Then
sName = Mid(sName, 5)
End If
Do While IsNumeric(Right(sName, 1)) = True
sName = Left(sName, Len(sName) - 1)
Loop
StripTrailingNumbers = sName
End Function
Private Function isInternalNode(ByVal oNode As BrowserNode) As Boolean
If oNode.Visible = False Then
isInternalNode = True
Exit Function
End If
Select Case True
Case oNode.BrowserNodeDefinition.Label = "Relationships":
isInternalNode = True
Call RenumberConstraints(oNode.BrowserNodes)
Case oNode.BrowserNodeDefinition.Label = "iMates": 'NativeObject=Part / AssemblyComponentDefinition
isInternalNode = True
Case oNode.BrowserNodeDefinition.Label = "Representations": '"Darstellungen":
isInternalNode = True
Case oNode.BrowserNodeDefinition.Label = "Origin": '"Ursprung":
isInternalNode = True
Case InStr(oNode.BrowserNodeDefinition.Label, "Positionsdarstellungen"):
isInternalNode = True
Case oNode.BrowserNodeDefinition.Label = "End of Features": '"Elementenende":
isInternalNode = True
Case oNode.BrowserNodeDefinition.Label = "Blocks": '"Blöcke": 'NativeObject=Nothing
isInternalNode = True
Case Left(oNode.BrowserNodeDefinition.Label, 12) = "Solid Bodies": '"SurfaceBodies": '"Volumenkörper(":
If oNode.NativeObject Is Nothing Then
Call RenumberSurfaceBodies(oNode.BrowserNodes)
isInternalNode = True
End If
Case Left(oNode.BrowserNodeDefinition.Label, 12) = "WorkSurfaces": '"Flächenkörper(":
If oNode.NativeObject Is Nothing Then
Call RenumberWorkSurfaces(oNode.BrowserNodes)
isInternalNode = True
End If
Case Left(oNode.BrowserNodeDefinition.Label, 10) = "DesignView": '"Ansicht:": 'NativeObject.type=kDesignViewRepresentationobject
If oNode.NativeObject.Type = ObjectTypeEnum.kDesignViewRepresentationObject Then
isInternalNode = True
End If
Case oNode.BrowserNodeDefinition.Label = "End of Part": '"Bauteilende": 'NativeObject.type=kendoffeaturesobject
isInternalNode = True
Case Else:
isInternalNode = False
End Select
End Function
Krieg,
See image, I am trying to add these features to 'oObjColl' but without success.
Would you please point me in the right direction?
I've tried the following your trend to add the Sketches, please find the pieces of code attached followed by the complete code.
At some point the function 'GetBend' recognizes a 'kBendFeatureObject' but then the value 'oNode.NativeObject' is not passed in 'Set GetBend'.
As far as 'Corner' is concerned, I miss the 'NativeObject' completely while I do see it in the list of items.
Where are things going wrong?
Thanks in advance.
Dim oBend As BendOptions
Set oBend = GetBend(oStartNode.BrowserNodes.Item(i).BrowserNodes)
If Not oBend Is Nothing Then
Call oObjColl.Add(oBend)
End If
Dim oCorner As CornerOptions
Set oCorner = GetCorner(oStartNode.BrowserNodes.Item(i).BrowserNodes)
If Not oCorner Is Nothing Then
Call oObjColl.Add(oCorner)
End If
Private Function GetBend(ByVal oNodes As BrowserNodesEnumerator) As BendOptions
Dim oNode As BrowserNode
For Each oNode In oNodes
On Error Resume Next 'By CheckCheck.Master
If Not oNode.NativeObject Is Nothing Then
'MsgBox oNode.NativeObject.Name
If oNode.NativeObject.Type = kBendFeatureObject Then
Set GetBend = oNode.NativeObject
Exit For
End If
End If
Next
End Function
Private Function GetCorner(ByVal oNodes As BrowserNodesEnumerator) As CornerOptions
Dim oNode As BrowserNode
For Each oNode In oNodes
On Error Resume Next 'By CheckCheck.Master
If Not oNode.NativeObject Is Nothing Then
If oNode.NativeObject.Type = kCornerOptionsObject Then
Set GetCorner = oNode.NativeObject
Exit For
End If
End If
Next
End Function
Option Explicit
Private Const sEOP As String = "End of Features"
Private Const sEOF As String = "End of Features"
'Private Const sEOP As String = "End Of Part"
Private Const sConstraints As String = "Constraints"
Private Const siMates As String = "iMates" 'iMates
Private Const sRepresentations As String = "Representations"
Private Const sOrigin As String = "Origin"
Private Const sPosRep As String = "PositionalRepresentations"
Private Const sBlocks As String = "Blocks"
Private Const sSurfaceBodies As String = "SurfaceBodies"
Private Const sWorkSurfaces As String = "WorkSurfaces"
Private Const sDesignView As String = "DesignView:"
'Private Const sEOP As String = "Elementenende" '"End of Features"
'Private Const sEOF As String = "Elementenende" 'End of Features
''Private Const sEOP As String = "Bauteilende" 'EndOfPart
'Private Const sConstraints As String = "Beziehungen" 'Constraints
'Private Const siMates As String = "iMates" 'iMates
'Private Const sRepresentations As String = "Darstellungen" 'Representations
'Private Const sOrigin As String = "Ursprung" 'Origin
'Private Const sPosRep As String = "Positionsdarstellungen" 'PositionalRepresentations
'Private Const sBlocks As String = "Blöcke" 'Blocks
'Private Const sSurfaceBodies As String = "Volumenkörper(" 'SurfaceBodies(
'Private Const sWorkSurfaces As String = "Flächenkörper(" 'WorkSurfaces
'Private Const sDesignView As String = "Ansicht:" 'DesignView:
Public Sub Sort_Browser_KR()
Dim oApp As Inventor.Application
Set oApp = ThisApplication
Dim oDoc As Document
Dim oPartDoc As PartDocument
Dim oAssDoc As AssemblyDocument
If oApp.ActiveDocumentType = kAssemblyDocumentObject Then
Set oAssDoc = oApp.ActiveDocument
Call ProcessAssBrowserPane(oAssDoc)
For Each oDoc In oAssDoc.AllReferencedDocuments
If oDoc.DocumentType = kPartDocumentObject Then
Call ProcessPartBrowserPane(oDoc)
ElseIf oDoc.DocumentType = kAssemblyDocumentObject Then
Call ProcessAssBrowserPane(oDoc)
End If
Next
ElseIf oApp.ActiveDocumentType = kPartDocumentObject Then
Set oPartDoc = oApp.ActiveDocument
Call ProcessPartBrowserPane(oPartDoc)
Else
MsgBox ("Part or Assembly, nothing else.")
End If
End Sub
Private Sub ProcessPartBrowserPane(ByVal oPartDoc As PartDocument)
If oPartDoc.FullFileName Like "*Bieb HML*" Then Exit Sub
'If the "ContentCenter" property set exists, the part came from Content Center
Dim IsCCPart As String
IsCCPart = oPartDoc.PropertySets.PropertySetExists("ContentCenter")
''MsgBox oPartDoc.DisplayName & "Is Content Center Part: " & IsCCPart
If IsCCPart = "True" Then Exit Sub
'Detect if Assembly/Part is Locked/Content Center 'By CheckMaster
If oPartDoc.ComponentDefinition.IsContentMember = True Then Exit Sub
'MsgBox oPartDoc.ComponentDefinition.IsContentMember '' = False Then
'Detect if Assembly/Part is Is Modifiable 'By CheckMaster
'MsgBox oPartDoc.IsModifiable
If oPartDoc.IsModifiable = False Then Exit Sub
' Did not work...
'Detect if Assembly/Part is Read Only 'By CheckMaster
'If oPartDoc.ComponentDefinition.IsContentMember = True Then Exit Sub
'MsgBox oPartDoc.ReadOnly
Dim oBrowserPane As BrowserPane
For Each oBrowserPane In oPartDoc.BrowserPanes
If oBrowserPane.InternalName = "PmDefault" Then Exit For
Next
If Not oBrowserPane Is Nothing Then
Dim oTopNode As BrowserNode
Set oTopNode = oBrowserPane.TopNode
'SheetMetal parts have an additional node for folded model and flat pattern
Dim oStartNode As BrowserNode
If oPartDoc.DocumentSubType.DocumentSubTypeID = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Then 'part
Set oStartNode = oTopNode
ElseIf oPartDoc.DocumentSubType.DocumentSubTypeID = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'sheetmetal part
Set oStartNode = oTopNode.BrowserNodes.Item(1)
Else
MsgBox ("Unknown PartDocumentType detected for file: " & vbCrLf & oPartDoc.FullDocumentName)
Exit Sub
End If
Dim i As Integer
Dim j As Integer
Dim oObjColl As ObjectCollection
Set oObjColl = ThisApplication.TransientObjects.CreateObjectCollection
For i = 1 To oStartNode.BrowserNodes.Count
On Error Resume Next
If isInternalNode(oStartNode.BrowserNodes.Item(i)) = False Then
''Debug.Print oStartNode.BrowserNodes.Item(i).NativeObject.Name
''Debug.Print oStartNode.BrowserNodes.Item(i).NativeObject.Type
Select Case oStartNode.BrowserNodes.Item(i).NativeObject.Type
Case kComponentOccurrenceObject:
Call oObjColl.Add(oStartNode.BrowserNodes.Item(i).NativeObject)
Case kCircularOccurrencePatternObject:
Dim oCPatternOccs As ObjectCollection
Set oCPatternOccs = ThisApplication.TransientObjects.CreateObjectCollection
Set oCPatternOccs = GetPatternElements(oStartNode.BrowserNodes.Item(i).BrowserNodes)
If Not oCPatternOccs Is Nothing Then
For j = 1 To oCPatternOccs.Count
Call oObjColl.Add(oCPatternOccs.Item(j))
Next
End If
Case kRectangularOccurrencePatternObject:
Dim oRPatternOccs As ObjectCollection
Set oRPatternOccs = ThisApplication.TransientObjects.CreateObjectCollection
Set oRPatternOccs = GetPatternElements(oStartNode.BrowserNodes.Item(i).BrowserNodes)
If Not oRPatternOccs Is Nothing Then
For j = 1 To oRPatternOccs.Count
Call oObjColl.Add(oRPatternOccs.Item(j))
Next
End If
Case kFeatureBasedOccurrencePatternObject:
Dim oFBPatternOccs As ObjectCollection
Set oFBPatternOccs = ThisApplication.TransientObjects.CreateObjectCollection
Set oFBPatternOccs = GetPatternElements(oStartNode.BrowserNodes.Item(i).BrowserNodes)
If Not oFBPatternOccs Is Nothing Then
For j = 1 To oFBPatternOccs.Count
Call oObjColl.Add(oFBPatternOccs.Item(j))
Next
End If
Case kPlanarSketchObject:
Call oObjColl.Add(oStartNode.BrowserNodes.Item(i).NativeObject)
Case kDerivedPartComponentObject:
'ignore derived components
Case kDerivedAssemblyComponentObject:
'ignore derived components
'Case kBrowserNodeObject: 'By CheckCheck.Master
'?????
Case Else: 'Anything else should be an assemblyfeature *?*
Call oObjColl.Add(oStartNode.BrowserNodes.Item(i).NativeObject)
'Search for non-shared Sketches
Dim oSketch As PlanarSketch
Set oSketch = GetBaseSketch(oStartNode.BrowserNodes.Item(i).BrowserNodes)
If Not oSketch Is Nothing Then
Call oObjColl.Add(oSketch)
End If
Dim oSketch3D As Sketch3D
Set oSketch3D = GetBaseSketch3D(oStartNode.BrowserNodes.Item(i).BrowserNodes) 'By CheckCheck.Master
'Set oSketch3D = GetBaseSketch3D(oTopNode.BrowserNodes.Item(i).BrowserNodes)
If Not oSketch3D Is Nothing Then
Call oObjColl.Add(oSketch3D)
End If
Dim oBend As BendOptions
Set oBend = GetBend(oStartNode.BrowserNodes.Item(i).BrowserNodes)
If Not oBend Is Nothing Then
Call oObjColl.Add(oBend)
End If
Dim oCorner As CornerOptions
Set oCorner = GetCorner(oStartNode.BrowserNodes.Item(i).BrowserNodes)
If Not oCorner Is Nothing Then
Call oObjColl.Add(oCorner)
End If
End Select
End If
Next
'Setting temporary names
On Error Resume Next
For j = 1 To oObjColl.Count
oObjColl.Item(j).Name = "tmp_" & oObjColl.Item(j).Name
Next
Dim iExit As Integer
Dim sName As String
For i = 1 To oObjColl.Count
iExit = 1
Do
sName = StripTrailingNumbers(oObjColl.Item(i).Name)
If sName = "" Then Exit Do
sName = sName & iExit
oObjColl.Item(i).Name = sName
'Emergency Exit 999
If iExit > 999 Then Exit Do
iExit = iExit + 1
Loop While oObjColl.Item(i).Name <> sName
Next
On Error GoTo 0
End If
End Sub
Private Sub ProcessAssBrowserPane(ByVal oAssDoc As AssemblyDocument)
'MsgBox oAssDoc.FullFileName
If oAssDoc.FullFileName Like "*Bieb HML*" Then Exit Sub
'Detect if Assembly/Part is Is Modifiable 'By CheckMaster
'MsgBox oPartDoc.IsModifiable
If oAssDoc.IsModifiable = False Then Exit Sub
'Did not work for Assembly
'Detect if Assembly/Part is Locked/Content Center 'By CheckMaster
'If oAssDoc.ComponentDefinition.IsContentMember = True Then Exit Sub
'MsgBox oAssDoc.ComponentDefinition.IsContentMember '' = False Then
'If the "ContentCenter" property set exists, the part came from Content Center
Dim IsCCPart As String
IsCCPart = oAssDoc.PropertySets.PropertySetExists("ContentCenter")
''MsgBox oAssDoc.DisplayName & "Assembly Is Content Center Part: " & IsCCPart
If IsCCPart = "True" Then Exit Sub
Dim oBrowserPane As BrowserPane
For Each oBrowserPane In oAssDoc.BrowserPanes
If oBrowserPane.InternalName = "AmBrowserArrangement" Then Exit For
Next
If Not oBrowserPane Is Nothing Then
Dim oTopNode As BrowserNode
Set oTopNode = oBrowserPane.TopNode
Dim i As Integer
Dim j As Integer
Dim oObjColl As ObjectCollection
Set oObjColl = ThisApplication.TransientObjects.CreateObjectCollection
Dim oSketchColl As ObjectCollection
Set oSketchColl = ThisApplication.TransientObjects.CreateObjectCollection
For i = 1 To oTopNode.BrowserNodes.Count
If isInternalNode(oTopNode.BrowserNodes.Item(i)) = False Then
On Error Resume Next
Select Case oTopNode.BrowserNodes.Item(i).NativeObject.Type
Case kComponentOccurrenceObject:
Call oObjColl.Add(oTopNode.BrowserNodes.Item(i).NativeObject)
Case kCircularOccurrencePatternObject:
Dim oCPatternOccs As ObjectCollection
Set oCPatternOccs = ThisApplication.TransientObjects.CreateObjectCollection
Set oCPatternOccs = GetPatternElements(oTopNode.BrowserNodes.Item(i).BrowserNodes)
If Not oCPatternOccs Is Nothing Then
For j = 1 To oCPatternOccs.Count
Call oObjColl.Add(oCPatternOccs.Item(j))
Next
End If
Case kRectangularOccurrencePatternObject:
Dim oRPatternOccs As ObjectCollection
Set oRPatternOccs = ThisApplication.TransientObjects.CreateObjectCollection
Set oRPatternOccs = GetPatternElements(oTopNode.BrowserNodes.Item(i).BrowserNodes)
If Not oRPatternOccs Is Nothing Then
For j = 1 To oRPatternOccs.Count
Call oObjColl.Add(oRPatternOccs.Item(j))
Next
End If
Case kFeatureBasedOccurrencePatternObject:
Dim oFBPatternOccs As ObjectCollection
Set oFBPatternOccs = ThisApplication.TransientObjects.CreateObjectCollection
Set oFBPatternOccs = GetPatternElements(oTopNode.BrowserNodes.Item(i).BrowserNodes)
If Not oFBPatternOccs Is Nothing Then
For j = 1 To oFBPatternOccs.Count
Call oObjColl.Add(oFBPatternOccs.Item(j))
Next
End If
Case kPlanarSketchObject:
Call oSketchColl.Add(oTopNode.BrowserNodes.Item(i).NativeObject)
Case Else: 'Anything else should be an assemblyfeature *?*
Call oObjColl.Add(oTopNode.BrowserNodes.Item(i).NativeObject)
'Search for non-shared Sketches
Dim oSketch As PlanarSketch
Set oSketch = GetBaseSketch(oTopNode.BrowserNodes.Item(i).BrowserNodes)
If Not oSketch Is Nothing Then
Call oSketchColl.Add(oSketch)
End If
End Select
End If
Next
'Setting temporary names
For j = 1 To oObjColl.Count
On Error Resume Next 'By CheckCheck.Master
oObjColl.Item(j).Name = "tmp_" & oObjColl.Item(j).Name
Next
Dim iExit As Integer
Dim sName As String
On Error Resume Next
For j = 1 To oObjColl.Count
iExit = 1
If InStr(oObjColl.Item(j).Name, ":") Then
Do
Err.Clear
oObjColl.Item(j).Name = Mid(Left(oObjColl.Item(j).Name, InStrRev(oObjColl.Item(j).Name, ":") - 1), 5) & ":" & iExit
'Emergency Exit 999
'Debug.Print iExit
If iExit > 999 Then Exit Do
iExit = iExit + 1
Loop While Err.Number <> 0
Else
Do
sName = StripTrailingNumbers(oObjColl.Item(j).Name)
If sName = "" Then Exit Do
sName = sName & iExit
oObjColl.Item(j).Name = sName
'Notausstieg bei 999
If iExit > 999 Then Exit Do
iExit = iExit + 1
Loop While oObjColl.Item(j).Name <> sName
End If
Next
'Sketches can all have the same name, no need to temp rename them
'Is this a bug in assembly sketches???
For j = 1 To oSketchColl.Count
sName = StripTrailingNumbers(oSketchColl.Item(j).Name)
If Not sName = "" Then
oSketchColl.Item(j).Name = sName & j
End If
Next
On Error GoTo 0
End If
End Sub
Private Function GetPatternElements(ByVal oNodes As BrowserNodesEnumerator) As ObjectCollection
Dim oElementsColl As ObjectCollection
Set oElementsColl = ThisApplication.TransientObjects.CreateObjectCollection
Dim oNode As BrowserNode
For Each oNode In oNodes
If Not oNode.NativeObject Is Nothing Then
If oNode.NativeObject.Type = kComponentOccurrenceObject Then
Call oElementsColl.Add(oNode.NativeObject)
Else
Dim oSubElementsColl As ObjectCollection
Set oSubElementsColl = ThisApplication.TransientObjects.CreateObjectCollection
Set oSubElementsColl = GetPatternElements(oNode.BrowserNodes)
If Not oSubElementsColl Is Nothing Then
Dim i As Integer
For i = 1 To oSubElementsColl.Count
Call oElementsColl.Add(oSubElementsColl.Item(i))
Next
End If
End If
End If
Next
Set GetPatternElements = oElementsColl
End Function
Private Function GetBaseSketch(ByVal oNodes As BrowserNodesEnumerator) As PlanarSketch
Dim oNode As BrowserNode
For Each oNode In oNodes
On Error Resume Next 'By CheckCheck.Master
If Not oNode.NativeObject Is Nothing Then
If oNode.NativeObject.Type = kPlanarSketchObject Then
Set GetBaseSketch = oNode.NativeObject
Exit For
End If
End If
Next
End Function
Private Function GetBaseSketch3D(ByVal oNodes As BrowserNodesEnumerator) As Sketch3D
Dim oNode As BrowserNode
For Each oNode In oNodes
On Error Resume Next 'By CheckCheck.Master
If Not oNode.NativeObject Is Nothing Then
If oNode.NativeObject.Type = kSketch3DObject Then
Set GetBaseSketch3D = oNode.NativeObject
Exit For
End If
End If
Next
End Function
Private Function GetBend(ByVal oNodes As BrowserNodesEnumerator) As BendOptions
Dim oNode As BrowserNode
For Each oNode In oNodes
On Error Resume Next 'By CheckCheck.Master
If Not oNode.NativeObject Is Nothing Then
MsgBox oNode.NativeObject.Name
If oNode.NativeObject.Type = kBendFeatureObject Then
Set GetBend = oNode.NativeObject
Exit For
End If
End If
Next
End Function
Private Function GetCorner(ByVal oNodes As BrowserNodesEnumerator) As CornerOptions
Dim oNode As BrowserNode
For Each oNode In oNodes
On Error Resume Next 'By CheckCheck.Master
If Not oNode.NativeObject Is Nothing Then
If oNode.NativeObject.Type = kCornerOptionsObject Then
Set GetCorner = oNode.NativeObject
Exit For
End If
End If
Next
End Function
Private Sub RenumberSurfaceBodies(ByVal oNodes As BrowserNodesEnumerator)
On Error Resume Next
Dim i As Integer
For i = 1 To oNodes.Count
oNodes(i).NativeObject.Name = "tmp_" & oNodes(i).NativeObject.Name
Next
Dim sName As String
Dim iExit As Integer
For i = 1 To oNodes.Count
iExit = 1
Do
sName = StripTrailingNumbers(oNodes.Item(i).NativeObject.Name)
If sName = "" Then Exit Do
sName = sName & iExit
oNodes.Item(i).NativeObject.Name = sName
'Notausstieg bei 999
If iExit > 999 Then Exit Do
iExit = iExit + 1
Loop While oNodes(i).NativeObject.Name <> sName
Next
On Error GoTo 0
End Sub
Private Sub RenumberWorkSurfaces(ByVal oNodes As BrowserNodesEnumerator)
On Error Resume Next
Dim i As Integer
For i = 1 To oNodes.Count
oNodes(i).NativeObject.Name = "tmp_" & oNodes(i).NativeObject.Name
Next
Dim sName As String
Dim iExit As Integer
For i = 1 To oNodes.Count
iExit = 1
Do
sName = StripTrailingNumbers(oNodes.Item(i).NativeObject.Name)
If sName = "" Then Exit Do
sName = sName & iExit
oNodes.Item(i).NativeObject.Name = sName
'Notausstieg bei 999
If iExit > 999 Then Exit Do
iExit = iExit + 1
Loop While oNodes(i).NativeObject.Name <> sName
Next
On Error GoTo 0
End Sub
Private Sub RenumberConstraints(ByVal oNodes As BrowserNodesEnumerator)
Dim i As Integer
For i = 1 To oNodes.Count
oNodes(i).NativeObject.Name = "tmp_" & oNodes(i).NativeObject.Name
Next
For i = 1 To oNodes.Count
Dim iExit As Integer
iExit = 1
On Error Resume Next
Do
Err.Clear
oNodes.Item(i).NativeObject.Name = Mid(Left(oNodes.Item(i).NativeObject.Name, InStrRev(oNodes.Item(i).NativeObject.Name, ":") - 1), 5) & ":" & iExit
'Notausstieg bei 999
If iExit > 999 Then Exit Do
iExit = iExit + 1
Loop While Err.Number <> 0
Next
End Sub
Private Function StripTrailingNumbers(ByVal sName As String) As String
If Left(sName, 4) = "tmp_" Then
sName = Mid(sName, 5)
End If
Do While IsNumeric(Right(sName, 1)) = True
sName = Left(sName, Len(sName) - 1)
Loop
StripTrailingNumbers = sName
End Function
Private Function isInternalNode(ByVal oNode As BrowserNode) As Boolean
If oNode.Visible = False Then
isInternalNode = True
Exit Function
End If
Select Case True
Case oNode.BrowserNodeDefinition.Label = "Relationships":
isInternalNode = True
Call RenumberConstraints(oNode.BrowserNodes)
Case oNode.BrowserNodeDefinition.Label = "iMates": 'NativeObject=Part / AssemblyComponentDefinition
isInternalNode = True
Case oNode.BrowserNodeDefinition.Label = "Representations": '"Darstellungen":
isInternalNode = True
Case oNode.BrowserNodeDefinition.Label = "Origin": '"Ursprung":
isInternalNode = True
Case InStr(oNode.BrowserNodeDefinition.Label, "Positionsdarstellungen"):
isInternalNode = True
Case oNode.BrowserNodeDefinition.Label = "End of Features": '"Elementenende":
isInternalNode = True
Case oNode.BrowserNodeDefinition.Label = "Blocks": '"Blöcke": 'NativeObject=Nothing
isInternalNode = True
Case Left(oNode.BrowserNodeDefinition.Label, 12) = "Solid Bodies": '"SurfaceBodies": '"Volumenkörper(":
If oNode.NativeObject Is Nothing Then
Call RenumberSurfaceBodies(oNode.BrowserNodes)
isInternalNode = True
End If
Case Left(oNode.BrowserNodeDefinition.Label, 12) = "WorkSurfaces": '"Flächenkörper(":
If oNode.NativeObject Is Nothing Then
Call RenumberWorkSurfaces(oNode.BrowserNodes)
isInternalNode = True
End If
Case Left(oNode.BrowserNodeDefinition.Label, 10) = "DesignView": '"Ansicht:": 'NativeObject.type=kDesignViewRepresentationobject
If oNode.NativeObject.Type = ObjectTypeEnum.kDesignViewRepresentationObject Then
isInternalNode = True
End If
Case oNode.BrowserNodeDefinition.Label = "End of Part": '"Bauteilende": 'NativeObject.type=kendoffeaturesobject
isInternalNode = True
Case Else:
isInternalNode = False
End Select
End Function
Hello
The function for the bends should return a bendfeature, not a bendoption.
Dim oBend As BendFeature
Set oBend = GetBend(oStartNode.BrowserNodes.Item(i).BrowserNodes)
If Not oBend Is Nothing Then
Call oObjColl.Add(oBend)
End If
Private Function GetBend(ByVal oNodes As BrowserNodesEnumerator) As BendFeature
Dim oNode As BrowserNode
For Each oNode In oNodes
On Error Resume Next 'By CheckCheck.Master
If Not oNode.NativeObject Is Nothing Then
'MsgBox oNode.NativeObject.Name
If oNode.NativeObject.Type = kBendFeatureObject Then
Set GetBend = oNode.NativeObject
Exit For
End If
End If
Next
End Function
The corner doesn't seem to return anything. This means in fact it's not implemented in API so far or there's something broken. Sorry, I don't see any option to get this work.
Thanks Krieg for your support, 'GetBend' is working now, nice!
Disappointing that 'corner' cannot be made to work.
By means of a 'Watch' the value of the 'NativeObject' appears to be: <Application-defined or object-defined error>.
I can imagine something about your statement, regarding the 'API ObjectModel' it seems that we have the correct 'Corner', so it sounds plausible.
Is there a chance that 'Corner' is accessible through iLogic / VB.net?
Is that related to the 'DLLs' that are being accessed?
I don't think so, but is a 'Label' possibly suitable for a name change?
Greetings!
Hello
The only point to rename/renumber this browser node is in the browsernodedefinition.label property. All labels for corners are named "Corner" and the number. By searching for this kind of name we can find the corner nodes and collect them.
But this can only work if the browser nodes are not renamed manually.
Next (maybe) possible way, the corner labeled nodes only appear within Flange Features, Contour Flange Features and Corner Features. Corner Features are out of scope, because the NativeObject of the browser node returns the corner feature and it's name property.
So we have to concentrate on the other two features.
If the browsernode.nativeobject returns FlangeFeature, the browsernode.browsernodes.item(1) is the bend, item(2) the corner. So we can get browsernode.browsernodes.item(2).browsernodedefinition.label as "name" of the corner. It doesn't matter if renamed or not.
We can do the same for Contour Flange Features. Different from the Flange Feature, we have here the sketch as item(1), bend as item(2) and corner as item(3).
Hope this helps.