Getting the part sizes with Visual basic apprentice

Anonymous

Getting the part sizes with Visual basic apprentice

Anonymous
Not applicable
Can anybody help?

I need to convert the following code, from Inventor vba to Visual basic for Apprentice...

Sub GetPartSize()
Dim i As Long
Dim rangeBox As Box
Dim surfBody As SurfaceBody
Dim pxMin As Double, pyMin As Double, pzMin As Double
Dim pxMax As Double, pyMax As Double, pzMax As Double
Dim procType As Long

Set surfBody = doc.ComponentDefinition.SurfaceBodies(1)

Set rangeBox = surfBody.rangeBox
With rangeBox
pxMin = .MinPoint.x: pyMin = .MinPoint.y: pzMin = .MinPoint.z
pxMax = .MaxPoint.x: pyMax = .MaxPoint.y: pzMax = .MaxPoint.z
End With

For i = 2 To doc.ComponentDefinition.SurfaceBodies.Count
Set surfBody = doc.ComponentDefinition.SurfaceBodies(i)
Set rangeBox = surfBody.rangeBox
With rangeBox
pxMin = Min(.MinPoint.x, pxMin): pyMin = Min(.MinPoint.y, pyMin): pzMin = Min(.MinPoint.z, pzMin)
pxMax = Max(.MaxPoint.x, pxMax): pyMax = Max(.MaxPoint.y, pyMax): pzMax = Max(.MaxPoint.z, pzMax)
End With
Next

PartSizeX = 10 * (pxMax - pxMin)
PartSizeY = 10 * (pyMax - pyMin)
PartSizeZ = 10 * (pzMax - pzMin)
End Sub

I cannot get it to work. I need to know the PartSizes (mm)

Many thanks for your assistance.

Carolyn
0 Likes
Reply
330 Views
1 Reply
Reply (1)

Anonymous
Not applicable
Hello Carolyn, When your working with ApprenticeServer you are dealing with an ApprenticeServerDocument or an ApprenticeServerDrawingDocument. So I presume you have opened a part documetn in ApprenticeServer using the Open method. You have to have a valid instance of ApprenticeServer first. Dim objApprenServer as ApprenticeServerComponent set objApprenServer = new ApprenitceServerComponent Make sure you have a referenct to "Autodesk Inventor's Apprentice Object Library" not the Autodesk Inventor Object Library. Once you open your document, you need to verify that SurfaceBidies exist check the Count property. Once you have a body you can get to its RangeBox. Keep in mind that internally Inventor uses Centimeter as the unit of length internall. There is an object called UnitsOfMeasure that will allow you to convert back and forward to the unit type you need. This is documented in the Programmers Help file and also on the Inventor installation there is a sample under the VB SDK folder for UnitsOfMeasure. The rest of your code looks like it should work. I hope this helps Charles API QA Inventor "CarolynH" wrote in message news:10633216.1083828898786.JavaMail.jive@jiveforum1.autodesk.com... > Can anybody help? > > I need to convert the following code, from Inventor vba to Visual basic for Apprentice... > > Sub GetPartSize() > Dim i As Long > Dim rangeBox As Box > Dim surfBody As SurfaceBody > Dim pxMin As Double, pyMin As Double, pzMin As Double > Dim pxMax As Double, pyMax As Double, pzMax As Double > Dim procType As Long > > Set surfBody = doc.ComponentDefinition.SurfaceBodies(1) > > Set rangeBox = surfBody.rangeBox > With rangeBox > pxMin = .MinPoint.x: pyMin = .MinPoint.y: pzMin = .MinPoint.z > pxMax = .MaxPoint.x: pyMax = .MaxPoint.y: pzMax = .MaxPoint.z > End With > > For i = 2 To doc.ComponentDefinition.SurfaceBodies.Count > Set surfBody = doc.ComponentDefinition.SurfaceBodies(i) > Set rangeBox = surfBody.rangeBox > With rangeBox > pxMin = Min(.MinPoint.x, pxMin): pyMin = Min(.MinPoint.y, pyMin): pzMin = Min(.MinPoint.z, pzMin) > pxMax = Max(.MaxPoint.x, pxMax): pyMax = Max(.MaxPoint.y, pyMax): pzMax = Max(.MaxPoint.z, pzMax) > End With > Next > > PartSizeX = 10 * (pxMax - pxMin) > PartSizeY = 10 * (pyMax - pyMin) > PartSizeZ = 10 * (pzMax - pzMin) > End Sub > > I cannot get it to work. I need to know the PartSizes (mm) > > Many thanks for your assistance. > > Carolyn
0 Likes