Getting accurate RangeBox XYZ values

NachoShaw
Advisor Advisor
12,054 Views
55 Replies
Message 1 of 56

Getting accurate RangeBox XYZ values

NachoShaw
Advisor
Advisor

Hey

 

I'm using the RangeBox method to return the XYZ values of some parts. My problem with this is that if the part was angled, I do not get the correct XYZ but instead, I get XYZ of the angled part as if it was flat. Hard to explain but let's say for example the part was 10" x 10" x 1". that's the RB set of values but if the same part was angled at 45 degrees, I then get something like 10" x 10" x 5"...

 

is there a method of routine available that would allow me to obtain the true XYX even if the part wasnt laid flat or angled?

 

 

thanks

 

Nacho

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Accepted solutions (3)
12,055 Views
55 Replies
Replies (55)
Message 41 of 56

ganesh_omkaar
Contributor
Contributor
Nice code invention by Autodesk Inventor
It's perfectly work for scewed part. It's really help full for skeletal modeling method. it save lot of time
0 Likes
Message 42 of 56

floccipier
Advocate
Advocate
brilliant, thank you.
0 Likes
Message 43 of 56

artem.kolchyk
Participant
Participant

Hi, why i cannot use this code in my ilogic (AI professional 2019)

There is an error: 

The rule must contain: Sub Main() ... End Sub

0 Likes
Message 44 of 56

bradeneuropeArthur
Mentor
Mentor

can you upload your code here?

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 45 of 56

artem.kolchyk
Participant
Participant

 

Private Function GetPartSize(oDoc As Document, axis As String) As Double
    Dim i As Long
    Dim rangeBox As Box
    Dim pxMin As Double, pyMin As Double, pzMin As Double
    Dim pxMax As Double, pyMax As Double, pzMax As Double
    
    Dim PartSizeX As Double, PartSizeY As Double, PartSizeZ As Double
    
    Dim oCompDef As ComponentDefinition
    Set oCompDef = oDoc.ComponentDefinition
    
    Dim oBox As Box
    Set oBox = oCompDef.rangeBox
    
    With oBox
    pxMin = .MinPoint.x: pyMin = .MinPoint.y: pzMin = .MinPoint.z
    pxMax = .MaxPoint.x: pyMax = .MaxPoint.y: pzMax = .MaxPoint.z
    End With
    
    Dim oUOM As UnitsOfMeasure
    Set oUOM = oDoc.UnitsOfMeasure

    PartSizeX = oUOM.ConvertUnits((pxMax - pxMin), kCentimeterLengthUnits, oUOM.LengthUnits)
    PartSizeY = oUOM.ConvertUnits((pyMax - pyMin), kCentimeterLengthUnits, oUOM.LengthUnits)
    PartSizeZ = oUOM.ConvertUnits((pzMax - pzMin), kCentimeterLengthUnits, oUOM.LengthUnits)
  
    Select Case axis
        Case "X"
        GetPartSize = SizeSort(2)
        Case "Y"
        GetPartSize = SizeSort(1)
        Case "Z"
        GetPartSize = SizeSort(0)
    End Select
    
    'Set oDoc = Nothing

End Function

This.. 

0 Likes
Message 46 of 56

bradeneuropeArthur
Mentor
Mentor

and the call for "GetPartSize"?

 

 

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 47 of 56

artem.kolchyk
Participant
Participant

I dont know, i just copied this code into new ilogic rule and try to run it via ilogicc rule.

0 Likes
Message 48 of 56

bradeneuropeArthur
Mentor
Mentor

This is code for VBA not for i-logic.

 

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 49 of 56

bradeneuropeArthur
Mentor
Mentor

this will do:

Public Sub main
	GetPartSize(ThisDoc.Document)
	End Sub

Private Function GetPartSize(oDoc As Document) As Double
    'Dim i As Long
    Dim rangeBox As Box
    Dim pxMin As Double, pyMin As Double, pzMin As Double
    Dim pxMax As Double, pyMax As Double, pzMax As Double
    
    Dim PartSizeX As Double, PartSizeY As Double, PartSizeZ As Double
    
    Dim oCompDef As ComponentDefinition
    oCompDef = oDoc.ComponentDefinition
    
    Dim oBox As Box
    oBox = oCompDef.RangeBox
    
    With oBox
    pxMin = .MinPoint.X
	pyMin = .MinPoint.Y 
	pzMin = .MinPoint.Z
    pxMax = .MaxPoint.X
	pyMax = .MaxPoint.Y 
	pzMax = .MaxPoint.Z
    End With
    MsgBox ("")
    Dim oUOM As UnitsOfMeasure
    oUOM = oDoc.UnitsOfMeasure

    PartSizeX = oUOM.ConvertUnits((pxMax - pxMin),Inventor.unitstypeenum.kCentimeterLengthUnits, oUOM.LengthUnits)
    PartSizeY = oUOM.ConvertUnits((pyMax - pyMin), Inventor.unitstypeenum.kCentimeterLengthUnits, oUOM.LengthUnits)
    PartSizeZ = oUOM.ConvertUnits((pzMax - pzMin), Inventor.unitstypeenum.kCentimeterLengthUnits, oUOM.LengthUnits)
  
'    Select Case axis
'        Case "X"
'        GetPartSize =  SizeSort(2)
'        Case "Y"
'        GetPartSize = SizeSort(1)
'        Case "Z"
'        GetPartSize = SizeSort(0)
'    End Select
    MsgBox (PartSizeX.ToString & vbCrLf & PartSizeY.ToString & vbCrLf & PartSizeZ.ToString)
    'Set oDoc = Nothing

End Function

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 50 of 56

artem.kolchyk
Participant
Participant

Anyhow this code is not working...

25-6-2021 13-18-48.jpg

 

0 Likes
Message 51 of 56

Ralf_Krieg
Advisor
Advisor

Hello

 

Sorry, but:

- the code from @bradeneuropeArthur works fine.

- your error message is from VBA, not iLogic. The provided last code is for iLogic.

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 52 of 56

bradeneuropeArthur
Mentor
Mentor

you need it for VBA?

Public Sub main
	GetPartSize(ThisDoc.Document)
	End Sub

Private Function GetPartSize(oDoc As Document) As Double
    'Dim i As Long
    Dim rangeBox As Box
    Dim pxMin As Double, pyMin As Double, pzMin As Double
    Dim pxMax As Double, pyMax As Double, pzMax As Double
    
    Dim PartSizeX As Double, PartSizeY As Double, PartSizeZ As Double
    
    Dim oCompDef As ComponentDefinition
    Set oCompDef = oDoc.ComponentDefinition
    
    Dim oBox As Box
    Set oBox = oCompDef.RangeBox
    
    With oBox
    Set pxMin = .MinPoint.X
	Set pyMin = .MinPoint.Y 
	Set pzMin = .MinPoint.Z
    Set pxMax = .MaxPoint.X
	Set pyMax = .MaxPoint.Y 
	Set pzMax = .MaxPoint.Z
    End With
    MsgBox ("")
    Dim oUOM As UnitsOfMeasure
    Set oUOM = oDoc.UnitsOfMeasure

    Set PartSizeX = oUOM.ConvertUnits((pxMax - pxMin),Inventor.unitstypeenum.kCentimeterLengthUnits, oUOM.LengthUnits)
    Set PartSizeY = oUOM.ConvertUnits((pyMax - pyMin), Inventor.unitstypeenum.kCentimeterLengthUnits, oUOM.LengthUnits)
    Set PartSizeZ = oUOM.ConvertUnits((pzMax - pzMin), Inventor.unitstypeenum.kCentimeterLengthUnits, oUOM.LengthUnits)
  
'    Select Case axis
'        Case "X"
'        Set GetPartSize =  SizeSort(2)
'        Case "Y"
'        Set GetPartSize = SizeSort(1)
'        Case "Z"
'        Set GetPartSize = SizeSort(0)
'    End Select
    MsgBox (PartSizeX.ToString & vbCrLf & PartSizeY.ToString & vbCrLf & PartSizeZ.ToString)
    'Set oDoc = Nothing

End Function

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

Message 53 of 56

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@orswift.mi 

 

See example below, using the examples from this thread.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

' Get the active document. 
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef)
	oDoc = oOccurrence.Definition.Document

	' Get surface body to measure (assume it's the first body).
	Dim body1 As SurfaceBody = oDoc.ComponentDefinition.SurfaceBodies.Item(1)

	' Get the oriented mininum range box of the body.
	' NOTE: "OrientedMinimumRangeBox" was added in Inventor 2020.3/2021.
	Dim minBox As OrientedBox = body1.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 = oDoc.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)

	iProperties.Value(oOccurrence.Name, "Custom", "Length") = maxLength.ToString("#.###")
	iProperties.Value(oOccurrence.Name, "Custom", "Width") = midLength.ToString("#.###")
	iProperties.Value(oOccurrence.Name, "Custom", "Thickness") = minLength.ToString("#.###")

Next

 

Message 54 of 56

RiccardoSighinolfi
Contributor
Contributor

Hello

This iLogic script works perfectly for my needs but I can't understand how to insert the three dimensions thus obtained in as many iproperties instead of in a messagebox.

Could anyone help me?

Thank you!!

0 Likes
Message 55 of 56

ganesh_omkaar
Contributor
Contributor

Please add below code into your code 

 

I store my dimensions in iproperties  project tab, in Description field, you can change as per your requirement 

'Save into iProperties.Value("Project", "Description

 

 iProperties.Value("Project", "Description") = midLength.ToString("#.###")&"x"& minLength.ToString("#.###")&"x"& maxLength.ToString("#.###")

 

 

Message 56 of 56

phoenixwahoff
Contributor
Contributor

Hi Curtis,

 

I am kinda new to ilogic. But i have a question- is there a way with the rule you had created to add thickness width and length to the iproperties or parameters? This way i can write a template what will generate the BOM for our firm

We do cabinetry and use a ton of rectangular parts. So far what i have been doing is - create from each part the sheet metal and then it saves the parameters to the iproperties of the part - and in the assembly its then a proper BOM

the bummer is that i have to do this part by part - Is there a way to achive this with the rule u posted on an assembly level?

0 Likes