Rule for measurements

Rule for measurements

Anonymous
Not applicable
858 Views
6 Replies
Message 1 of 7

Rule for measurements

Anonymous
Not applicable

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

0 Likes
Accepted solutions (1)
859 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
Does anyone have a solution?
0 Likes
Message 3 of 7

rossano_praderi
Collaborator
Collaborator

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!
---------------
0 Likes
Message 4 of 7

Anonymous
Not applicable
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.
0 Likes
Message 5 of 7

Anonymous
Not applicable

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.

0 Likes
Message 6 of 7

rossano_praderi
Collaborator
Collaborator
Accepted solution

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
Not applicable
Sorry for the late response. Thank you very much Rossano, we've got it working :).
0 Likes