Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Switching imported parameters to user defined parameters through iLogic

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
schefer.chris
700 Views, 3 Replies

Switching imported parameters to user defined parameters through iLogic

Hello Inventor Forum

 

 

I have linked parameters in multiple documents and would like to delete the link through an iLogic rule. The imported parameters are supposed to become user defined parameters without any external references, much like when using the manual "delete folder" command in the parameters window. I do not care for the exportparameter flag in the originating file, unless the solution necessitates changing it.

 

Is there an easy way to do this? I can't seem to find the right function. I'm running Inventor 2016 SP1.

3 REPLIES 3
Message 2 of 4
b_sharanraj
in reply to: schefer.chris

Hi @schefer.chris

 

Try the below Code 🙂

 

Option Explicit

Sub Main()

Dim Param As Parameter
Dim Param_Expression As String
Dim Param_Units As String
Dim Usr_Params As UserParameters
Dim Der_Param_Table As DerivedParameterTable
Dim i As Integer

i = 1

For Each Der_Param_Table In ThisApplication.ActiveDocument.ComponentDefinition.Parameters.DerivedParameterTables

For Each Param In ThisApplication.ActiveDocument.ComponentDefinition.Parameters.DerivedParameterTables.Item(i).DerivedParameters

Param_Expression = AlphaNumericOnly(Param.Expression)
MsgBox(Param_Expression)

Param_Units = Param.Units
Param = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters.AddByExpression("Temp_" & Param.Name, Param_Expression, Param_Units)

Next

i = i + 1

Next

For Each Der_Param_Table In ThisApplication.ActiveDocument.ComponentDefinition.Parameters.DerivedParameterTables

ThisApplication.ActiveDocument.ComponentDefinition.Parameters.DerivedParameterTables.Item(1).Delete

Next

For Each Param In ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters

If InStr(Param.Name, "Temp_") = 1 Then

Param.Name = Right(Param.Name, Len(Param.Name) - 5)

End If

Next

End Sub


Function AlphaNumericOnly(strSource As String) As String
    Dim i As Integer
    Dim strResult As String

    For i = 1 To Len(strSource)
        Select Case Asc(Mid(strSource, i, 1))
            Case 46, 48 To 57:
                strResult = strResult & Mid(strSource, i, 1)
        End Select
    Next
    AlphaNumericOnly = strResult
End Function

 

Regards

B.Sharan Raj

Message 3 of 4

Hi Chris,

if you only want to delete the derived tables try this:

 

Option Explicit

Sub Main()

Dim oPart As PartDocument
    oPart = ThisApplication.ActiveDocument

Dim oParams As Parameters
Dim oDevParam As DerivedParameter
'Get Parameter Tables
    oParams = oPart.ComponentDefinition.Parameters
	'check id there is a derived table
    If oParams.DerivedParameterTables.Count > 0 Then
	 
	 For Each oDevTable In oParams.DerivedParameterTables
'Kopie Parameters to User Parameters '! This not necessary if the derived parameters are used in the model parameters ' then they will be copied automatically For Each oDevParam in oDevTable.DerivedParameters 'Copy Method from B.Sharan Raj Next If oDevTable.HasReferenceComponent = False Then 'delete all linked tables oDevTable.Delete End If Next End If End Sub

When derived parameters are used in model parameters inventor copies them automatically into the user parameters when the derived table is deleted.

Otherwise they are lost.

If you want to copy all of the derived parameters to user parameters look at the code from B.Sharan Raj.

 

Message 4 of 4

Hi B.Sharan Raj, Hi Martin

 

I've tested both rules and they seem to do exactly what I need. In retrospect I see that my description was somewhat vague, since, I only need the parameters that are actually being used in the active document. Thus, in my current case, the second one is the one I'm going to be using. The first one however will surely come in handy at a later point in time.

 

Thank you very much!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report