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: 

Get model properties into text box using iLogic

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
Anonymous
1658 Views, 7 Replies

Get model properties into text box using iLogic

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

7 REPLIES 7
Message 2 of 8
Yijiang.Cai
in reply to: Anonymous

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

 

Thanks,
River Cai

Inventor Quality Assurance Team
Autodesk, Inc.
Email: River-Yijiang.Cai@autodesk.com
Message 3 of 8
Yijiang.Cai
in reply to: Anonymous

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

 

Thanks,
River Cai

Inventor Quality Assurance Team
Autodesk, Inc.
Email: River-Yijiang.Cai@autodesk.com
Message 4 of 8
Cosmin_V
in reply to: Yijiang.Cai

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

 

Message 5 of 8
Anonymous
in reply to: Yijiang.Cai

Thank you! I can definitely get what I need from what your responses. 

Message 6 of 8
Anonymous
in reply to: Yijiang.Cai

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.

Message 7 of 8
Yijiang.Cai
in reply to: Anonymous

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
Thanks,
River Cai

Inventor Quality Assurance Team
Autodesk, Inc.
Email: River-Yijiang.Cai@autodesk.com
Message 8 of 8
Anonymous
in reply to: Yijiang.Cai

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.

Post to forums  

Autodesk Design & Make Report