<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Rule for measurements in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-for-measurements/m-p/6505937#M66220</link>
    <description>&lt;P&gt;Hi Stan,&lt;/P&gt;&lt;P&gt;the following function calculate all three dimensions of a component definition.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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\" &amp;amp; aFileNameWithoutExt &amp;amp; ".txt")
'	oWrite.WriteLine(aFileNameWithoutExt &amp;amp; vbCrLf &amp;amp; DateString &amp;amp; " " &amp;amp; Timestring)
'	oWrite.WriteLine("All data was collected in " &amp;amp; Round(bElapsedTime, 2) &amp;amp; "s" &amp;amp; vbCrLf &amp;amp; "")
'	oWrite.WriteLine("Tubes:" &amp;amp; vbCrLf &amp;amp; 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&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why you should use this function instead of using the feature "Measure"?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think it's more versatile because you need only to reference a document....no matter where is it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bregs&lt;/P&gt;&lt;P&gt;Rossano Praderi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NB: you have defined two variables that refer to the same document ("aAsm" &amp;amp; "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).&lt;/P&gt;</description>
    <pubDate>Wed, 17 Aug 2016 16:36:50 GMT</pubDate>
    <dc:creator>rossano_praderi</dc:creator>
    <dc:date>2016-08-17T16:36:50Z</dc:date>
    <item>
      <title>Rule for measurements</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-for-measurements/m-p/6457222#M65645</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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\" &amp;amp; aFileNameWithoutExt &amp;amp; ".txt")
	oWrite.WriteLine(aFileNameWithoutExt &amp;amp; vbCrLf &amp;amp; DateString &amp;amp; " " &amp;amp; Timestring)
	oWrite.WriteLine("All data was collected in " &amp;amp; Round(bElapsedTime, 2) &amp;amp; "s" &amp;amp; vbCrLf &amp;amp; "")
	oWrite.WriteLine("Tubes:" &amp;amp; vbCrLf &amp;amp; oListB)
	oWrite.Close()
End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you, Stan Mertens&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jul 2016 10:05:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-for-measurements/m-p/6457222#M65645</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-07-25T10:05:05Z</dc:date>
    </item>
    <item>
      <title>Re: Rule for measurements</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-for-measurements/m-p/6459114#M65660</link>
      <description>Does anyone have a solution?</description>
      <pubDate>Tue, 26 Jul 2016 05:37:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-for-measurements/m-p/6459114#M65660</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-07-26T05:37:18Z</dc:date>
    </item>
    <item>
      <title>Re: Rule for measurements</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-for-measurements/m-p/6494708#M66048</link>
      <description>&lt;P&gt;Hi Stan,&lt;/P&gt;&lt;P&gt;sorry for the late response....&lt;img id="smileysad" class="emoticon emoticon-smileysad" src="https://forums.autodesk.com/i/smilies/16x16_smiley-sad.png" alt="Smiley Sad" title="Smiley Sad" /&gt;&lt;/P&gt;&lt;P&gt;If you use "aDocument" as reference you will give wrong informations to the application and then you get back&amp;nbsp;wrong results.&lt;/P&gt;&lt;P&gt;You should use "oRefDoc.DisplayName" instead.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;*********
	iProperties.Value(&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;oRefDoc.DisplayName&lt;/FONT&gt;&lt;/STRONG&gt;, "Custom", "aMeasure") = Measure.ExtentsHeight
	iProperties.Value(&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;oRefDoc.DisplayName&lt;/FONT&gt;&lt;/STRONG&gt;, "Custom", "bMeasure") = Measure.ExtentsWidth
	iProperties.Value(&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;oRefDoc.DisplayName&lt;/FONT&gt;&lt;/STRONG&gt;, "Custom", "cMeasure") = Measure.ExtentsLength
********&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bregs&lt;/P&gt;&lt;P&gt;Rossano Praderi&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2016 16:23:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-for-measurements/m-p/6494708#M66048</guid>
      <dc:creator>rossano_praderi</dc:creator>
      <dc:date>2016-08-11T16:23:29Z</dc:date>
    </item>
    <item>
      <title>Re: Rule for measurements</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-for-measurements/m-p/6496924#M66083</link>
      <description>Hi Rossano,&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;Stan.</description>
      <pubDate>Fri, 12 Aug 2016 14:57:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-for-measurements/m-p/6496924#M66083</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-08-12T14:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: Rule for measurements</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-for-measurements/m-p/6502283#M66125</link>
      <description>&lt;P&gt;Hi Rossano,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried your modifications in the following code:&lt;/P&gt;&lt;PRE&gt;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\" &amp;amp; aFileNameWithoutExt &amp;amp; ".txt")
'	oWrite.WriteLine(aFileNameWithoutExt &amp;amp; vbCrLf &amp;amp; DateString &amp;amp; " " &amp;amp; Timestring)
'	oWrite.WriteLine("All data was collected in " &amp;amp; Round(bElapsedTime, 2) &amp;amp; "s" &amp;amp; vbCrLf &amp;amp; "")
'	oWrite.WriteLine("Tubes:" &amp;amp; vbCrLf &amp;amp; oListB)
'	oWrite.Close()
End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Stan.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2016 07:02:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-for-measurements/m-p/6502283#M66125</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-08-16T07:02:44Z</dc:date>
    </item>
    <item>
      <title>Re: Rule for measurements</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-for-measurements/m-p/6505937#M66220</link>
      <description>&lt;P&gt;Hi Stan,&lt;/P&gt;&lt;P&gt;the following function calculate all three dimensions of a component definition.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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\" &amp;amp; aFileNameWithoutExt &amp;amp; ".txt")
'	oWrite.WriteLine(aFileNameWithoutExt &amp;amp; vbCrLf &amp;amp; DateString &amp;amp; " " &amp;amp; Timestring)
'	oWrite.WriteLine("All data was collected in " &amp;amp; Round(bElapsedTime, 2) &amp;amp; "s" &amp;amp; vbCrLf &amp;amp; "")
'	oWrite.WriteLine("Tubes:" &amp;amp; vbCrLf &amp;amp; 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&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why you should use this function instead of using the feature "Measure"?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think it's more versatile because you need only to reference a document....no matter where is it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bregs&lt;/P&gt;&lt;P&gt;Rossano Praderi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NB: you have defined two variables that refer to the same document ("aAsm" &amp;amp; "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).&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2016 16:36:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-for-measurements/m-p/6505937#M66220</guid>
      <dc:creator>rossano_praderi</dc:creator>
      <dc:date>2016-08-17T16:36:50Z</dc:date>
    </item>
    <item>
      <title>Re: Rule for measurements</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-for-measurements/m-p/6536670#M66539</link>
      <description>Sorry for the late response. Thank you very much Rossano, we've got it working :).</description>
      <pubDate>Thu, 01 Sep 2016 14:17:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-for-measurements/m-p/6536670#M66539</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-09-01T14:17:45Z</dc:date>
    </item>
  </channel>
</rss>

