Add Feature to MirrorFeature

<?xml encoding=”UTF-8″>By Adam Nagy

You tried to use this code, but it does not work:

Sub UpdateMirrorFeature()
Dim ss As SelectSet
Set ss = ThisApplication.ActiveDocument.SelectSet
Dim mf As MirrorFeature
Set mf = ss(1)
Dim ptf As PunchToolFeature
Set ptf = ss(2)
Call mf.ParentFeaturesAdd(ptf)
End Sub

Sometimes the API is not completely intuitive and you run into a scenario similar to the one mentioned here – i.e. first you have to take the property object, modify it, then assign it back to the property.

First select the MirrorFeature then the Feature you want to add to it (make sure it is shown in the browser before the MirrorFeature otherwise it will not be available in the UI either to be added to that MirrorFeature), then run the code:

Sub UpdateMirrorFeature()
Dim ss As SelectSet
Set ss = ThisApplication.ActiveDocument.SelectSet
Dim mf As MirrorFeature
Set mf = ss(1)
Dim ptf As PunchToolFeature
Set ptf = ss(2)
' Take the property object
Dim oc As ObjectCollection
Set oc = mf.ParentFeatures
' Modify it
Call oc.Add(ptf)
' Assign it back to the property
mf.ParentFeatures = oc
End Sub

And the result:

Mirrorfeature

 


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading