This might seem a silly idea but if this macro is possible it would solve many problems for us (basically make synchronous modeling possible in a way…)
When you import i.e. a parasolid file there is only one ‘feature’ present. The body (or the bodies) which are named i.e. ‘imported1’.
Is it possible to write a macro that does this for me? That basically takes the geometry of what I have already designed, erases the whole feature tree and puts only this feature in there? I don’t care if it looses all face IDs etc.
I actually want to skip the route of having to go export & then import again. It’s important to still use the same file if possible.
Does anybody have an idea if this is possible?
Edit: After so many responses I have to clarify something. It is important that the feature in the feature tree is the ‘imported’ feature. No other feature (converted etc.) gives you the possibility to automatically recognize features for you!
I feel like it should be possible somehow because you can MODIFY THE BODY i.e. re-order imported features (or delete them), modify them (& then delete the recognized features from the tree) or use a move/copy body and then delete the move/copy body (thank you josh !) without it affecting the feature tree.
Is there a reason why you cannot overwrite the existing file with new file? As long as the process doesn’t delete the file PDM will treat it as the same “File” (it keeps history and doc ID).
Sub main()
Set swApp = Application.SldWorks
Set mDoc = swApp.ActiveDoc
Set pDoc = mDoc
vBodies = pDoc.GetBodies2(swBodyType_e.swSolidBody, True)
For Each vBody In vBodies
Dim nextBody As Body2
Set nextBody = vBody
Dim bodyCopy As Body2
Set bodyCopy = nextBody.Copy2(False)
vFeatures = nextBody.GetFeatures()
For Each vFeature In vFeatures
Dim nextFeature As Feature
Set nextFeature = vFeature
If Not InStr(nextFeature.Name, "Imported") Then
nextFeature.Select2 True, 0
End If
Next
pDoc.CreateFeatureFromBody3 bodyCopy, False, swCreateFeatureBodyOpts_e.swCreateFeatureBodyCheck
Next
Set mExt = mDoc.Extension
mExt.DeleteSelection2 (swDeleteSelectionOptions_e.swDelete_Absorbed + swDeleteSelectionOptions_e.swDelete_Children)
End Sub