I want to get the wire bodies added in the PART documents. I have used API Part::GetBodies2 with swBodyType_e :: swWireBody but it cant return any bodies.
Also is there any API to get temporary bodies displayed in the part document?
You need to traverse all edges and cal IEdge::GetBody and check if that is a wire body. Check this example for the reference: Offset planar curve (wire body) using SOLIDWORKS API.
You should have the list of all temp bodies. Those are created by you and the pointer is stored by you (so you have all the control) and you should have the list of those. Or are you trying to get the display bodies displayed by other macros, plugins?
No. I have created macro feature having display bodies. I want to retrieve this display bodies from macro feature added in Sollidworks.
Do you mean you return them from the macro feature regenerate method? If so, those are no longer temp bodies but permanent bodies, so you can just have IFeature::GetFaces()=>IFace2::GetBody to list those bodies.
Yes I want to return from the macro feature regenerate method. IFeature::GetFaces()=>IFace2::GetBody works for solid bodies. I want to retrieve wire bodies.
I see, then IFeature::GetEdges->IEdge::GetBody
In Solidworks 2019 there is no IFeature::GetEdges API present. Only I can get faces from feature using IFeature::GetFaces.
You are right, sorry, didn't look into API help. I do not know the answer on top of my head. I will try to look into this. Do you return one curve or multiple from your macro feature?
Thank you. I have returned multiple curve from macro feature.
I can think of a nasty workaround:
- rollback to just before the macro feature and call PartDoc.GetBodies(swWireBody)
- roll forward to just after the macro feature and call GetBodies again
any additional bodies in the second list must have been created by the macro feature.
Thank you for information. I have tried above workaround but number of bodies before and after macro feature is zero.
This workaround is working for swSheetBody, swSolidBody but not for swWireBody
Any chance you can attach the part? Simplify it down to the basics if you want.
Simon, I believe Mahadev is using C++ add-in so you will need to register the macro feature COM object to load the macro feature in the model. You can use this example instead, which is inserting macro feature with geometry using VBA, so no need ot register any COM objects: Generate box geometry (solid, sheet, wire) Macro Feature using SOLIDWORKS API
Set the following at the beggining of the macro to create wire body:
Const BODY_TYPE As Integer = swBodyType_e.swWireBody
Now, the tricky part is how to get the list of edges from this feature.
Thank you for information.
Do you mean at before the creation of wire body or before the creation of macro feature?
I notice that the wire bodies created by the macro are Temporary bodies. I don't think they actually belong to the part.
But I can't work out how to turn them into true wire bodies.
It is a temp body only within regenerate method of macro feature. Once it is returned it is no longer a temp body.
If you select any edge of this body:
and run the following macro:
Dim swApp As SldWorks.SldWorksDim swModel As SldWorks.ModelDoc2
Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc Dim swSelMgr As SldWorks.SelectionMgr Set swSelMgr = swModel.SelectionManager Dim swEdge As SldWorks.Edge Set swEdge = swSelMgr.GetSelectedObject6(1, -1) Dim swBody As SldWorks.Body2 Set swBody = swEdge.GetBody Debug.Print "Is Temp: " & swBody.IsTemporaryBody Debug.Print "Is Wire: " & (swBody.GetType() = swBodyType_e.swWireBody) End Sub
The result would be:
Is Temp: FalseIs Wire: True
Retrieving data ...