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: 

Call part properties to drawing

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Gwennberg
302 Views, 6 Replies

Call part properties to drawing

Hi

I would like to show the part property "material" on my drawing with a script. But the script also need to check that there are only one part and no assembly shown on the drawing views. Is it possible?

BR/Goran

6 REPLIES 6
Message 2 of 7
WCrihfield
in reply to: Gwennberg

Hi @Gwennberg.  Sure sounds possible to me.  Do you want this note on the drawing to just contain the simple name of the parts material, or do you want that note to be 'linked' to the 'Material' iProperty in the model.  Anything else special about this note?  Is this just going to be a general note somewhere on the sheet, or is it going to be within a BorderDefinition Sketch, or within a TitleBlockDefinition sketch?  Any other text within the note, before or after the name of the material?  If there is an assembly found within the drawing, should it just do nothing then, or place some other note?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 7
Cadkunde.nl
in reply to: Gwennberg

You could do that with this code:

 

Class Event_BeforeSave_Drawing
	Shared oDoc As Document
	Shared modeldoc As Document
	Shared partdoc As PartDocument
	Sub Main()
		oDoc = ThisDoc.Document
		If Not oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
		modeldoc = ThisDrawing.ModelDocument

		If modeldoc Is Nothing Then Exit Sub
		If Not modeldoc.documenttype = DocumentTypeEnum.kPartDocumentObject Then Exit Sub
		If oDoc.ReferencedDocuments.Count > 1 Then Exit Sub
		partdoc = modeldoc
		
		'''Names can be found at: https://modthemachine.typepad.com/my_weblog/2010/02/accessing-iproperties.html
		UpdateProperty("Inventor User Defined Properties", "Material", partdoc.ActiveMaterial.DisplayName)
	End Sub

	Sub UpdateProperty(propset As String, propname As String, propvalue As String)
		Try
			oDoc.PropertySets.Item(propset).Item(propname).Value = propvalue
	   	Catch
			oDoc.PropertySets.Item(propset).Add(propvalue, propname)
		End Try
	End Sub
End Class

However, I prefer to add material in the title block (or sketched symbol), when you reference to an assembly it remains empty (except welded assemblies, but you could add a material for that named "-"

 

Message 4 of 7
WCrihfield
in reply to: Gwennberg

This is what I had in mind, if we were talking about a regular GeneralNote on the 'active' sheet (and not within a border or title block), and with the value being 'linked'.  Just one way among many.

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 oRefDocs As DocumentsEnumerator = oDDoc.ReferencedDocuments
If oRefDocs.Count = 0 Or oRefDocs.Count > 1 Then Exit Sub
Dim oRefDoc As Document = oRefDocs.Item(1)
If oRefDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then Exit Sub
Dim oPDoc As PartDocument = oRefDoc
Dim oPSet As PropertySet = oPDoc.PropertySets.Item(3)
Dim oProp As Inventor.Property = oPSet.Item("Material")
Dim oMaterial As String = oProp.Value
Dim oGNotes As GeneralNotes = oDDoc.ActiveSheet.DrawingNotes.GeneralNotes
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oP2d As Point2d = oTG.CreatePoint2d(3, 3)
Dim oFText As String = "<Property Document='model' PropertySet='" & oPSet.Name & "' Property='" & oProp.Name & "' FormatID='" & oPSet.InternalName & "' PropertyId='" & oProp.PropId & "' />"
Dim oNote As GeneralNote = oGNotes.AddFitted(oP2d, oFText)

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 5 of 7
Gwennberg
in reply to: Cadkunde.nl

Many thanks. I have the material property in the title block and with this script I got the material to the part shown in the drawing. Great!

I was trying to figure out how to make the "/" symbol appear when there was an assembly, "two or more parts" or exploded view but I can't figure out where to change the code. Wish I could learn iLogic..

Do you have any tips where I can start learning programming? Website, youtube, book.

//Goran

Message 6 of 7
WCrihfield
in reply to: Gwennberg

Here is a link to an article I put together to help out with this goal.

Learning about Inventor's iLogic 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 7
Cadkunde.nl
in reply to: Gwennberg

I took a course vb.net/ilogic of 4 days. Then just make small script within comfortzone or with 1 - 2 challanges raising the bar. keeping it fun and not frustrating. Slowly stepping up. And after a few years anything is possible.

At first, dont mind the googling and copy pasting and adjust it till you understand it

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report