AnsweredAssumed Answered

Choose body in View (c#)

Question asked by Roman Mettler on May 12, 2018
Latest reply on May 13, 2018 by Roman Mettler

Hello, im trying to define view body, it should be easily done by "swView.Bodies = new object[]{ somebody }", i created a vba macro with same principle (taken from api help ) and all works fine, in c# i cant make it work, debugging shows that the contents of "View.Bodies" never get replaced with new array... some clue?

c# version:

        public void SetBody()
            object[] b = new object[1];
            ModelDoc2 modDoc = SwApp.ActiveDoc;
            SelectionMgr selectionMgr = modDoc.ISelectionManager;
            SolidWorks.Interop.sldworks.View v = selectionMgr.GetSelectedObject6(1, -1);
            modDoc = v.ReferencedDocument;
            var bodies = ((PartDoc)modDoc).GetBodies2((int)swBodyType_e.swSolidBody, true);
            b[0] = bodies[1];

            v.Bodies = b;


VBA version:


Dim Bodies(1) As Object
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swView As SldWorks.View
Dim arrBody As Variant

Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swView = swSelMgr.GetSelectedObject6(1, -1)
Set swModel = swView.ReferencedDocument
arrBody = swModel.GetBodies2(swSolidBody, True)
Set Bodies(0) = arrBody(1)
swView.Bodies = Bodies



any help would be much appreciated...