Why does CreateBodyFromBox3 return Nothing?

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
Answers 4
SF
SF 2010-11-23 Best Answer

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

JP
JP 2010-11-23

Hi Greg,

Try declaring
Dim faBoxDimArray(8) As Double
instead of as Object

-John

GA
GA 2010-11-23

Thanks, Scott and John.

SW API support has opened up a Service Request on this.

GA
GA 2010-11-30

This from SW API Support:

<p>I believe you have hit upon one of our already known issue-</p><p></p><p>SPR 414400 -  CreateBodyFromBox3 doesn't work well with managed languages</p><p></p><p>Although the SPR says it doesn't works with the managed languages but it effects all API clients including the VBA macro.</p><p></p>