In a Part document, I'm trying to use CreateBodyFromBox3 to create a cube with unit dimensions.
The edges of the cube will be aligned with the XYZ axes.
Here is the code:
Dim swBodyAligned As SolidWorks.Interop.sldworks.Body2
Dim swModeler As SolidWorks.Interop.sldworks.Modeler
Dim faBoxDimArray(8) As Object
swModeler = swApp.GetModeler
faBoxDimArray(0) = 0
faBoxDimArray(1) = 0
faBoxDimArray(2) = 0
faBoxDimArray(3) = 0
faBoxDimArray(4) = 0
faBoxDimArray(5) = 1
faBoxDimArray(6) = 1
faBoxDimArray(7) = 1
faBoxDimArray(8) = 1
swBodyUnitAligned = swModeler.CreateBodyFromBox3(faBoxDimArray)
After the call, swBodyUnitAligned is Nothing.
What am I doing wrong?
SolidworksApi macros
Hi,
swBodyUnitAligned is not declared.
The old api works (below). Perhaps the new one is broken. Check with api support.
Dim swDoc As ModelDoc2 = swApp.ActiveDoc
Dim swBodyAligned As Body2 = Nothing
Dim swModeler As Modeler = swApp.GetModeler
Dim faBoxDimArray(8) As Double
faBoxDimArray(0) = 0
faBoxDimArray(1) = 0
faBoxDimArray(2) = 0
faBoxDimArray(3) = 0
faBoxDimArray(4) = 0
faBoxDimArray(5) = 1
faBoxDimArray(6) = 1
faBoxDimArray(7) = 1
faBoxDimArray(8) = 1
swBodyAligned = swModeler.CreateBodyFromBox(faBoxDimArray)'works
'swBodyAligned = swModeler.CreateBodyFromBox3(faBoxDimArray) 'not working
swBodyAligned.Display3(swDoc, 250, swTempBodySelectOptions_e.swTempBodySelectable)
Scott
Hi Greg,
Try declaring
Dim faBoxDimArray(8) As Double
instead of as Object
-John
Thanks, Scott and John.
SW API support has opened up a Service Request on this.
This from SW API Support: