Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
rossano_praderi
in reply to: Anonymous

Hi Stan,

the following function calculate all three dimensions of a component definition.

 

Sub Main()
	Dim StartTime As DateTime
	Dim aElapsedTime As TimeSpan
	StartTime = Now
	Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments
	aPropParNum = oAsmDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
	aFileNameWithoutExt = IO.Path.GetFileNameWithoutExtension(oAsmDoc.FullDocumentName)
	
	For Each oRefDoc In oRefDocs
		bPropParNum = oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
		bFileNameWithoutExt = IO.Path.GetFileNameWithoutExtension(oRefDoc.FullDocumentName)
		bFullpath = IO.Path.GetFullPath(oRefDoc.FullDocumentName)
		bFileName = IO.Path.GetFileName(oRefDoc.FullDocumentName)
		If oRefDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
			'If InStr(bFileNameWithoutExt, "koker", CompareMethod.Text) = 1 Then
			
			'ThisApplication.Documents.Open(bFullpath, True)
			'InventorVb.DocumentUpdate()
			aDocument = ThisApplication.ActiveDocument
			iProperties.Value(aDocument, "Custom", "aMeasure") = mSize(oRefDoc,"z")'Measure.ExtentsHeight
			iProperties.Value(aDocument, "Custom", "bMeasure") = mSize(oRefDoc,"y")'Measure.ExtentsWidth
			iProperties.Value(aDocument, "Custom", "cMeasure") = mSize(oRefDoc,"x")'Measure.ExtentsLength
			'If aDocument.Open Then aDocument.Close(True)
			
			'End If
		End If
	Next
	aElapsedTime = Now().Subtract(StartTime)
	bElapsedTime = aElapsedTime.TotalSeconds
'	oWrite = System.IO.File.CreateText("X:\01 productie\25 Werkvoorbereiding\07 Zaaglijsten\" & aFileNameWithoutExt & ".txt")
'	oWrite.WriteLine(aFileNameWithoutExt & vbCrLf & DateString & " " & Timestring)
'	oWrite.WriteLine("All data was collected in " & Round(bElapsedTime, 2) & "s" & vbCrLf & "")
'	oWrite.WriteLine("Tubes:" & vbCrLf & oListB)
'	oWrite.Close()
End Sub

Private Function mSize(oDoc As Inventor.Document, t As String) As String
	cD = oDoc.ComponentDefinition
	If cD IsNot Nothing Then
		Select Case UCase(t)
			Case "X" ' X is extent length
				X = Math.Abs(cD.RangeBox.MinPoint.X - cD.RangeBox.MaxPoint.X)
				mSize =  Round(oDoc.UnitsOfMeasure.ConvertUnits(X,"cm" ,oDoc.UnitsOfMeasure.LengthUnits )).ToString
			Case "Y" ' Y is extent width
				Y = Math.Abs(cD.RangeBox.MinPoint.Y - cD.RangeBox.MaxPoint.Y)
				mSize =  Round(oDoc.UnitsOfMeasure.ConvertUnits(Y,"cm" ,oDoc.UnitsOfMeasure.LengthUnits )).ToString
			Case "Z" ' Z is extent height
				Z = Math.Abs(cD.RangeBox.MinPoint.Z - cD.RangeBox.MaxPoint.Z)
				mSize =  Round(oDoc.UnitsOfMeasure.ConvertUnits(Z,"cm" ,oDoc.UnitsOfMeasure.LengthUnits )).ToString
		End Select
	End If
End Function

 

Why you should use this function instead of using the feature "Measure"?

 

I think it's more versatile because you need only to reference a document....no matter where is it.

 

 

Bregs

Rossano Praderi

 

 

NB: you have defined two variables that refer to the same document ("aAsm" & "aDocument"), every time you pass throught the loop "for/next" you assign everytime the same variable with the same document (I haven't check everything, but I only seen this as unnecessary).



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------