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: 

Sort User parameters by code

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
planglais75
2264 Views, 12 Replies

Sort User parameters by code

Hi all,

 

I work with Inventor 2011.

 

It is possible to sort Parameters (user parameters) by code (simulating a click on column header) ?

 

 

Thanks,

 

Pascal

12 REPLIES 12
Message 2 of 13
planglais75
in reply to: planglais75

If it's impossible by API, maybe I can change directly in the SQL database ?

Message 3 of 13

API doesn't support this sorting. 😞

Of course you are free to sort any list of parameters in your own interface (e.g., form with grid) or in the external data base.


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 4 of 13
planglais75
in reply to: planglais75

Ok, I've found a workaround.

 

1- Get list of user parameter has Key and show in interface

2- Reorder by user interaction

3- Deactivate iLogic

4- For each user parameter

  a) Add new user parameter, give temporary name

  b) Set properties of new parameter from old one

  c) For each dependent in Dependents

     i) In Expression property, replace old name parameter by temporary name

  d) Delete old parameter

  e) Rename new parameter by old parameter name

5- Activate iLogic

 

Here part of my code (sorry I program in C#):

 

// Get application instance
var app = CL.Framework.AutodeskInventor.Application.GetInstance(startIfClosed: false);
((dynamic)app.Preferences)(1).DeferUpdate = true;

// Deactivate iLogic
Inventor.ApplicationAddIn iLogic = app.ApplicationAddIns.ItemByName("iLogic");
iLogic.Deactivate();

// Validate if active document is part document
if (app.ActiveDocument is PartDocument)
{
    PartDocument doc = (PartDocument)app.ActiveDocument;

    // Get part user parameters
    Inventor.UserParameters userParams = doc.ComponentDefinition.Parameters.UserParameters;

    string tempParamName = "TemporaryParameterName";
    string oldParamName = string.Empty;

    // For each user parameter in ordered list
    ListOfKeyParams.OrderBy(p => p.Order).ForEach<UserParameterWrapper>(p =>
    {
        Inventor.UserParameter oldParam = p.UserParameter;

        // Get param name
        oldParamName = oldParam.Name;

        // Add new parameter
        string uom = oldParam.get_Units();
        Inventor.UserParameter newParam = null;
        if (oldParam.Expression != null && oldParam.ExpressionList == null)
            newParam = userParams.AddByExpression(tempParamName, oldParam.Expression, uom);
        else
            newParam = userParams.AddByValue(tempParamName, oldParam.Value, uom);

        // Copy properties from old parameters to new one
        newParam.Comment = oldParam.Comment;
        newParam.DisabledActionTypes = oldParam.DisabledActionTypes;
        newParam.DisplayFormat = oldParam.DisplayFormat;
        newParam.ExposedAsProperty = oldParam.ExposedAsProperty;
        newParam.ExpressionList.SetExpressionList(oldParam.ExpressionList.GetExpressionList());
        newParam.IsKey = oldParam.IsKey;
        newParam.ModelValueType = oldParam.ModelValueType;
        newParam.Precision = oldParam.Precision;
        newParam.Value = oldParam.Value;

        // Redirect dependencies on new parameter
        oldParam.Dependents.ForEach<Parameter>(i =>
        {
            i.Expression = i.Expression.Replace(oldParam.Name, tempParamName);
        });

        // Delete parameter
        oldParam.Delete();

        // Rename new parameter
        newParam.Name = oldParamName;

        // Activate iLogic
        iLogic.Activate();

        ((dynamic)app.Preferences)(1).DeferUpdate = false;
    });
}

 

Message 5 of 13
RStancescu
in reply to: planglais75

How can I use the above program in iLogic? I'm copying this in a rule and something is missing.

Thank you

radu

Message 6 of 13
planglais75
in reply to: RStancescu

HI Radu,

 

This is not iLogic code, this is a C# code using the API.

 

 

Regards, 

 

Pascal

Message 7 of 13
RStancescu
in reply to: planglais75

Yeah, I noticed that.

Thank you Pascal

Message 8 of 13
DonStauffer99
in reply to: RStancescu
Message 9 of 13

I am new to Inventors and have started using API and iLogic recently!

Thank You,

Pramod

Message 10 of 13

May I get the steps for, Where and how to use these codes in inventors.

Thankyou,

Pramod

Message 11 of 13

It's been a while since I wrote that, but I think you can paste it into an iLogic script and then call it, passing it the collection of strings containing the parameter names in the order you want them. It could alternatively be put into a DLL but that's more complicated. Please do note the comments at the top of the file. This works, but it requires you restart Inventor afterward because it leaves iLogic non-functional, unless a more recent Inventor release fixed that.

Message 12 of 13

This screenshot may help.

Message 13 of 13
RStancescu
in reply to: DonStauffer99

Thank you, I will look at it next week.

radu

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

Post to forums  

Autodesk Design & Make Report