Print iProperty value from assembly onto drawing

Print iProperty value from assembly onto drawing

ober2558
Enthusiast Enthusiast
417 Views
5 Replies
Message 1 of 6

Print iProperty value from assembly onto drawing

ober2558
Enthusiast
Enthusiast

I am looking for a code that when run will automatically print a value from a custom iproperty of the assembly into the current drawing page. I am not very experienced with iLogic so any help you could provide would be greatly appreciated. 

0 Likes
Accepted solutions (1)
418 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Hi @ober2558.  This is just a rough draft, since I literally do not know anything about which property it is, or where to put it, or what assembly to get it from.  I just assumed you have a drawing open, and have a view of an assembly on that active sheet, and want the first custom iProperty from that assembly.  Then I just assumed placing a regular text note somewhere near the lower left corner of the sheet with that property's value would be OK.  Here is the code.

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing document must be active for this code to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument = ThisDoc.Document
	Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
	If oSheet.DrawingViews.Count = 0 Then
		MsgBox("There are no views on this sheet. Exiting Rule.", , "iLogic")
		Exit Sub
	End If
	Dim oView As DrawingView = oSheet.DrawingViews.Item(1)
	If oView.ReferencedDocumentDescriptor.ReferencedDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
		MsgBox("The first view on this sheet is not of an assembly.  Exiting Rule.", , "iLogic")
		Exit Sub
	End If
	Dim oADoc As AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
	Dim oCProps As Inventor.PropertySet = oADoc.PropertySets.Item(4) 'the 'Custom' property set
	If oCProps.Count = 0 Then
		MsgBox("There are no custom iProperties directly in the assembly.  Exiting Rule.", , "iLogic")
		Exit Sub
	End If
	Dim oCProp As Inventor.Property = oCProps.Item(1) '<<<Which One ?>>>
	Dim oGenNotes As Inventor.GeneralNotes = oSheet.DrawingNotes.GeneralNotes
	Dim oPosition As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(1, 1)
	Dim sFText As String = oCProp.Value.ToString
	Dim oGenNote As GeneralNote = oGenNotes.AddFitted(oPosition, sFText)
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 6

ober2558
Enthusiast
Enthusiast

The custom iProperty will be "Total Tool Weight". There will typically be only one assembly on the active drawing view at a time, is there a way to increase the text size as well?

0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor

OK.  Then this line:

Dim oCProp As Inventor.Property = oCProps.Item(1) '<<<Which One ?>>>

...can be changed to:

Dim oCProp As Inventor.Property = Nothing
Try 'tries to find it by its name
	oCProp = oCProps.Item("Total Tool Weight")
Catch 'it was not found, which would have caused an Error
	'you could try to create it here instead, if you have a default value you want to give it
	MsgBox("The custom iProperty named 'Total Tool Weight' could not be found.", , "iLogic")
	Exit Sub
End Try

 The text size is controlled by the currently active TextStyle by default.  We could have specified a TextStyle for it to use, as the third input into the last line of code, where it creates the GeneralNote, but we would first need to know which TextStyle, and we would have to retrieve that TextStyle to a variable first, before we could supply it to that method.  The other way of controlling text size is by including a bunch of pretty complicated XML tags within the 'FormattedText of that GeneralNote, instead of just supplying the value of the iProperty to it.  That can get a lot more complicated than you may have had in mind, because that extra code would be trying to compensate for all the extra stuff you see within the manual Format Text dialog.  If you already have an existing TextStyle in your drawing's Styles & Standards editor that is set to the size text you want, you would need to know its name, then retrieve it, then supply it within that last line...sort of like this:

Dim oTextStyle As Inventor.TextStyle = oDDoc.StylesManager.TextStyles.Item("LargerTextStyle")
Dim oGenNote As GeneralNote = oGenNotes.AddFitted(oPosition, sFText, oTextStyle)

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 6

ober2558
Enthusiast
Enthusiast

Is there a way to add "Total Tool Weight:" preceding the iproperty value when printed to the drawing document? 

0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor

Yes.  Replace (or edit) this line:

Dim sFText As String = oCProp.Value.ToString

... to be like this:

Dim sFText As String = "Total Tool Weight: " & oCProp.Value.ToString

Wesley Crihfield

EESignature

(Not an Autodesk Employee)