- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello
I have a multi body part with a single solid representing multiple timber rails.
What I would like to be able to do is analyse the solid body that represents the rails, and calculate the length/width/thickness for each rail.
The SurfaceBody.OrientedMinimumRangeBox Property works fine for the whole solid, but I would need to do the same to the faceshells belonging to the solid body.
The code that I have so far works with the x,y,z co-ordinates of the faceshell, but I would like to know how to get the correct dimensions for a faceshell that is not aligned to the x,y,z axis.
Part File attached, with rules inside.
Any ideas?
Threads that I have referenced for the code are:
https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/faceshell-orientedrangebox/m-p/10472442
Code Snippet 1 (Faceshell Rangebox)
doc = ThisDoc.Document oDef = doc.ComponentDefinition Dim oSB As SurfaceBody For Each oSB In oDef.SurfaceBodies If oSB.Name.Contains("REF_RAILS") Then For Each fs As FaceShell In oSB.FaceShells If fs.IsVoid Then Continue For Dim DeltaX, DeltaY, DeltaZ As Double Dim fsBox As Box = fs.RangeBox DeltaX = fsBox.MaxPoint.X - fsBox.MinPoint.X DeltaY = fsBox.MaxPoint.Y - fsBox.MinPoint.Y DeltaZ = fsBox.MaxPoint.Z - fsBox.MinPoint.Z ' Convert lengths to document's length units. Dim uom As UnitsOfMeasure = doc.UnitsOfMeasure DeltaX = uom.ConvertUnits(DeltaX, "cm", uom.LengthUnits) DeltaY = uom.ConvertUnits(DeltaY, "cm", uom.LengthUnits) DeltaZ = uom.ConvertUnits(DeltaZ, "cm", uom.LengthUnits) ' Sort lengths from smallest to largest. Dim lengths As New List(Of Double) From {DeltaX, DeltaY, DeltaZ } lengths.Sort Dim minLength As Double = lengths(2) Dim midLength As Double = lengths(1) Dim maxLength As Double = lengths(0) ' Display minimum rangebox size. MessageBox.Show("Rangebox Size: " & minLength.ToString("#.###") & " x " & midLength.ToString("#.###") & " x " & maxLength.ToString("#.###"), oSB.Name, MessageBoxButtons.OK, MessageBoxIcon.Information) Next End If Next
Code Snippet 2 (Surface Body Orientated Minimum Rangebox)
doc = ThisDoc.Document oDef = doc.ComponentDefinition ' Get surface body to measure Dim oSB As SurfaceBody For Each oSB In oDef.SurfaceBodies Dim minBox As OrientedBox = oSB.OrientedMinimumRangeBox ' Get length of each side of mininum range box. Dim dir1 As Double = minBox.DirectionOne.Length Dim dir2 As Double = minBox.DirectionTwo.Length Dim dir3 As Double = minBox.DirectionThree.Length ' Convert lengths to document's length units. Dim uom As UnitsOfMeasure = doc.UnitsOfMeasure dir1 = uom.ConvertUnits(dir1, "cm", uom.LengthUnits) dir2 = uom.ConvertUnits(dir2, "cm", uom.LengthUnits) dir3 = uom.ConvertUnits(dir3, "cm", uom.LengthUnits) ' Sort lengths from smallest to largest. Dim lengths As New List(Of Double) From {dir1, dir2, dir3 } lengths.Sort Dim minLength As Double = lengths(0) Dim midLength As Double = lengths(1) Dim maxLength As Double = lengths(2) ' Display minimum rangebox size. MessageBox.Show(" Oriented Minimum Rangebox Size: " & minLength.ToString("#.###") & " x " & midLength.ToString("#.###") & " x " & maxLength.ToString("#.###"), oSB.Name, MessageBoxButtons.OK, MessageBoxIcon.Information) Next
Solved! Go to Solution.