I'm trying to get a few properties to be placed into text boxes automatically in my drawings. Namely, Part name, Drawing Scale, the 'Description' iProperty, and a quantity from a BOM. I also want all of these properties to update when changes are made
So far I have this:
Sub Main() Dim ThisPartInfo As String For Each DrawingView In ThisApplication.ActiveDocument.ActiveSheet.DrawingViews ' Info to be placed under each view ThisPartInfo = DrawingView.ScaleString & " SCALE" & vbLf & "1 REQUIRED" 'Place the Info Block ThisApplication.ActiveDocument.ActiveSheet.DrawingNotes.GeneralNotes.AddFitted(ThisApplication.TransientGeometry.CreatePoint2d(DrawingView.position.x-DrawingView.width/2,DrawingView.position.y-DrawingView.height/2-1),ThisPartInfo) Next End Sub
The functionality I have so far is:
I run this rule manually, it automatically places a text box under each drawing view on the active sheet, the text box shows the correct scale of the drawing, and a default "1 REQUIRED" underneath the scale.
-I don't know how to update the scale in the text box automatically when the view scale is changed.
-I don't know how to get the part name or description from the model in the drawing view.
-I don't know how to get the qty from a BOM or else where.
-In general I don't how to get model properties from a drawing view.
can someone show me how to get these properties?
I'm not even sure if it possible from this approach
Solved! Go to Solution.
Solved by Yijiang.Cai. Go to Solution.
Please see how to get the model name and properties as below -
Sub Main() Dim ThisPartInfo As String For Each DrawingView In ThisApplication.ActiveDocument.ActiveSheet.DrawingViews Dim oDoc As Inventor.Document oDoc = ThisDrawing.ModelDocument Dim partName As String partName = oDoc.DisplayName ' Get the design tracking property set. Dim invDesignInfo As PropertySet invDesignInfo = oDoc.PropertySets.Item("Design Tracking Properties") ' Get the part number property. Dim DesProperty As Inventor.Property DesProperty = invDesignInfo.Item("Description") ' Info to be placed under each view ThisPartInfo = DrawingView.ScaleString & " SCALE" & vbLf & partName & " Name" & vbLf & DesProperty.Value & " Description" 'Place the Info Block ThisApplication.ActiveDocument.ActiveSheet.DrawingNotes.GeneralNotes.AddFitted(ThisApplication.TransientGeometry.CreatePoint2d(DrawingView.position.x-DrawingView.width/2,DrawingView.position.y-DrawingView.height/2-1),ThisPartInfo) Next
You could trigger the event to make rule running automatically. Please see the attached image.
For the partlist qty, you could refer the code sample below -
Public Sub PartListQuery() ' Set a reference to the drawing document. ' This assumes a drawing document is active. Dim oDrawDoc As DrawingDocument Set oDrawDoc = ThisApplication.ActiveDocument ' Set a reference to the first parts list on the active sheet. ' This assumes that a parts list is on the active sheet. Dim oPartList As PartsList Set oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1) ' Iterate through the contents of the parts list. Dim i As Long For i = 1 To oPartList.PartsListRows.Count ' Get the current row. Dim oRow As PartsListRow Set oRow = oPartList.PartsListRows.Item(i) ' Iterate through each column in the row. Dim j As Long For j = 1 To oPartList.PartsListColumns.Count ' Get the current cell. Dim oCell As PartsListCell Set oCell = oRow.Item(j) ' Display the value of the current cell. Debug.Print "Row: " & i & ", Column: " & oPartList.PartsListColumns.Item(j).Title & " = "; oCell.Value Next Next End Sub
This are the code to control each iProprietis
iProperties.Value("Project", "Part Number")for Part Number iProperties.Value("Project", "Description")for Description iProperties.Value("Project", "Revision Number")for Revision Number iProperties.Value("Summary", "Title")for Title iProperties.Value("Summary", "Subject")for Subject iProperties.Value("Project", "Stock Number")for Stock Number iProperties.Value("Project", "Project")for Project iProperties.Value("Project", "Engineer")for Engineer iProperties.Value("Custom", "StringNo")for StringNo
I'm actually having problems with this now that I started working on it again. The name
ThisDrawing.ModelDocument.DisplayName
Applies the first one retrieved to all other drawings in the sheet.
The scale still applies to each view properly.
I have refined the code sample to get the referenced document of every drawing view. Please see the code sample below. If it works for you, please accept it as solution. Thanks!
Sub Main() Dim ThisPartInfo As String Dim DrawingView As Inventor.DrawingView For Each DrawingView In ThisApplication.ActiveDocument.ActiveSheet.DrawingViews Dim oDoc As Inventor.Document oDoc=DrawingView.ReferencedDocumentDescriptor.ReferencedDocument Dim partName As String partName = oDoc.DisplayName ' Get the design tracking property set. Dim invDesignInfo As PropertySet invDesignInfo = oDoc.PropertySets.Item("Design Tracking Properties") ' Get the part number property. Dim DesProperty As Inventor.Property DesProperty = invDesignInfo.Item("Description") ' Info to be placed under each view ThisPartInfo = DrawingView.ScaleString & " SCALE" & vbLf & partName & " Name" & vbLf & DesProperty.Value & " Description" 'Place the Info Block ThisApplication.ActiveDocument.ActiveSheet.DrawingNotes.GeneralNotes.AddFitted(ThisApplication.TransientGeometry.CreatePoint2d(DrawingView.position.x-DrawingView.width/2,DrawingView.position.y-DrawingView.height/2-1),ThisPartInfo) Next End sub
Thank you! I couldn't even guess what the problem was.
I Assume this is the key
oDoc=DrawingView.ReferencedDocumentDescriptor.ReferencedDocument
and I also didn't understand that DrawingView was a user-defined variable.
Can't find what you're looking for? Ask the community or share your knowledge.