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 Function
If 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)