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
Solved! Go to Solution.
Solved by rossano_praderi. Go to Solution.
Hi Stan,
sorry for the late response....
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
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.
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).
Can't find what you're looking for? Ask the community or share your knowledge.