Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RangeBox - Rotated Part

12 REPLIES 12
Reply
Message 1 of 13
FarrenYoung
3090 Views, 12 Replies

RangeBox - Rotated Part

I'm getting the rangebox of my assembly, but am having problems getting exactly what I need. Basically, if a part in my assembly is rotated, it's like it's getting the rangebox of the part's rangebox in its new orientation. I have included pictures to show what I am getting and what I would hope to get. In the last screenshot, I have drawn a red box to show what I would like to achieve. The black box being drawn from the rangebox was created from some code I downloaded (I think from this forum, but I couldn't find it via search, here is another link http://ww3.cad.de/foren/ubb/Forum258/HTML/001081.shtml)
Is there anyway to do what I am needing to do?

Thanks!
--Farren

************************************************************************************
If this post helps, please click the "thumbs up" to give kudos
If this post answers your question, please click "Accept as Solution"
************************************************************************************
12 REPLIES 12
Message 2 of 13
FarrenYoung
in reply to: FarrenYoung

Here is another screenshot of my problem.
The black box is what I'm getting.
The red box is what's causing the black box to be so large.
The green box is what I want.

Thanks again!
--Farren

************************************************************************************
If this post helps, please click the "thumbs up" to give kudos
If this post answers your question, please click "Accept as Solution"
************************************************************************************
Message 3 of 13
Anonymous
in reply to: FarrenYoung

Attached is a modified version of the range box sample that's delivered as
part of Inventor's online help. As you've found, the range box of the
occurrence is computed by fitting a box around the range box of the part.
This can result in a larger than necessary box. The only thing guaranteed
by the range box is that the occurrence is completely enclosed within the
box. In the attached sample I create a temporary part (using transient
B-Rep functionality) that's oriented based on the occurrence orientation and
get the range box from this part. Hopefully the sample makes sense.
--
Brian Ekins
Inventor API Product Designer
http://blogs.autodesk.com/modthemachine
Message 4 of 13
FarrenYoung
in reply to: FarrenYoung

Thanks Brian!

Very nice work, that was exactly what I hoped for.
--Farren

************************************************************************************
If this post helps, please click the "thumbs up" to give kudos
If this post answers your question, please click "Accept as Solution"
************************************************************************************
Message 5 of 13
Ralf_Krieg
in reply to: FarrenYoung

Hello

As author of the linked thread in german forum, I wasn't able to find a solution to the described problem until now. We worked around by placing the part temporarly in a new assembly. The first part is always placed in the assembly with fitting workplanes, so that the assembly rangebox can be used to get the wanted dimensions.

Your solution is a bit smarter and works fine for one selected part. Is creating BRep by copying an existing part a new function in Inventor 2011?

The real problem comes up, when there's more then one (rotated) part in the assembly and you want the dimensions of the assembly. There's no way to get around the "wided" rangebox.

R. Krieg
RKW Solutions GmbH
www.rkw-solutions.com
Message 6 of 13
cadfish1
in reply to: FarrenYoung

Just for fun I create some TextGraphics displayed at all the of the corners of the box (middle justified). My part and assembly are both in centimeters so there no conversion (rounding) issues. Also, the parts only sketch is constrained to 0,0 and the part is constrained to the origin workplanes in the assembly so the coordinate system of both the part file and the part wthin the assembly, are the same. Why isn't the TextGraphics.Text show 0 for those that lies along the X, Y & Z axis? See the attached graphic

{code}
Dim oTransientGeometry As TransientGeometry
Dim oPoint As Point

'Draws a bounding box of a part (occurrence) in the context of the assembly.
Public Sub DrawOccurrenceRangeBox()
Dim oAssemblyDocument As AssemblyDocument
Dim oComponentOccurrence As ComponentOccurrence
Dim oGraphicsDataSets As GraphicsDataSets
Dim oClientGraphics As ClientGraphics
Dim oSurfaceBody As SurfaceBody
Dim oBox As Box
Dim oGraphicsNode As GraphicsNode
Dim oLineGraphics As LineGraphics
Dim oGraphicsCoordinateSet As GraphicsCoordinateSet
Dim adBoxLines(1 To 12 * 6) As Double
Dim adMinPoint(1 To 3) As Double
Dim adMaxPoint(1 To 3) As Double

Dim oTextGraphics_Pnt1 As TextGraphics
Dim oTextGraphics_Pnt2 As TextGraphics
Dim oTextGraphics_Pnt3 As TextGraphics
Dim oTextGraphics_Pnt4 As TextGraphics
Dim oTextGraphics_Pnt5 As TextGraphics
Dim oTextGraphics_Pnt6 As TextGraphics
Dim oTextGraphics_Pnt7 As TextGraphics
Dim oTextGraphics_Pnt8 As TextGraphics
Dim oTextGraphics_xLen As TextGraphics
Dim oTextGraphics_yLen As TextGraphics
Dim oTextGraphics_zLen As TextGraphics
'create Transient Geometry for text anchor point
Set oTransientGeometry = ThisApplication.TransientGeometry

' Set a reference to the active assembly.
Set oAssemblyDocument = ThisApplication.ActiveDocument
' Make sure an occurrence is selected.
On Error Resume Next
Set oComponentOccurrence = oAssemblyDocument.SelectSet.Item(1)
If Err.Number <> 0 Then
MsgBox "You must select an occurrence to display the range box."
' Delete any graphics, if they exist.
On Error Resume Next
Set oGraphicsDataSets = oAssemblyDocument.GraphicsDataSetsCollection.Item("RangeBoxGraphics")
If Err.Number = 0 Then
On Error GoTo 0
Set oClientGraphics = oAssemblyDocument.ComponentDefinition. _
ClientGraphicsCollection.Item("RangeBoxGraphics")
oClientGraphics.Delete
oGraphicsDataSets.Delete
ThisApplication.ActiveView.Update
End If
Exit Sub
Else
' Check to make sure it 's a leaf level component.
If oComponentOccurrence.DefinitionDocumentType <> kPartDocumentObject Then
MsgBox "A leaf component (Part) must be selected."
Exit Sub
End If
End If

' Create a transient body of the selected part. Transform the body =to
' match the transform in the assembly.
Set oSurfaceBody = ThisApplication.TransientBRep.Copy(oComponentOccurrence.Definition.SurfaceBodies.Item(1))
Call ThisApplication.TransientBRep.Transform(oSurfaceBody, oComponentOccurrence.Transformation)
' Get the range box of the transformed body.
Set oBox = oSurfaceBody.RangeBox
' Check to see if range box graphics information already exists.
On Error Resume Next
Set oGraphicsDataSets = oAssemblyDocument.GraphicsDataSetsCollection.Item("RangeBoxGraphics")

If Err Then
Err.Clear
On Error GoTo 0
' Set a reference to the transient geometry object for user =later.
Set oTransientGeometry = ThisApplication.TransientGeometry
' Create a graphics data set object. This object contains all of =the
' information used to define the graphics.
Set oGraphicsDataSets = oAssemblyDocument.GraphicsDataSetsCollection.Add("RangeBoxGraphics")
' Create a coordinate set.
Set oGraphicsCoordinateSet = oGraphicsDataSets.CreateCoordinateSet(1)
' Create the client graphics for this compdef.
Set oClientGraphics = oAssemblyDocument.ComponentDefinition.ClientGraphicsCollection.Add( _
"RangeBoxGraphics")
' Create a graphics node.
Set oGraphicsNode = oClientGraphics.AddNode(1)
oGraphicsNode.Selectable = False
' Create line graphics.
Set oLineGraphics = oGraphicsNode.AddLineGraphics
oLineGraphics.CoordinateSet = oGraphicsCoordinateSet

'add Text Graphics to node
Set oTextGraphics_Pnt1 = oGraphicsNode.AddScalableTextGraphics
Set oTextGraphics_Pnt2 = oGraphicsNode.AddScalableTextGraphics
Set oTextGraphics_Pnt3 = oGraphicsNode.AddScalableTextGraphics
Set oTextGraphics_Pnt4 = oGraphicsNode.AddScalableTextGraphics
Set oTextGraphics_Pnt5 = oGraphicsNode.AddScalableTextGraphics
Set oTextGraphics_Pnt6 = oGraphicsNode.AddScalableTextGraphics
Set oTextGraphics_Pnt7 = oGraphicsNode.AddScalableTextGraphics
Set oTextGraphics_Pnt8 = oGraphicsNode.AddScalableTextGraphics

Set oTextGraphics_xLen = oGraphicsNode.AddScalableTextGraphics
Set oTextGraphics_yLen = oGraphicsNode.AddScalableTextGraphics
Set oTextGraphics_zLen = oGraphicsNode.AddScalableTextGraphics
Else
Set oGraphicsCoordinateSet = oGraphicsDataSets.ItemById(1)
Set oGraphicsNode = oAssemblyDocument.ComponentDefinition.ClientGraphicsCollection.Item( _
"RangeBoxGraphics").ItemById(1)
Set oTextGraphics_Pnt1 = oGraphicsNode.Item(2)
Set oTextGraphics_Pnt2 = oGraphicsNode.Item(3)
Set oTextGraphics_Pnt3 = oGraphicsNode.Item(4)
Set oTextGraphics_Pnt4 = oGraphicsNode.Item(5)
Set oTextGraphics_Pnt5 = oGraphicsNode.Item(6)
Set oTextGraphics_Pnt6 = oGraphicsNode.Item(7)
Set oTextGraphics_Pnt7 = oGraphicsNode.Item(8)
Set oTextGraphics_Pnt8 = oGraphicsNode.Item(9)

Set oTextGraphics_xLen = oGraphicsNode.Item(10)
Set oTextGraphics_yLen = oGraphicsNode.Item(11)
Set oTextGraphics_zLen = oGraphicsNode.Item(12)
End If

Call oBox.GetBoxData(adMinPoint, adMaxPoint)

' Line 1 -------------------------------------------------------------------
adBoxLines(1) = adMinPoint(1)
adBoxLines(2) = adMinPoint(2)
adBoxLines(3) = adMinPoint(3)
adBoxLines(4) = adMaxPoint(1)
adBoxLines(5) = adMinPoint(2)
adBoxLines(6) = adMinPoint(3)
'Debug.Print "Line 1: " & C(adMinPoint(1)) & "," & C(adMinPoint(2)) & "," & C(adMinPoint(3)) & " : " & C(adMaxPoint(1)) & "," & C(adMinPoint(2)) & "," & C(adMinPoint(3))
'Point 1
DrawingCoord_Pnt oTextGraphics_Pnt1, "1", adMinPoint(1), adMinPoint(2), adMinPoint(3)
'Point 2
DrawingCoord_Pnt oTextGraphics_Pnt2, "2", adMaxPoint(1), adMinPoint(2), adMinPoint(3)


' Line 2 ---------------------------------------------------------------------
adBoxLines(7) = adMinPoint(1)
adBoxLines(8) = adMinPoint(2)
adBoxLines(9) = adMinPoint(3)
adBoxLines(10) = adMinPoint(1)
adBoxLines(11) = adMaxPoint(2)
adBoxLines(12) = adMinPoint(3)
'Debug.Print "Line 2: " & C(adMaxPoint(1)) & "," & C(adMinPoint(2)) & "," & C(adMinPoint(3)) & " : " & C(adMinPoint(1)) & "," & C(adMaxPoint(2)) & "," & C(adMinPoint(3))

'Point 3
DrawingCoord_Pnt oTextGraphics_Pnt3, "3", adMinPoint(1), adMaxPoint(2), adMinPoint(3)

' Line 3 --------------------------------------------------------------------
adBoxLines(13) = adMinPoint(1)
adBoxLines(14) = adMinPoint(2)
adBoxLines(15) = adMinPoint(3)
adBoxLines(16) = adMinPoint(1)
adBoxLines(17) = adMinPoint(2)
adBoxLines(18) = adMaxPoint(3)
'Debug.Print "Line 3: " & C(adMinPoint(1)) & "," & C(adMinPoint(2)) & "," & C(adMinPoint(3)) & " : " & C(adMinPoint(1)) & "," & C(adMinPoint(2)) & "," & C(adMaxPoint(3))

'Point 4
DrawingCoord_Pnt oTextGraphics_Pnt4, "4", adMinPoint(1), adMinPoint(2), adMaxPoint(3)

' Line 4
adBoxLines(19) = adMaxPoint(1)
adBoxLines(20) = adMaxPoint(2)
adBoxLines(21) = adMaxPoint(3)
adBoxLines(22) = adMinPoint(1)
adBoxLines(23) = adMaxPoint(2)
adBoxLines(24) = adMaxPoint(3)
'Debug.Print "Line 4: " & C(adMaxPoint(1)) & "," & C(adMaxPoint(2)) & "," & C(adMaxPoint(3)) & " : " & C(adMinPoint(1)) & "," & C(adMaxPoint(2)) & "," & C(adMaxPoint(3))

'Point 5
DrawingCoord_Pnt oTextGraphics_Pnt5, "5", adMaxPoint(1), adMaxPoint(2), adMaxPoint(3)
'Point 6
DrawingCoord_Pnt oTextGraphics_Pnt6, "6", adMinPoint(1), adMaxPoint(2), adMaxPoint(3)

' Line 5
adBoxLines(25) = adMaxPoint(1)
adBoxLines(26) = adMaxPoint(2)
adBoxLines(27) = adMaxPoint(3)
adBoxLines(28) = adMaxPoint(1)
adBoxLines(29) = adMinPoint(2)
adBoxLines(30) = adMaxPoint(3)
'Debug.Print "Line 5: " & C(adMaxPoint(1)) & "," & C(adMaxPoint(2)) & "," & C(adMaxPoint(3)) & " : " & C(adMaxPoint(1)) & "," & C(adMinPoint(2)) & "," & C(adMaxPoint(3))

'Point 7
DrawingCoord_Pnt oTextGraphics_Pnt7, "7", adMaxPoint(1), adMinPoint(2), adMaxPoint(3)

' Line 6
adBoxLines(31) = adMaxPoint(1)
adBoxLines(32) = adMaxPoint(2)
adBoxLines(33) = adMaxPoint(3)
adBoxLines(34) = adMaxPoint(1)
adBoxLines(35) = adMaxPoint(2)
adBoxLines(36) = adMinPoint(3)
'Debug.Print "Line 6: " & C(adMaxPoint(1)) & "," & C(adMaxPoint(2)) & "," & C(adMaxPoint(3)) & " : " & C(adMaxPoint(1)) & "," & C(adMaxPoint(2)) & "," & C(adMinPoint(3))

'Point 8
DrawingCoord_Pnt oTextGraphics_Pnt8, "8", adMaxPoint(1), adMaxPoint(2), adMinPoint(3)

' Line 7
adBoxLines(37) = adMinPoint(1)
adBoxLines(38) = adMaxPoint(2)
adBoxLines(39) = adMinPoint(3)
adBoxLines(40) = adMaxPoint(1)
adBoxLines(41) = adMaxPoint(2)
adBoxLines(42) = adMinPoint(3)
'Debug.Print "Line 7: " & C(adMinPoint(1)) & "," & C(adMaxPoint(2)) & "," & C(adMinPoint(3)) & " : " & C(adMaxPoint(1)) & "," & C(adMaxPoint(2)) & "," & C(adMinPoint(3))

' Line 8
adBoxLines(43) = adMinPoint(1)
adBoxLines(44) = adMaxPoint(2)
adBoxLines(45) = adMinPoint(3)
adBoxLines(46) = adMinPoint(1)
adBoxLines(47) = adMaxPoint(2)
adBoxLines(48) = adMaxPoint(3)
'Debug.Print "Line 8: " & C(adMinPoint(1)) & "," & C(adMaxPoint(2)) & "," & C(adMinPoint(3)) & " : " & C(adMinPoint(1)) & "," & C(adMaxPoint(2)) & "," & C(adMaxPoint(3))

' Line 9
adBoxLines(49) = adMaxPoint(1)
adBoxLines(50) = adMinPoint(2)
adBoxLines(51) = adMaxPoint(3)
adBoxLines(52) = adMaxPoint(1)
adBoxLines(53) = adMinPoint(2)
adBoxLines(54) = adMinPoint(3)
'Debug.Print "Line 9: " & C(adMaxPoint(1)) & "," & C(adMinPoint(2)) & "," & C(adMaxPoint(3)) & " : " & C(adMaxPoint(1)) & "," & C(adMinPoint(2)) & "," & C(adMinPoint(3))

' Line 10
adBoxLines(55) = adMaxPoint(1)
adBoxLines(56) = adMinPoint(2)
adBoxLines(57) = adMaxPoint(3)
adBoxLines(58) = adMinPoint(1)
adBoxLines(59) = adMinPoint(2)
adBoxLines(60) = adMaxPoint(3)
'Debug.Print "Line 10: " & C(adMaxPoint(1)) & "," & C(adMinPoint(2)) & "," & C(adMaxPoint(3)) & " : " & C(adMinPoint(1)) & "," & C(adMinPoint(2)) & "," & C(adMaxPoint(3))

' Line 11
adBoxLines(61) = adMinPoint(1)
adBoxLines(62) = adMinPoint(2)
adBoxLines(63) = adMaxPoint(3)
adBoxLines(64) = adMinPoint(1)
adBoxLines(65) = adMaxPoint(2)
adBoxLines(66) = adMaxPoint(3)
'Debug.Print "Line 11: " & C(adMinPoint(1)) & "," & C(adMinPoint(2)) & "," & C(adMaxPoint(3)) & " : " & C(adMinPoint(1)) & "," & C(adMaxPoint(2)) & "," & C(adMaxPoint(3))

' Line 12
adBoxLines(67) = adMaxPoint(1)
adBoxLines(68) = adMinPoint(2)
adBoxLines(69) = adMinPoint(3)
adBoxLines(70) = adMaxPoint(1)
adBoxLines(71) = adMaxPoint(2)
adBoxLines(72) = adMinPoint(3)
'Debug.Print "Line 12: " & C(adMaxPoint(1)) & "," & C(adMinPoint(2)) & "," & C(adMinPoint(3)) & " : " & C(adMaxPoint(1)) & "," & C(adMaxPoint(2)) & "," & C(adMinPoint(3))

' Assign the points into the coordinate set.
Call oGraphicsCoordinateSet.PutCoordinates(adBoxLines)

' Update the display.
ThisApplication.ActiveView.Update
End Sub

Sub DrawingCoord_Pnt(oTextGraphics As TextGraphics, sPointNum As String, ByVal X As Double, ByVal Y As Double, ByVal Z As Double)
Debug.Print "P " & sPointNum & ": " & X & "," & Y & "," & X
oTextGraphics.Text = "P" & sPointNum & ": " & C(X) & "," & C(Y) & "," & C(Z)
oTextGraphics.SetTransformBehavior oTransientGeometry.CreatePoint(X, Y, Z), kFrontFacingAndPixelScaling
oTextGraphics.FontSize = 10
oTextGraphics.HorizontalAlignment = kAlignTextCenter
oTextGraphics.VerticalAlignment = kAlignTextMiddle
End Sub

Function C(dCoord As Double) As String
C = CStr(dCoord)
' Dim iP As Integer
' iP = InStr(C, ".")
' If iP <> 0 Then C = Mid(C, 1, iP + 3)
End Function
{code}
Message 7 of 13
Anonymous
in reply to: FarrenYoung

There's a long discussion that related to this here:
http://discussion.autodesk.com/forums/thread.jspa?messageID=5181844ᆔ
--
Brian Ekins
Inventor API Product Designer
http://blogs.autodesk.com/modthemachine
Message 8 of 13
Anonymous
in reply to: FarrenYoung

You're right that this doesn't handle an assembly. Although I think it can
be scaled up to handle assemblies by doing this procedure to get the range
box of each part and combining those boxes to get a range box that contains
all of the parts.

The functionality I used was new in Inventor 2010.
--
Brian Ekins
Inventor API Product Designer
http://blogs.autodesk.com/modthemachine
Message 9 of 13
cadfish1
in reply to: FarrenYoung

Thanks Brian. I will use your function when comparing two doubles however in this case I'm not comparing numbers. Do you have any suggestions on how I can convert the number I'm getting from Inventor (in this case should be 0 but I'm getting for instance -2.22044604925031E-16)? My guess is no but I have to ask.


Also, when I convert for instance -2.22044604925031E-16 to a string I get "-2.22044604925031E-16". How can I get "-0.000000000000000222044604925031" instead? Edited by: Cadfish1 on Mar 31, 2010 5:30 PM
Message 10 of 13
Anonymous
in reply to: FarrenYoung

You'll need to use a function that formats the value. For example, your
function "C" can be changed to:

Function C(dCoord As Double) As String
C = Format(dCoord, "0.00000")
End Function

The second argument controls the output format. In this case the resulting
number will show file number to the right of the decimal. Just add more
zeros for more numbers.

In VB.net you can use the Format property of the Double object:

Function C(ByVal dCoord As Double) As String
Return dCoord.ToString("0.00000")
End Function

--
Brian Ekins
Inventor API Product Designer
http://blogs.autodesk.com/modthemachine
Message 11 of 13
cadfish1
in reply to: FarrenYoung

Thank you Brian.
Message 12 of 13
cadfish1
in reply to: FarrenYoung

I haven't done exhaustive testing but this seems to work. This function uses Format to round the number off to (in this case) 14 places which seems to work for numbers that should a whole number but display something else (like -2.22044604925031E-16 which should be 0.0 and 0.99999999999999999999999 which should be 1.0). Because Format adds trailing zeros, a While loop is added to remove any. There of course could be situations where the number is actually within 14 places which rounds off to a whole number but shouldn't be rounded off. Use at your own risk.

{code}
Function C(ByVal dReal As Double) As String
'Out to 14 places seems to do the trick but not completely sure.
C = Format(dReal, "0.00000000000000")
'Next trim the trailing zero
While Right(C, 1) = "0"
C = Mid(C, 1, Len(C) - 1)
Wend
If Right(C, 1) = "." Then C = C & "0"
End Function
{code}
Message 13 of 13
martinxw
in reply to: FarrenYoung

Could you write here code, how you get the red box?

Because, I need red box 🙂

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report