Size of parts in an assembly

Size of parts in an assembly

ngocson8335
Advocate Advocate
1,069 Views
3 Replies
Message 1 of 4

Size of parts in an assembly

ngocson8335
Advocate
Advocate

Dear Expert,

 

I want to code a bounding box for all part in the assembly but I don't want to Open part in Line: invApp.Documents.Open(oDocPartSub.FullFileName, True). I  tried to change to False but it wasn't working.

 

Here is my Code:

 

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

assemblyDoc = invApp.ActiveDocument

Dim oDocs As Inventor.DocumentsEnumerator
oDocs = assemblyDoc.ReferencedDocuments

For i As Integer = 1 To oDocs.Count

Dim oDocType As DocumentTypeEnum = oDocs.Item(i).DocumentType

If oDocType = DocumentTypeEnum.kAssemblyDocumentObject Then

Dim oSubDocs As Inventor.DocumentsEnumerator
oSubDocs = oDocs.Item(i).ReferencedDocuments

For ii As Integer = 1 To oSubDocs.Count

Dim oDocPartSub As Inventor.Document
oDocPartSub = oSubDocs.Item(ii)

invApp.Documents.Open(oDocPartSub.FullFileName, True)

partDoc = invApp.ActiveDocument

Dim oPartDef As Inventor.ComponentDefinition
oPartDef = partDoc.ComponentDefinition

Dim oBox As Inventor.Box = oPartDef.RangeBox

Dim dMax As Point = oBox.MaxPoint
Dim dMin As Point = oBox.MinPoint

Dim docPrec As Integer

Dim dX As Decimal = Math.Round((dMax.X - dMin.X) * 10, docPrec)
Dim dY As Decimal = Math.Round((dMax.Y - dMin.Y) * 10, docPrec)
Dim dZ As Decimal = Math.Round((dMax.Z - dMin.Z) * 10, docPrec)

Dim strThickness As Single
Dim strLength As Single
Dim strWidth As Single

Try

If dX = dY Then
strLength = dX
strWidth = dY
strThickness = dZ
End If

If dY = dZ Then
strLength = dX
strWidth = dZ
strThickness = dY

End If

If dX = dZ Then
strLength = dZ
strWidth = dY
strThickness = dX
End If

If dX > dY And dX > dZ Then
strLength = dX
If dY > dZ Then
strWidth = dY
strThickness = dZ
Else
strWidth = dZ
strThickness = dY
End If

End If
Catch ex As Exception

End Try

If dY > dX And dY > dZ Then
strLength = dY
If dX > dZ Then
strWidth = dX
strThickness = dZ
Else
strWidth = dZ
strThickness = dX
End If
End If

If dZ > dX And dZ > dY Then
strLength = dZ
If dX > dY Then
strWidth = dX
strThickness = dY
Else
strWidth = dY
strThickness = dX
End If
End If

MsgBox(strThickness & " x " & strWidth & " x " & strLength)
Next
End If
Next
End Sub

Ngoc Son
Autodesk User
0 Likes
Accepted solutions (1)
1,070 Views
3 Replies
Replies (3)
Message 2 of 4

JaneFan
Autodesk
Autodesk

Hey @ngocson8335 , 

 

ActiveDocument doesn't work for opened hidden document so that the error happens. Work around is that getting the  opened document by invApp.Documents.ItemByName (oDocPartSub.FullFileName) instead of ActiveDocument.




Jane Fan
Inventor/Fusion QA Engineer
0 Likes
Message 3 of 4

ngocson8335
Advocate
Advocate

Thanks @

 

 

Zalo_ScreenShot_27_2_2019_933271.png

Ngoc Son
Autodesk User
0 Likes
Message 4 of 4

ngocson8335
Advocate
Advocate
Accepted solution

Hello @

 

I fixed already!!! It's working well.

 

Many thanks. Have a great day!!! 🙂

Ngoc Son
Autodesk User