Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
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: 

Ilogic code to pull user parameters from a part within assembly and populate drawing parameters

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Anthony5375F
408 Views, 4 Replies

Ilogic code to pull user parameters from a part within assembly and populate drawing parameters

Hi there

I currently have created user parameters within my drawing template that i need to populate using part parameters. 

Part level - has job information that sends data to and excel spreadsheet that i also need to populate my drawing user parameter.

Assembly- Has alternate parameters that populate my drawing. 

partdoc = ThisDrawing.ModelDocument(1)  '''THis needs to search all part files for the below
'Dim oAss As AssemblyDocument = ThisApplication.ActiveDocument

'Below code is to pull parameters from a document which is referenced in drawing document
PROJECT_NO = Parameter(partdoc.DisplayName, "PROJECT_NO") 
CLIENT1 = Parameter(partdoc.DisplayName, "CLIENT1") 
RACKING_MATERIAL = Parameter(partdoc.DisplayName, "RACKING_MATERIAL")
FRAME_MATERIAL = Parameter(partdoc.DisplayName, "FRAME_MATERIAL")
RACKING_FINISH = Parameter(partdoc.DisplayName, "RACKING_FINISH") 
FRAME_FINISH = Parameter(partdoc.DisplayName, "FRAME_FINISH") 
LOCATION = Parameter(partdoc.DisplayName, "LOCATION  ") 
COOLING = Parameter(partdoc.DisplayName, "COOLING ")
COOLING_TEMP = Parameter(partdoc.DisplayName, "COOLING_TEMP") 
PIPE_RUN = Parameter(partdoc.DisplayName, "PIPE_RUN ") 
CONDENSER = Parameter(partdoc.DisplayName, "CONDENSER")    
LIGHT_TEMP = Parameter(partdoc.DisplayName, "LIGHT_TEMP ")
CONTROLLER_LOCATION = Parameter(partdoc.DisplayName, "CONTROLLER_LOCATION") 

 

As i am trying to create a template drawing, i need the rule to search all parts files for the user parameters listed  rather than a specific part. 

There may be a much easier way to do this, but i am still learning everything 

Thanks

4 REPLIES 4
Message 2 of 5
WCrihfield
in reply to: Anthony5375F

Hi @Anthony5375F.  Just to clarify a couple things... This code will be in an 'internal' (saved within a document, not external) iLogic rule, right?  And this rule will be saved within the template drawing document, right?  And you expect that the 'model' of the drawing will always be an assembly, and not a part directly, right?  Then you want this code to loop through all parts (not any sub-assemblies) within that assembly, looking for one that contains this specific set of parameters, then copy those parameter values over to pre-existing user parameters with the same names within the drawing, right?  Will there only be one part that contains all of these parameters, or is it possible for there to be multiple parts with these parameters?  Is it possible that the part may have just some of those parameters, and not all of them?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 5
Anthony5375F
in reply to: WCrihfield

Hi @WCrihfield 

That is correct thank you! 

The parameters i am looking for will always be in one part. At present that is all i need to pull over

 

Thanks again

Anthony

Message 4 of 5
WCrihfield
in reply to: Anthony5375F

Hi @Anthony5375F.  This task is a bit more complex than it may seem at first, but I did write some iLogic code for it that you can try out.  I have not tested this, because I do not have a set of files all set-up as is needed to test it on, so proceed with caution.  Let me know how this works for you.

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 oADoc As AssemblyDocument = oDDoc.ReferencedDocuments.Item(1)
	Dim oParamNames As New List(Of String)	
	oParamNames.AddRange({"PROJECT_NO", "CLIENT1", "RACKING_MATERIAL", "FRAME_MATERIAL", _
	"RACKING_FINISH", "FRAME_FINISH", "LOCATION", "COOLING", "COOLING_TEMP", "PIPE_RUN", _
	"CONDENSER", "LIGHT_TEMP", "CONTROLLER_LOCATION" })
	Dim oSourcePart As PartDocument = Nothing
	For Each oRefDoc As Document In oADoc.AllReferencedDocuments
		If oRefDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then Continue For
		Dim oPDoc As PartDocument = oRefDoc
		Dim oParams As Inventor.Parameters = oPDoc.ComponentDefinition.Parameters
		Dim oAllFound As Boolean = False
		For Each oParamName In oParamNames
			Dim oFound As Boolean = False
			For Each oParam As Inventor.Parameter In oParams
				If oParam.Name = oParamName Then oFound = True
			Next 'oParam
			If Not oFound Then Exit For 'if any name not found, exit loop of names
			If oParamName = oParamNames.Last Then oAllFound = True
		Next 'oParamName
		If oAllFound Then oSourcePart = oPDoc : Exit For
	Next 'oRefDoc
	If IsNothing(oSourcePart) Then
		MsgBox("No part found will all specified parameters.", vbCritical, "")
		Exit Sub
	End If
	Dim oSourceParams As Inventor.Parameters = oSourcePart.ComponentDefinition.Parameters
	Dim oDestinationParams As UserParameters = oDDoc.Parameters.UserParameters
	For Each oParamName In oParamNames
		Try
			oDestinationParams.Item(oParamName).Value = oSourceParams.Item(oParamName).Value
		Catch
			MsgBox("Error copying param value from source to destination.", vbExclamation, "")
		End Try
	Next
	MsgBox("Done with attempt to copy parameter values to drawing.", vbInformation, "")
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 5 of 5
Anthony5375F
in reply to: WCrihfield

You are a wizard! It worked, thank you so much!

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

Post to forums  

Autodesk Design & Make Report