I want to do a macro that roll back the design tree of a part before the first feature, insert a part, lock all references, delete the part inserted with the keep/delete body feature and then roll back the design tree after the last feature.
I'm new with Solidwork's macro and for now I'm able to insert the part and lock all the references, but I'm not able to manipulate the design tree and delete my part inserted with the keep/delete body feature. Can someone help me with that ?
Thanks
SolidworksApi macros
So here is a part of the code that works :
Set swFeatMgr = swModel.FeatureManager
boolstatus = swFeatMgr.EditRollback(swMoveRollbackBarToBeforeFeature, "Boss-Extrude1")
Set myFeature = swModel.InsertPart2(NewFilePath, 19)
swModel.ClearSelection2 True
CNC_Name = swModel.GetTitle
CNC_Name = CNC_Name & "-CNC"
boolstatus = swModel.Extension.SelectByID2(CNC_Name, "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
swModel.LockAllExternalReferences
swModel.ClearSelection2 True
boolstatus = swModel.Extension.SelectByID2("-<1/16 1/8 =< Ep < 1/2 (0.0625) Diameter Hole1> ", "SOLIDBODY", 4.47525398873836E-02, 8.28659607474833E-02, 9.52499999988277E-03, True, 0, Nothing, 0)
Set myFeature = swFeatMgr.InsertDeleteBody2(False)
swModel.ClearSelection2 True
boolstatus = swFeatMgr.EditRollback(swMoveRollbackBarToBeforeFeature, "")
But this code only works for a specific part. I need to find how to get the name of the first feature in the design tree and how to get the name of the solid body of the part inserted (bold text) like I do with the model title. Someone knows how to do that ?