measure extents length for a subassembly from main assembly.

measure extents length for a subassembly from main assembly.

Amjed_Abdat
Observer Observer
720 Views
1 Reply
Message 1 of 2

measure extents length for a subassembly from main assembly.

Amjed_Abdat
Observer
Observer

we need to measure the extents dimensions of the subassemblies inside the main assembly, when i run the code it measures the extents dimensions of the main assembly only, it doesn't go inside the subassemblies.
so how to modify the below code to be able to reach the subassemblies level.
thanks.

 

 

Dim opendoc As Document
opendoc = ThisDoc.Document
Dim docfile As Document
		
For Each docfile In opendoc.AllReferencedDocuments
  If docfile.DocumentType = 12291 Then

		Dim x = Measure.ExtentsLength
		Dim y = Measure.ExtentsWidth
		Dim z = Measure.ExtentsHeight

	MessageBox.Show("Part Number/Name :" & docfile.DisplayName & vbLf & "length = " & x & vbLf & "Width = " & Measure.ExtentsWidth & vbLf & "Height = " & Measure.ExtentsHeight, "Title")
	

End If
Next

 

0 Likes
721 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor

Hi @Amjed_Abdat.  I'm sure there are multiple ways to do this, and multiple ways to assemble the retrieved data after the fact, but here is one way you can do it.  The problem with those iLogic only snippets you were using, is that I believe they just target the 'active' document, and you are wanting them to work on other referenced documents.  This code below uses the RangeBox of each top level referenced sub-assembly to get its size along the main 3 axes.  Beware though, the results will be in centimeters by default, so if you need the results in different units, you will need to include some math or some units conversion code.

Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oReport As String
For Each oRefDoc As Document In oADoc.ReferencedDocuments
	If oRefDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Continue For
	Dim oRefADoc As AssemblyDocument = oRefDoc
	oRefADef = oRefADoc.ComponentDefinition
	oMinP = oRefADef.RangeBox.MinPoint
	oMaxP = oRefADef.RangeBox.MaxPoint
	oXDiff = oMaxP.X - oMinP.X
	oYDiff = oMaxP.Y - oMinP.Y
	oZDiff = oMaxP.Z - oMinP.Z
	oName = System.IO.Path.GetFileNameWithoutExtension(oRefDoc.FullFileName)
	oSize = oXDiff & " Long x " & oYDiff & " Wide x " & oZDiff & " High"
	If Not String.IsNullOrEmpty(oReport) Then oReport = oReport & vbCrLf
	oReport = oReport & oName & " was " & oSize
Next
MsgBox(oReport,,"")

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)