- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm making code to transfer the key parameters from one file to another (via ilogic, not xml) and I can't find how to check if a parameter is a multi-value parameter and to copy it over to a new parameter if it is.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Check the ExpressionList Property of each parameter.
Non-list Parameters have ExpressionList.Count = 0
Sample:
For Each p As Parameter In ThisDoc.Document.ComponentDefinition.Parameters
If p.ExpressionList.Count > 0
Logger.Trace(p.Name & " List QTY: " & p.ExpressionList.Count)
End If
Next
Run rule in Log Level Trace to check sample code results.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @danny.lewisA9QBW .
See if this code does what you're trying to do:
Sub Main
'define source document
Dim oSourceDoc As Document = ThisApplication.ActiveDocument
'get its parameters
Dim oSParams As Inventor.Parameters = GetParams(oSourceDoc)
Dim oSParam As Inventor.Parameter
'define target document
Dim oTargetDoc As Document
Dim oTargetDocName As String = GetTargetDoc
If oTargetDocName = "" Then Exit Sub
oTargetDoc = ThisApplication.Documents.Open(GetTargetDoc, True)
'get its parameters
Dim oTParams As Inventor.Parameters = GetParams(oTargetDoc)
Dim oTParam As Inventor.Parameter
For Each oSParam In oSParams
If Not oSParam.IsKey Then Continue For
Try
oTParam = oTParams.Item(oSParam.Name)
Catch
If oSParam.ParameterType = ParameterTypeEnum.kModelParameter Then
oTParam = oTParams.ModelParameters.AddByExpression(oSParam.Expression, oSParam.Units, oSParam.Name)
If oSParam.ExpressionList IsNot Nothing AndAlso oSParam.ExpressionList.Count > 0 Then
Dim oExps() As String = oSParam.ExpressionList.GetExpressionList
oTParam.ExpressionList.SetExpressionList(oExps)
End If
ElseIf oSParam.ParameterType = ParameterTypeEnum.kUserParameter Then
oTParam = oTParams.UserParameters.AddByExpression(oSParam.Expression, oSParam.Units, oSParam.Name)
If oSParam.ExpressionList IsNot Nothing AndAlso oSParam.ExpressionList.Count > 0 Then
Dim oExps() As String = oSParam.ExpressionList.GetExpressionList
oTParam.ExpressionList.SetExpressionList(oExps)
End If
End If
Catch
MsgBox("Failed to copy source param named '" & oSParam.Name & "' to target document.",,"")
End Try
Next
End Sub
Public Function GetParams(oDoc As Document) As Inventor.Parameters
'check doc type
Dim oDocType As DocumentTypeEnum = oDoc.DocumentType
'get its Params
Dim oPrms As Inventor.Parameters
If oDocType = DocumentTypeEnum.kPartDocumentObject Or _
oDocType = DocumentTypeEnum.kAssemblyDocumentObject Then
oPrms = ThisApplication.ActiveDocument.ComponentDefinition.Parameters
ElseIf oDocType = DocumentTypeEnum.kDrawingDocumentObject Then
oPrms = ThisDrawing.Document.Parameters
End If
Return oPrms
End Function
Public Function GetTargetDoc() As String
'use Open File Dialog to get target document
Dim oFileName As String
Dim oDoc As Inventor.Document
Dim oFileDialog As Inventor.FileDialog
ThisApplication.CreateFileDialog(oFileDialog)
oFileDialog.DialogTitle = "Select 'Target' file."
oFileDialog.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
oFileDialog.Filter = "Autodesk Inventor Files (*.iam;*.dwg;*.idw;*.ipt:*.ipn;*.ide) | *.iam;*.dwg;*.idw;*ipt;*.ipn;*.ide | All files (*.*)|*.*"
oFileDialog.MultiSelectEnabled = False
oFileDialog.OptionsEnabled = False
oFileDialog.CancelError = True
oFileDialog.InsertMode = False
On Error Resume Next
oFileDialog.ShowOpen
If Err.Number <> 0 Then
MsgBox("Dialog was canceled. Exiting.", vbOKOnly, "CANCELED")
Return ""
Else
If oFileDialog.FileName <> vbNullString Then
oFileName = oFileDialog.FileName
Return oFileName
Else
MsgBox("No file was selected. Exiting.", vbOKOnly + vbExclamation, "FILE NOT SELECTED")
Return ""
End If
End If
End FunctionIf this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS)
.
If you have time, please... Vote For My IDEAS
or you can Explore My CONTRIBUTIONS
Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
that's most of what I need, but not sure how to have it copy over the multivalue list to the new parameter.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
If you are using iLogic below code will help you.
CopyParam is a parameter in which you will copy the multivalue list.
SourceParam is a parameter in which there is already a multivalue list.
MultiValue.List("CopyParam") = MultiValue.List("SourceParam") RuleParametersOutput InventorVb.DocumentUpdate
See if this helps.
Regards,
Dutt Thakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The code I posted already contained code to copy the multi-value list from the source parameter to the target parameter. That's what the following block of code, that appears twice within it, was for:
If oSParam.ExpressionList IsNot Nothing AndAlso oSParam.ExpressionList.Count > 0 Then
Dim oExps() As String = oSParam.ExpressionList.GetExpressionList
oTParam.ExpressionList.SetExpressionList(oExps)
End IfIt doesn't just copy a list of 'Values', it copies the list of 'Expressions', in case you want to maintain a list of possible equations or similar non-simple entries.
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
While I think your code chunk would work; here's a bigger picture of the relevant code so people have a better idea of what's going on:
Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim AssyDoc As AssemblyDocument = ThisApplication.Documents.Add(kAssemblyDocumentObject, "{source Assy filepath}", True)
Dim oUParams As UserParameters = oDoc.ComponentDefinition.Parameters.UserParameters
Dim iUParamCount As Integer = oUParams.Count
Dim Cycle As Integer
Dim uParamName As String
For Cycle = 1 To iUParamCount
uParamName = oUParams(Cycle).Name
If oUParams(Cycle).IsKey = True Then
If oUParams(Cycle).Units = "ul" Then
AssyDoc.ComponentDefinition.Parameters.UserParameters.AddByExpression(uParamName, oUParams(Cycle).Value, "ul").IsKey = True
' If oUParams(Cycle).ExpressionList.Count > 0 Then
' AssyDoc.ComponentDefinition.Parameters.UserParameters.AddByExpression(uParamName, MultiValue.List(uParamName), "ul").IsKey = True
' End If
Else If oUParams(Cycle).Units = "Text" Then
AssyDoc.ComponentDefinition.Parameters.UserParameters.AddByValue(uParamName, oUParams(Cycle).Value, kTextUnits).IsKey = True
Else
AssyDoc.ComponentDefinition.Parameters.UserParameters.AddByValue(uParamName, oUParams(Cycle).Value, kMillimeterLengthUnits).IsKey = True
End If
End If
Next
It's because I'm trying to transfer the parameters between the source (part) file to the destination (part or assy) file that I'm tripping up.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
OK. Maybe try it this way then.
Sub Main
'source document
Dim oSDoc As PartDocument = ThisApplication.ActiveDocument
Dim oSUParams As UserParameters = oSDoc.ComponentDefinition.Parameters.UserParameters
Dim oSUParam As UserParameter
'target document
Dim oTDoc As AssemblyDocument = ThisApplication.Documents.Add(kAssemblyDocumentObject, "{source Assy filepath}", True)
Dim oTUParams As UserParameters = oTDoc.ComponentDefinition.Parameters.UserParameters
Dim oTUParam As UserParameter
For Each oSUParam In oSUParams
If Not oSUParam.IsKey Then Continue For 'so it will only process Key params
If oSUParam.Units = "ul" Then
oTUParam = oTUParams.AddByExpression(oSUParam.Name, oSUParam.Value, "ul")
oTUParam.IsKey = True
CopyExpList(oSUParam,oTUParam)
ElseIf oSUParam.Units = "Text" Then
oTUParam = oTUParams.AddByValue(oSUParam.Name, oSUParam.Value, kTextUnits)
oTUParam.IsKey = True
CopyExpList(oSUParam,oTUParam)
Else
oTUParam = oTUParams.AddByValue(oSUParam.Name, oSUParam.Value, kMillimeterLengthUnits)
oTUParam.IsKey = True
CopyExpList(oSUParam,oTUParam)
End If
Next
End Sub
Public Sub CopyExpList(oSourceP As UserParameter, oTargetP As UserParameter)
If oSourceP.ExpressionList IsNot Nothing AndAlso oSourceP.ExpressionList.Count > 0 Then
oTargetP.ExpressionList.SetExpressionList(oSourceP.ExpressionList.GetExpressionList)
End If
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
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report