Is there an easy way to export a list of user-defined parameter names?

Is there an easy way to export a list of user-defined parameter names?

chris
Advisor Advisor
413 Views
5 Replies
Message 1 of 6

Is there an easy way to export a list of user-defined parameter names?

chris
Advisor
Advisor

I'm looking for a way to export a list of all the user-defined parameter names. I need to be able to copy and paste them if possible

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

Michael.Navara
Advisor
Advisor
Accepted solution

Try this code.

 

 

Dim part As PartDocument = ThisDoc.Document
Dim userParams = part.ComponentDefinition.Parameters.UserParameters
Dim paramNames As New List(Of String)
For Each param As Parameter In userParams
    paramNames.Add(param.Name)
Next

Dim paramNamesAsLines As String = String.Join(vbCrLf, paramNames)
Logger.Debug("ParamNames{0}{1}", vbCrLf, paramNamesAsLines)

If MsgBox("Copy to clipboard?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
    System.Windows.Forms.Clipboard.SetText(paramNamesAsLines)
End If

 

Message 3 of 6

WCrihfield
Mentor
Mentor

Not sure if you are familiar with this process, or if it would work for you, but you could mark all your UserParameters as 'Key', then export them to an external XML file.  Then, you can import them into another document.  The process of marking all user parameters as Key is relatively simple to do by code, and there is actually a simple iLogic API line of code for the export or import step.

Dim oDoc As Document = ThisDoc.Document
Dim oUParams As UserParameters = Nothing
If (TypeOf oDoc Is AssemblyDocument) OrElse (TypeOf oDoc Is PartDocument) Then
	oUParams = oDoc.ComponentDefinition.Parameters.UserParameters
ElseIf (TypeOf oDoc Is DrawingDocument) Then
	oUParams = oDoc.Parameters.UserParameters
Else
	Return
End If
For Each oUParam As UserParameter In oUParams
	Try : oUParam.IsKey = True : Catch : End Try
Next oUParam
Dim sXMLFile As String = ThisDoc.PathAndFileName(False) & ".xml"
iLogicVb.Automation.ParametersXmlSave(oDoc, sXMLFile, XmlSaveOption.KeysOnly)
'iLogicVb.Automation.ParametersXmlLoad(oDoc, sXMLFile)

This assumes that you have not marked any of your ModelParameters or other parameter types as Key.  If you have, then you may need to include a little more code to temporarily set those to not being Key, then export, then set them back as Key.  The last line of code in the example above would be the one used for importing (loading) parameters into a document from an already existing XML file, just for reference, but would not really be used in the example above.

 

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 4 of 6

chris
Advisor
Advisor

I tried the XML export last night, but it's not just a list of names, it's everything, messy to deal with unless I was doing something wrong... which is possible

0 Likes
Message 5 of 6

chris
Advisor
Advisor

@Michael.Navara This worked great, exactly what I wanted/needed.!

0 Likes
Message 6 of 6

JBerns
Advisor
Advisor

Both great solutions from @Michael.Navara and @WCrihfield.

 

In Michael's solution, if you would like the parameter list sorted alphabetically, add this code at Line 7:

paramNames.Sort()

 

Hope others find this useful.

 

Regards,

Jerry 

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes