Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
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: 

Rule for measurements

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Anonymous
677 Views, 6 Replies

Rule for measurements

Hello everyone,

 

I'm currently working on a rule and I have one slight problem. The problem is that this rule returns the measurements from the assembly, I want the measurements from the referenced documents.

 

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") = Measure.ExtentsHeight
	iProperties.Value(aDocument, "Custom", "bMeasure") = Measure.ExtentsWidth
	iProperties.Value(aDocument, "Custom", "cMeasure") = 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

 

 

Thank you, Stan Mertens

6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: Anonymous

Does anyone have a solution?
Message 3 of 7
rossano_praderi
in reply to: Anonymous

Hi Stan,

sorry for the late response....Smiley Sad

If you use "aDocument" as reference you will give wrong informations to the application and then you get back wrong results.

You should use "oRefDoc.DisplayName" instead.

 

*********
	iProperties.Value(oRefDoc.DisplayName, "Custom", "aMeasure") = Measure.ExtentsHeight
	iProperties.Value(oRefDoc.DisplayName, "Custom", "bMeasure") = Measure.ExtentsWidth
	iProperties.Value(oRefDoc.DisplayName, "Custom", "cMeasure") = Measure.ExtentsLength
********

 

Bregs

Rossano Praderi



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
Message 4 of 7
Anonymous
in reply to: rossano_praderi

Hi Rossano,

Thank you very much. I'm currently at vacation, coming monday i will be back at work. I will give you feedback as soon as i tried your code.

Stan.
Message 5 of 7
Anonymous
in reply to: rossano_praderi

Hi Rossano,

 

I've tried your modifications in the following code:

Sub Main()
	Dim StartTime As DateTime
	Dim aElapsedTime As TimeSpan
	StartTime = Now
	Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments
	aFileNameWithoutExt = IO.Path.GetFileNameWithoutExtension(oAsmDoc.FullDocumentName)
		For Each oRefDoc In oRefDocs
		bFileNameWithoutExt = IO.Path.GetFileNameWithoutExtension(oRefDoc.FullDocumentName)
			If oRefDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
				If InStr(bFileNameWithoutExt, "buis", CompareMethod.Text) = 1 Then
				iProperties.Value(oRefDoc.DisplayName, "Custom", "aMeasure") = Measure.ExtentsHeight
				iProperties.Value(oRefDoc.DisplayName, "Custom", "bMeasure") = Measure.ExtentsWidth
				iProperties.Value(oRefDoc.DisplayName, "Custom", "cMeasure") = Measure.ExtentsLength
				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

 

 

It does exactly the same as it did before (see screenshot). The rule returns the measurements from the assembly to the referenced documents, I want the measurements from referenced documents to be returned to the referenced documents themselves.

 

Stan.

Message 6 of 7
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!
---------------
Message 7 of 7
Anonymous
in reply to: rossano_praderi

Sorry for the late response. Thank you very much Rossano, we've got it working :).

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

Post to forums  

Autodesk Design & Make Report