Bounding box with the UCS Origin

Bounding box with the UCS Origin

ngocson8335
Advocate Advocate
2,247 Views
16 Replies
Message 1 of 17

Bounding box with the UCS Origin

ngocson8335
Advocate
Advocate

Dear Expert,

 

My name is Son, I am a user in the Autodesk Inventor. I have an issue when I get the bounding box with the UCS origin. Please see the attached file for the 

 

Please help me in this case.

 

Have a nice day.

Ngoc Son

Ngoc Son
Autodesk User
0 Likes
Accepted solutions (1)
2,248 Views
16 Replies
Replies (16)
Message 2 of 17

bradeneuropeArthur
Mentor
Mentor

Hi,

 

This is not directly the solution but it will help to implement this is future maybe!

You could vote this...….

Dimension Component!

 

Regards,

Autodesk Software: Inventor Professional 2018 | Vault Professional 2018 | Autocad Mechanical 2018
Programming Skills: Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
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 !

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 17

JamieVJohnson2
Collaborator
Collaborator

If we can't find it, we create it. 

Here is some code that will create a range box using the vertices from the solid object, translated to user UCS, calculated for range box, then translated back to origin ucs.

 

            Dim partDoc As PartDocument = invApp.ActiveDocument
'get 3d solid Dim sb As SurfaceBody = partDoc.SelectSet(1) 'get custom user coordinate system
Dim ucs As UserCoordinateSystem = partDoc.ComponentDefinition.UserCoordinateSystems(1) 'create a list of points (for sorting)
Dim vPoints As New List(Of Point) 'get the transformation matrix from the usc (what it takes to translate from user ucs to origin)
Dim mat As Matrix = ucs.Transformation
'invert the matrix (what it takes to translate from origin to user ucs) mat.Invert()
'cycle through all the points For Each vert As Vertex In sb.Vertices
'get the point data from the vertex Dim p As Point = vert.Point
'invert translate the point data (from origin to user ucs) p.TransformBy(mat)
'add translated point to collection vPoints.Add(p) Next
'create empty min and max points Dim minPoint As Point = tg.CreatePoint(0, 0, 0) Dim maxPoint As Point = tg.CreatePoint(0, 0, 0)
'sort points based on x values, and get lowest and highest value vPoints.Sort(Function(x, y) x.X.CompareTo(y.X)) minPoint.X = vPoints.First.X maxPoint.X = vPoints.Last.X
'sort points based on y values, and get lowest and highest values vPoints.Sort(Function(x, y) x.Y.CompareTo(y.Y)) minPoint.Y = vPoints.First.Y maxPoint.Y = vPoints.Last.Y
'sort points based on z values, and get lowest and highest values vPoints.Sort(Function(x, y) x.Z.CompareTo(y.Z)) minPoint.Z = vPoints.First.Z maxPoint.Z = vPoints.Last.Z
'transform min and max points from user ucs back to origin minPoint.TransformBy(ucs.Transformation) maxPoint.TransformBy(ucs.Transformation)

Note, when I attempted to create a new rangebox (box) object, and assign these min and max points, it behaved oddly, by setting the min and max Z value both to '-0.5'.  This is not the expected behavior as the min/max points have '0.5' and '-0.5'.

 

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 4 of 17

ngocson8335
Advocate
Advocate

Hi JamieVJohnson2,

 

This is for iLogic, I can not run it.

 

Please

 

Ngoc Son
Autodesk User
0 Likes
Message 5 of 17

bradeneuropeArthur
Mentor
Mentor

what do you need:

VBA

Vb.net

????

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 6 of 17

ngocson8335
Advocate
Advocate

iLogic please

Ngoc Son
Autodesk User
0 Likes
Message 7 of 17

bradeneuropeArthur
Mentor
Mentor
 Dim partDoc As Inventor.PartDocument
 partDoc = ThisApplication.ActiveDocument
 
'get 3d solid
            Dim sb As SurfaceBody 
			sb = partDoc.SelectSet(1)
			MsgBox (sb.ComponentDefinition.SurfaceBodies.Count)
'get custom user coordinate system
            Dim ucs As UserCoordinateSystem 
			MsgBox (partDoc.ComponentDefinition.UserCoordinateSystems.Count)
			ucs = partDoc.ComponentDefinition.UserCoordinateSystems(1)

'create a list of points (for sorting)
            Dim vPoints As  New List(Of Point)

'get the transformation matrix from the usc (what it takes to translate from user ucs to origin)
            Dim mat As Matrix 
			mat = ucs.Transformation
'invert the matrix (what it takes to translate from origin to user ucs)
            mat.Invert()

'cycle through all the points
            For Each vert As Vertex In sb.Vertices
'get the point data from the vertex
                Dim p As Point 
				p = vert.Point
'invert translate the point data (from origin to user ucs)
                p.TransformBy(mat)
'add translated point to collection
                vPoints.Add(p)
            Next
			
			 ' Get the corners of the range box.
    		Dim tg As TransientGeometry
    		tg = ThisApplication.TransientGeometry
'create empty min and max points
            Dim minPoint As Point 
			minPoint =  tg.CreatePoint(0, 0, 0)
            Dim maxPoint As Point 
			maxPoint = tg.CreatePoint(0, 0, 0)
'sort points based on x values, and get lowest and highest value
            vPoints.Sort(Function(x, y) x.X.CompareTo(y.X))
            minPoint.X = vPoints.First.X
            maxPoint.X = vPoints.Last.X
'sort points based on y values, and get lowest and highest values
            vPoints.Sort(Function(x, y) x.Y.CompareTo(y.Y))
            minPoint.Y = vPoints.First.Y
            maxPoint.Y = vPoints.Last.Y
'sort points based on z values, and get lowest and highest values
            vPoints.Sort(Function(x, y) x.Z.CompareTo(y.Z))
            minPoint.Z = vPoints.First.Z
            maxPoint.Z = vPoints.Last.Z
'transform min and max points from user ucs back to origin
            minPoint.TransformBy(ucs.Transformation)
            maxPoint.TransformBy(ucs.Transformation)

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 8 of 17

ngocson8335
Advocate
Advocate

I can not run, some errors. Please, help me to fix.

Ngoc Son
Autodesk User
0 Likes
Message 9 of 17

bradeneuropeArthur
Mentor
Mentor

have you added an UCS?

have you selected the part SurfaceBody?

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 17

ngocson8335
Advocate
Advocate

It still has this problem

Ngoc Son
Autodesk User
0 Likes
Message 11 of 17

ngocson8335
Advocate
Advocate

I am using Inventor 2017

Ngoc Son
Autodesk User
0 Likes
Message 12 of 17

JamieVJohnson2
Collaborator
Collaborator
 Dim partDoc As Inventor.PartDocument
 partDoc = ThisApplication.ActiveDocument
 
'get 3d solid
            Dim sb As SurfaceBody 
			sb = partDoc.SelectSet(1)
			MsgBox (sb.ComponentDefinition.SurfaceBodies.Count)
'get custom user coordinate system
            Dim ucs As UserCoordinateSystem 
			MsgBox (partDoc.ComponentDefinition.UserCoordinateSystems.Count)
			ucs = partDoc.ComponentDefinition.UserCoordinateSystems(1)

'create a list of points (for sorting)
            Dim vPoints As  New List(Of Point)

'get the transformation matrix from the usc (what it takes to translate from user ucs to origin)
            Dim mat As Matrix 
			mat = ucs.Transformation
'invert the matrix (what it takes to translate from origin to user ucs)
            mat.Invert()

'cycle through all the points
            For Each vert As Vertex In sb.Vertices
'get the point data from the vertex
                Dim p As Point 
				p = vert.Point
'invert translate the point data (from origin to user ucs)
                p.TransformBy(mat)
'add translated point to collection
                vPoints.Add(p)
            Next
			
			 ' Get the corners of the range box.
    		Dim tg As TransientGeometry
    		tg = ThisApplication.TransientGeometry
'create empty min and max points
            Dim minPoint As Point 
			minPoint =  tg.CreatePoint(0, 0, 0)
            Dim maxPoint As Point 
			maxPoint = tg.CreatePoint(0, 0, 0)
'sort points based on x values, and get lowest and highest value
            vPoints.Sort(Function(x, y) x.X.CompareTo(y.X))
            minPoint.X = vPoints(0).X
            maxPoint.X = vPoints(vPoints.count-1).X
'sort points based on y values, and get lowest and highest values
            vPoints.Sort(Function(x, y) x.Y.CompareTo(y.Y))
            minPoint.Y = vPoints(0).Y
            maxPoint.Y = vPoints(vPoint.count-1).Y
'sort points based on z values, and get lowest and highest values
            vPoints.Sort(Function(x, y) x.Z.CompareTo(y.Z))
            minPoint.Z = vPoints(0).Z
            maxPoint.Z = vPoints(vPoint.count-1).Z
'transform min and max points from user ucs back to origin
            minPoint.TransformBy(ucs.Transformation)
            maxPoint.TransformBy(ucs.Transformation)

The API is not performing as expected (even the iLogic API can run VB.Net code directly, we are using 2019).  So I modified the .First and .Last statements to their equivalent (0) index value and (vPoints.count-1) index value.

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 13 of 17

ngocson8335
Advocate
Advocate

The next problem. So I'll try to fix it. Thank you for your help.

Ngoc Son
Autodesk User
0 Likes
Message 14 of 17

ngocson8335
Advocate
Advocate

Hi JamieVJohnson2,

 

I can not fix this error. Could you support me?

 

Thanks

 

Ngoc Son
Autodesk User
0 Likes
Message 15 of 17

ngocson8335
Advocate
Advocate

I tried to use Inventor 2019 but I can not get the size of a part with UCS1 (User UCS). Please view my attached file

 

Here is your code and my code:

 

SyntaxEditor Code Snippet

 Dim partDoc As Inventor.PartDocument
 partDoc = ThisApplication.ActiveDocument
 oDef = partDoc.ComponentDefinition
 
'get 3d solid
            Dim sb As SurfaceBody 
			sb = oDef.SurfaceBodies.Item(1)
			'MsgBox (sb.ComponentDefinition.SurfaceBodies.Count)
'get custom user coordinate system
            Dim ucs As UserCoordinateSystem 
			'MsgBox (partDoc.ComponentDefinition.UserCoordinateSystems.Count)
			ucs = partDoc.ComponentDefinition.UserCoordinateSystems(1)

'create a list of points (for sorting)
            Dim vPoints As  New List(Of Point)

'get the transformation matrix from the usc (what it takes to translate from user ucs to origin)
            Dim mat As Matrix 
			mat = ucs.Transformation
'invert the matrix (what it takes to translate from origin to user ucs)
            mat.Invert()

'cycle through all the points
            For Each vert As Vertex In sb.Vertices
'get the point data from the vertex
                Dim p As Point 
				p = vert.Point
'invert translate the point data (from origin to user ucs)
                p.TransformBy(mat)
'add translated point to collection
                vPoints.Add(p)
            Next
			
			 ' Get the corners of the range box.
    		Dim tg As TransientGeometry
    		tg = ThisApplication.TransientGeometry
'create empty min and max points
            Dim minPoint As Point 
			minPoint =  tg.CreatePoint(0, 0, 0)
            Dim maxPoint As Point 
			maxPoint = tg.CreatePoint(0, 0, 0)
'sort points based on x values, and get lowest and highest value
            vPoints.Sort(Function(x, y) x.X.CompareTo(y.X))
            minPoint.X = vPoints.First.X
            maxPoint.X = vPoints.Last.X
'sort points based on y values, and get lowest and highest values
            vPoints.Sort(Function(x, y) x.Y.CompareTo(y.Y))
            minPoint.Y = vPoints.First.Y
            maxPoint.Y = vPoints.Last.Y
'sort points based on z values, and get lowest and highest values
            vPoints.Sort(Function(x, y) x.Z.CompareTo(y.Z))
            minPoint.Z = vPoints.First.Z
            maxPoint.Z = vPoints.Last.Z
'transform min and max points from user ucs back to origin
            minPoint.TransformBy(ucs.Transformation)
            maxPoint.TransformBy(ucs.Transformation)
			
'			MessageBox.Show(minPoint.Z, "Title")
 
If partDoc.ComponentDefinition.SurfaceBodies.Count > 1 Then
        oPartDoc = Nothing
        Exit Sub
End If
 
Dim oBox As Box
 
Try
        oBox = partDoc.ComponentDefinition.SurfaceBodies.Item(1).RangeBox
Catch
        iProperties.Value("Custom", "BBox_X") = ""
        iProperties.Value("Custom", "BBox_Y") = ""
        iProperties.Value("Custom", "BBox_Z") = ""
        oPartDoc = Nothing
        Exit Sub
End Try
Dim Lenght As String
Dim Width As String
Dim Height As String

Lenght = FormatNumber(oBox.MaxPoint.X - oBox.MinPoint.X, 1) & " cm"
Width = FormatNumber(oBox.MaxPoint.Y - oBox.MinPoint.Y, 1) & " cm"
Height = FormatNumber(oBox.MaxPoint.Z - oBox.MinPoint.Z, 1) & " cm"
MessageBox.Show(Lenght & " x " & Width & " x " & Height, "Size of Part")


oPartDoc = Nothing

 

Ngoc Son
Autodesk User
0 Likes
Message 16 of 17

JamieVJohnson2
Collaborator
Collaborator

So you have the confusion of how to calculate the distance between two points, and which method to use.  Think of it like this:

1.  If you use the method your code shows, where you break down 2 points into their 3 components (x,y,z) and then calculated the total distance, you will definitely get a ORIGIN based bounding box.

2.  If you use a different method (point1.distanceto(point2)), you will get a direct calculation between two points. 

 

Since your two points are in 3D space, you want to get distances from 2 dimensions, you need to create points that eliminate the third dimension per 'work plane' of interest.  Example:

dim pXYMin as point = tg.createpoint(minPoint.x,minpoint,x,0) 'see we only drop the z value

dim pXYMax as point = tg.createpoint(maxPoint.x,maxpoint.y,0)

dim distXY as double = pxymin.distanceto(pxymax)

'repeat for yz, and xz where you drop the x value then the y value.

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 17 of 17

JamieVJohnson2
Collaborator
Collaborator
Accepted solution

Also since your box is rotated per ucs1 in 3d space, you have two options:

1.  Trigonometry (turn the diagonal flat plane line into a right triangle equation to get the length and with)

2.  You could attempt to get the values Before we transform them BACK to origin ucs.

In fact if getting bounding lengths is you goal, then the second option is probably the easiest for your situation.

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes