Creating a bonding box for all parts & sub assembles within Top level assembly

Creating a bonding box for all parts & sub assembles within Top level assembly

GKPByDesign
Advocate Advocate
1,758 Views
17 Replies
Message 1 of 18

Creating a bonding box for all parts & sub assembles within Top level assembly

GKPByDesign
Advocate
Advocate

I am sure this has be discussed any times. But I require the following

 

- Create bonding box

        - Length and Width only not thickness. 

        - Length and width to be defended as iProperties of the same nae 'Length" & 'Width'

        - Sketch to be made invisible

        - Length and width to be constraint so that auto updates can occur (this may be hard to implement) 

 

I understand orientation has an effect with bounding boxes but at this stage I am sure this shouldn't be an issue. 

 

I found some old code below, but I require this to be within iLogic, and I think the code below is VBA?  Can someone help please

 

 Public Sub FindRangeBoxWithFacet(ByVal app As Inventor.Application)
 
        Dim oDoc As AssemblyDocument
        oDoc = app.ActiveDocument
 
        ' Set a reference to component definition of the active document.
        ' This assumes that a part or assembly document is active.
        Dim oCompDef As AssemblyComponentDefinition
        oCompDef = app.ActiveDocument.ComponentDefinition
 
        Dim aoRanges As Box = Nothing
 
        If oCompDef.Occurrences(1).SurfaceBodies.Count > 0 Then
            ' Set a reference to the body of the part.
            Dim oBody As SurfaceBody
            oBody = oCompDef.Occurrences(1).SurfaceBodies.Item(1)
 
            Dim iVertexCount As Integer
            Dim iFacetCount As Integer
            Dim adVertexCoords(0) As Double
            Dim adNormalVectors(0) As Double
            Dim aiVertexIndices(0) As Integer
 
            ' Determine the highest tolerance of the existing facet sets.
            Dim ToleranceCount As Long
            Dim ExistingTolerances(0) As Double
            Call oBody.GetExistingFacetTolerances(
                ToleranceCount, ExistingTolerances)
 
            Dim i As Long
            Dim BestTolerance As Double
            For i = 0 To ToleranceCount - 1
                If i = 0 Then
                    BestTolerance = ExistingTolerances(i)
                ElseIf ExistingTolerances(i) < BestTolerance Then
                    BestTolerance = ExistingTolerances(i)
                End If
            Next
 
            Call oBody.GetExistingFacets(
                BestTolerance,
                iVertexCount,
                iFacetCount,
                adVertexCoords,
                adNormalVectors,
                aiVertexIndices)
 
            Dim cn As Long
            Dim minPt As Point
            Dim maxPt As Point
 
 
            For cn = LBound(adVertexCoords) To UBound(adVertexCoords) Step 3
                ' The Range box can be identified by the fact that the aoRanges
                ' variable will still be Nothing.
                If aoRanges Is Nothing Then
                    'Initialize the range box with the first vertex
                    aoRanges = app.TransientGeometry.CreateBox
                    Dim firstPt(2) As Double
                    firstPt(0) = adVertexCoords(cn)
                    firstPt(1) = adVertexCoords(cn + 1)
                    firstPt(2) = adVertexCoords(cn + 2)
                    Call aoRanges.PutBoxData(firstPt, firstPt)
                Else
                    minPt = aoRanges.MinPoint
                    maxPt = aoRanges.MaxPoint
 
                    If (minPt.X > adVertexCoords(cn)) Then
                        minPt.X = adVertexCoords(cn)
                    End If
                    If (minPt.Y > adVertexCoords(cn + 1)) Then
                        minPt.Y = adVertexCoords(cn + 1)
                    End If
                    If (minPt.Z > adVertexCoords(cn + 2)) Then
                        minPt.Z = adVertexCoords(cn + 2)
                    End If
                    aoRanges.MinPoint = minPt
                    If (maxPt.X < adVertexCoords(cn)) Then
                        maxPt.X = adVertexCoords(cn)
                    End If
                    If (maxPt.Y < adVertexCoords(cn + 1)) Then
                        maxPt.Y = adVertexCoords(cn + 1)
                    End If
                    If (maxPt.Z < adVertexCoords(cn + 2)) Then
                        maxPt.Z = adVertexCoords(cn + 2)
                    End If
                    aoRanges.MaxPoint = maxPt
                End If
            Next
        End If
 
        ' Check to see if range box graphics information already exists.
        Dim oClientGraphics As ClientGraphics
        Dim oLineGraphics As LineGraphics
        Dim oBoxNode As GraphicsNode
        Dim oGraphicsData As GraphicsDataSets
 
        Try
 
            oGraphicsData = oDoc.GraphicsDataSetsCollection("RangeBoxGraphics")
            oClientGraphics = oCompDef.ClientGraphicsCollection
                ("RangeBoxGraphics")
 
            oGraphicsData.Delete()
            oClientGraphics.Delete()
 
        Catch ex As Exception
 
 
        End Try
 
        ' Create a graphics data set object.  This object contains all of the
        ' information used to define the graphics.
        Dim oDataSets As GraphicsDataSets
        oDataSets = oDoc.GraphicsDataSetsCollection.Add("RangeBoxGraphics")
 
        ' Create a coordinate set.
        Dim oCoordSet As GraphicsCoordinateSet
        oCoordSet = oDataSets.CreateCoordinateSet(1)
 
        ' Create the client graphics for this compdef.
        oClientGraphics = oCompDef.ClientGraphicsCollection.Add
            ("RangeBoxGraphics")
 
        ' Set a reference to the transient geometry object for user later.
        Dim oTransGeom As TransientGeometry
        oTransGeom = app.TransientGeometry
 
        ' Create a graphics node.
        oBoxNode = oClientGraphics.AddNode(1)
        oBoxNode.Selectable = False
 
        ' Create line graphics.
        oLineGraphics = oBoxNode.AddLineGraphics
        oLineGraphics.CoordinateSet = oCoordSet
 
        Dim dBoxLines(12 * 6 - 1) As Double
 
        Dim MinPoint(2) As Double
        Dim MaxPoint(2) As Double
        Call aoRanges.GetBoxData(MinPoint, MaxPoint)
 
        ' Line 1
        dBoxLines(0) = MinPoint(0)
        dBoxLines(1) = MinPoint(1)
        dBoxLines(2) = MinPoint(2)
        dBoxLines(3) = MaxPoint(0)
        dBoxLines(4) = MinPoint(1)
        dBoxLines(5) = MinPoint(2)
 
        ' Line 2
        dBoxLines(6) = MinPoint(0)
        dBoxLines(7) = MinPoint(1)
        dBoxLines(8) = MinPoint(2)
        dBoxLines(9) = MinPoint(0)
        dBoxLines(10) = MaxPoint(1)
        dBoxLines(11) = MinPoint(2)
 
        ' Line 3
        dBoxLines(12) = MinPoint(0)
        dBoxLines(13) = MinPoint(1)
        dBoxLines(14) = MinPoint(2)
        dBoxLines(15) = MinPoint(0)
        dBoxLines(16) = MinPoint(1)
        dBoxLines(17) = MaxPoint(2)
 
        ' Line 4
        dBoxLines(18) = MaxPoint(0)
        dBoxLines(19) = MaxPoint(1)
        dBoxLines(20) = MaxPoint(2)
        dBoxLines(21) = MinPoint(0)
        dBoxLines(22) = MaxPoint(1)
        dBoxLines(23) = MaxPoint(2)
 
        ' Line 5
        dBoxLines(24) = MaxPoint(0)
        dBoxLines(25) = MaxPoint(1)
        dBoxLines(26) = MaxPoint(2)
        dBoxLines(27) = MaxPoint(0)
        dBoxLines(28) = MinPoint(1)
        dBoxLines(29) = MaxPoint(2)
 
        ' Line 6
        dBoxLines(30) = MaxPoint(0)
        dBoxLines(31) = MaxPoint(1)
        dBoxLines(32) = MaxPoint(2)
        dBoxLines(33) = MaxPoint(0)
        dBoxLines(34) = MaxPoint(1)
        dBoxLines(35) = MinPoint(2)
 
        ' Line 7
        dBoxLines(36) = MinPoint(0)
        dBoxLines(37) = MaxPoint(1)
        dBoxLines(38) = MinPoint(2)
        dBoxLines(39) = MaxPoint(0)
        dBoxLines(40) = MaxPoint(1)
        dBoxLines(41) = MinPoint(2)
 
        ' Line 8
        dBoxLines(42) = MinPoint(0)
        dBoxLines(43) = MaxPoint(1)
        dBoxLines(44) = MinPoint(2)
        dBoxLines(45) = MinPoint(0)
        dBoxLines(46) = MaxPoint(1)
        dBoxLines(47) = MaxPoint(2)
 
        ' Line 9
        dBoxLines(48) = MaxPoint(0)
        dBoxLines(49) = MinPoint(1)
        dBoxLines(50) = MaxPoint(2)
        dBoxLines(51) = MaxPoint(0)
        dBoxLines(52) = MinPoint(1)
        dBoxLines(53) = MinPoint(2)
 
        ' Line 10
        dBoxLines(54) = MaxPoint(0)
        dBoxLines(55) = MinPoint(1)
        dBoxLines(56) = MaxPoint(2)
        dBoxLines(57) = MinPoint(0)
        dBoxLines(58) = MinPoint(1)
        dBoxLines(59) = MaxPoint(2)
 
        ' Line 11
        dBoxLines(60) = MinPoint(0)
        dBoxLines(61) = MinPoint(1)
        dBoxLines(62) = MaxPoint(2)
        dBoxLines(63) = MinPoint(0)
        dBoxLines(64) = MaxPoint(1)
        dBoxLines(65) = MaxPoint(2)
 
        ' Line 12
        dBoxLines(66) = MaxPoint(0)
        dBoxLines(67) = MinPoint(1)
        dBoxLines(68) = MinPoint(2)
        dBoxLines(69) = MaxPoint(0)
        dBoxLines(70) = MaxPoint(1)
        dBoxLines(71) = MinPoint(2)
 
        ' Assign the points into the coordinate set.
        Call oCoordSet.PutCoordinates(dBoxLines)
 
        ' Update the display.
        app.ActiveView.Update()
 
    End Sub
 
0 Likes
1,759 Views
17 Replies
Replies (17)
Message 2 of 18

bradeneuropeArthur
Mentor
Mentor

would this be sufficient for you:

 

Dim a As PartDocument ' or Document ' or AssemblyDocument
a = ThisApplication.ActiveDocument

Dim b As ComponentDefinition
b = a.ComponentDefinition

Dim c As Box
c = b.RangeBox


Dim dmax As Point
dmax = c.MaxPoint

Dim dmin As Point
dmin = c.MinPoint


MsgBox(dmax.X - dmin.X & " cm " & dmax.Y - dmin.Y & " cm " & dmax.Z - dmin.Z & " cm ")
Try
	Parameter("Length") = dmax.X - dmin.X

	Catch
Dim pa1 As Inventor.Parameter
pa1 = a.ComponentDefinition.Parameters.UserParameters.AddByValue("Length", dmax.X - dmin.X, "mm")	
pa1.ExposedAsProperty = True
pa1.CustomPropertyFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision
pa1.CustomPropertyFormat.ShowTrailingZeros = False
pa1.CustomPropertyFormat.ShowLeadingZeros = False
pa1.CustomPropertyFormat.ShowUnitsString = False
pa1.CustomPropertyFormat.Units = "mm"
		End Try

Try
	Parameter("Width") = dmax.Y - dmin.Y
	Catch
Dim pa2 As Inventor.Parameter
pa2 = a.ComponentDefinition.Parameters.UserParameters.AddByValue("Width", dmax.Y - dmin.Y, "mm")
pa2.ExposedAsProperty = True
pa2.CustomPropertyFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision
pa2.CustomPropertyFormat.ShowTrailingZeros = False
pa2.CustomPropertyFormat.ShowLeadingZeros = False
pa2.CustomPropertyFormat.ShowUnitsString = False
pa2.CustomPropertyFormat.Units = "mm"
 		End Try
 
 Try
	 Parameter("Thickness") = dmax.Z - dmin.Z
	 Catch
		 
Dim pa3 As Inventor.Parameter
pa3 = a.ComponentDefinition.Parameters.UserParameters.AddByValue("Thickness", dmax.Z - dmin.Z, "mm")
pa3.ExposedAsProperty = True
pa3.CustomPropertyFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision
pa3.CustomPropertyFormat.ShowTrailingZeros = False
pa3.CustomPropertyFormat.ShowLeadingZeros = False
pa3.CustomPropertyFormat.ShowUnitsString = False
pa3.CustomPropertyFormat.Units = "mm"
		End Try


Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 18

GKPByDesign
Advocate
Advocate

applying the code at an assembly level gives this result. Bare in mind I am running this on an assembly created by running 'Make Components' which are created using my own part template. Not sure if that is causing the issue? 

 

Error in rule: gkp-Bounding Box, in document: Showcase - Carcass.iam

Unable to cast COM object of type 'Inventor._DocumentClass' to interface type 'Inventor.PartDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{29F0D463-C114-11D2-B77F-0060B0F159EF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
0 Likes
Message 4 of 18

bradeneuropeArthur
Mentor
Mentor

change this:

Dim a As PartDocument

into this:

Dim a As Document

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 5 of 18

GKPByDesign
Advocate
Advocate

Running the code makes a text box appear with 3 dimensions at the assembly layer in 'cm' with like 10 decimal places and trailing zeros. Not exactly what I needed. 

 

Task needs to be.

 

- Assembly level

- Apply an actual sketch to all parts

- Length value to be shown as 'Length' iProp and width as 'Width' iProp.

- Save and return to assembly

 

Can this be done at all? 

0 Likes
Message 6 of 18

bradeneuropeArthur
Mentor
Mentor

Hi,

 

 

Task needs to be.

 

- Assembly level (So loop through each part of the assembly)

- Apply an actual sketch to all parts (How should the sketch be orientated)

- Length value to be shown as 'Length' iProp and width as 'Width' iProp. (this is also possible with the method we have shared)

- Save and return to assembly

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 7 of 18

GKPByDesign
Advocate
Advocate

When I run the above code, and change it to work, no sketch is created, and a text box appears? it needs to be in mm, to only 1 decimal place and needs to be put into an iProp not a text box that appears. My coding knowledge is limited, and I understand that rotated parts are harder to do, but I am finding the code isn't working as originally intended.

 

 

0 Likes
Message 8 of 18

GKPByDesign
Advocate
Advocate

I have found this code on the forums, this works however, I want to automate the process further,

 

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
Dim oDef As PartComponentDefinition
oDef = oDoc.ComponentDefinition
L = Math.Abs(oDef.RangeBox.MaxPoint.X - oDef.RangeBox.MinPoint.X) * 10
W = Math.Abs(oDef.RangeBox.MaxPoint.Y - oDef.RangeBox.MinPoint.Y) * 10
H = Math.Abs(oDef.RangeBox.MaxPoint.Z - oDef.RangeBox.MinPoint.Z) * 10

MessageBox.Show(L, "Length")
MessageBox.Show(W, "Width")
MessageBox.Show(H, "Height")

- I do not need a message box to appear

- I would rather height be "Thickness"

- If possible I want to run this at an assembly level, loop the parts and return to the assembly

- units to be mm, and only to 1 decimal place within trailing zeros. 

 

can someone help please.

 

"Width"

"Length"

"Thickness"

0 Likes
Message 9 of 18

bradeneuropeArthur
Mentor
Mentor

possible.

 

tell me please:

  • how the I-properties need to be called and in what format (mm inches ul...) 
  • what precision
  • tekst or number

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 10 of 18

GKPByDesign
Advocate
Advocate

3 iprops

"Length"

"Width"

"Thickness"

 

Precision 0.1

 

Units mm

 

number not text (tekst)

 

 

0 Likes
Message 11 of 18

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Ilogic

VBA

Vb.net

 

Only the parts within the assembly?

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 12 of 18

GKPByDesign
Advocate
Advocate

Preferably iLogic, global rule, and yes on an open assembly 

0 Likes
Message 13 of 18

GKPByDesign
Advocate
Advocate

....Anybody able to help at all please

0 Likes
Message 14 of 18

bradeneuropeArthur
Mentor
Mentor

Why don't you use an "on save" or equal for all parts.

Then you have all dimensions set before you need it.

This is easier to program!

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 15 of 18

GKPByDesign
Advocate
Advocate

I do not know what you mean? 

0 Likes
Message 16 of 18

bradeneuropeArthur
Mentor
Mentor

Hi,

 

If you would fill in the L W and T property already with the part creation (on save;on close; etc), you don't need additional code because the properties are already filled in.

 

Your idea will take very long and needs to do some additional checks (Read-only etc) and this makes it complex.

 

You understand my idea now?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 17 of 18

GKPByDesign
Advocate
Advocate

Hey so my standard template has this, what I am exploring is a multi-body part creation, In which those values will not be there, in solid works and solid edge, it is able to pick up the overall size of a solid body, but inventor still doesn't have this feature. So that is why I'm asking for a bounding box.

 

I wonder if the process would be

 

- to draw a box 10mm by 10mm, 

- set one as Length

- set the other as Width

- Then make dimensions none driven (within brackets)

- constrain the points of each line to the edges using co-ordinates? (< this part I have no idea what to do)

0 Likes
Message 18 of 18

GKPByDesign
Advocate
Advocate

My template works great, but I am exploring using multi-bodies, and the make components tool. 

0 Likes