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

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

Anthony5375F
Contributor Contributor
549 Views
4 Replies
Message 1 of 5

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

Anthony5375F
Contributor
Contributor

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

0 Likes
Accepted solutions (1)
550 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

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)

0 Likes
Message 3 of 5

Anthony5375F
Contributor
Contributor

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

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

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)

0 Likes
Message 5 of 5

Anthony5375F
Contributor
Contributor

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

0 Likes