Changing Linked Parameter Files with ilogic

Changing Linked Parameter Files with ilogic

Anonymous
Not applicable
2,828 Views
9 Replies
Message 1 of 10

Changing Linked Parameter Files with ilogic

Anonymous
Not applicable

I'm wanting to link one assembly's parameters to another, but with an option to change which one it is linked to. Normally i would just link the parameters directly, but when it comes to changing which assembly it is linked to, I can't find a way of changing it without linking it to a new file, then manually going through all the paramaters and sticking a "_1" on the end.

 

So i've thougth of another idea. I'm thinking to browse to the assembly i am wanting to liknk my parameters to, and if there is a user parameter that matches one in the active document, then set it to the linked assembly's parameter? Here is my attempt, but nothing seems to happen... I can't seem to get the parameters from the selected file. Can anyone advise where i've messed up, or if there is a better way of trying to acheive what i am trying to do.

 

SyntaxEditor Code Snippet

'present a File Selection dialog
Dim oFileDlg As inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.InitialDirectory = oOrigRefName
oFileDlg.CancelError = True
On Error Resume Next
oFileDlg.ShowOpen()
If Err.Number <> 0 Then
Return
ElseIf oFileDlg.FileName <> "" Then
selectedfile = oFileDlg.FileName
End If

On Error Resume Next
    oDoc = ThisApplication.Documents.ItemByName(selectedfile)
    If Err.Number <> 0 Then
        oDoc = ThisApplication.Documents.Open(selectedfile, False)
        _DocOpened = True
        MessageBox.Show("Must Select an Assembly File", "Error")

    End If
On Error Goto 0

Dim oOcc As AssemblyDocument = ThisDoc.Document
Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oUserParams As UserParameters = oCompDef.Parameters.UserParameters

For Each oParam In oUserParams

    'Parameter.Quiet = True
    
    Parameter(oOcc,oParam.Name) = Parameter(oDoc,oParam.Name)

Next

If _DocOpened = True
    oDoc.Close
End If

 

0 Likes
Accepted solutions (1)
2,829 Views
9 Replies
Replies (9)
Message 2 of 10

clutsa
Collaborator
Collaborator

Quick tip before I dig to deep, remove the "on error resume next" stuff from your code until you understand what errors you may be encountering. You say nothing is happening but my guess is errors are happening but the code just keeps plunging ahead and never tells you the error happened because you told it not to.

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 3 of 10

philip1009
Advisor
Advisor

The closest to it is using this line of code:

SyntaxEditor Code Snippet

ThisDoc.Document.ComponentDefinition.Parameters.ParameterTables.Item(1).FileName="C:\Users\Public\Documents\Book1.xlsx"

Unfortunately this only works with Excel spreadsheets, trying to link to another part or assembly file results in an error.  My usual workaround is to just have iLogic copy the parameter values all over the place, I typically avoid linking to Excel spreadsheets to minimize errors from software compatibility or linking.

 

I think the main issue is that there isn't even a function in the parameters window to replace the file reference in the first place, right clicking the file reference in the parameter window should provide an option to change the reference.  I'll find or make a post in Inventor Ideas to let Autodesk know this is a wanted feature.

0 Likes
Message 4 of 10

Anonymous
Not applicable

I've done that. I also used some message boxes to display what values i'm getting, and the problem is 

 

Parameter(oDoc,oParam.Name)

is giving the parameter values from oOcc not oDoc, so basically it's not making any changes.

 

0 Likes
Message 5 of 10

philip1009
Advisor
Advisor
0 Likes
Message 6 of 10

Anonymous
Not applicable

I agree with your earlier post; it should be a simple right-click to change the source file. I've voted, but could do with a solution now, without an excel file if possible.

 

is it not possible to do something like:

 

ThisDoc.Document.ComponentDefinition.Parameters = ThisApplication.Documents.ItemByName(selectedfile).ComponentDefinition.Parameters

 

0 Likes
Message 7 of 10

philip1009
Advisor
Advisor

I'm not sure what you mean by that, do you mean just copy or duplicate all parameters and/or their values from one file to another? there is a way to do that by just looping through all parameters in each file, but I can only see that generating all kind of errors unless you made either the code or the part parameters really specific to parameter names and types, you don't want to try to copy a length value with an angle value etc.  And that would only do a copy when that rule is run, you'll have to create the rule with the right Event Triggers to only run when you want it to so it doesn't overwrite your work or lock up Inventor to run the rule every time you do something.

 

I should've asked this at the beginning, what's your current goal that you're looking to achieve with iLogic?  Depending on what specific thing you're doing there could be other solutions.

0 Likes
Message 8 of 10

clutsa
Collaborator
Collaborator
Accepted solution

Looks like Parameter() only works on ReferencedDocuments so try accessing the parameter directly...

'present a File Selection dialog
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.InitialDirectory = oOrigRefName
oFileDlg.CancelError = True
On Error Resume Next
oFileDlg.ShowOpen()
If Err.Number <> 0 Then
Return
ElseIf oFileDlg.FileName <> "" Then
selectedfile = oFileDlg.FileName
End If

On Error Resume Next
    oDoc = ThisApplication.Documents.ItemByName(selectedfile)
    If Err.Number <> 0 Then
        oDoc = ThisApplication.Documents.Open(selectedfile, False)
        _DocOpened = True
        MessageBox.Show("Must Select an Assembly File", "Error")

    End If
On Error GoTo 0

Dim oOcc As AssemblyDocument = ThisDoc.Document
Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oUserParams As UserParameters = oCompDef.Parameters.UserParameters

For Each oParam In oUserParams

    'Parameter.Quiet = True
    
    Parameter(oOcc,oParam.Name) = oDoc.componentDefinition.Parameters.Item(oParam.Name).Value/2.54

Next

If _DocOpened = True
    oDoc.Close
End If

I had to divide by 2.54 to get from cm to inch but otherwise seems to work.

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 9 of 10

Anonymous
Not applicable

"I'm not sure what you mean by that, do you mean just copy or duplicate all parameters and/or their values from one file to another?"

yes this is what i want to do (apart from i'm just copying the user paramaters). I was planning on having the rule suppressed, and then running it from a form after you have selected the file you want to copy them across from.

  

Basically i'm wanting one assembly derived/linked to another assembly, with an easy way to be able to change the derived assembly.

0 Likes
Message 10 of 10

Anonymous
Not applicable

Thanks Clusta, that works a treat.

 

I had to do a bit of ****ing around with the units as some come through as cms. I couldn't just multiply everything by 10, because i have some text parameters, and some unitless ones etc.

 

0 Likes