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
Solved! Go to Solution.
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.
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; }); }
How can I use the above program in iLogic? I'm copying this in a rule and something is missing.
Thank you
radu
HI Radu,
This is not iLogic code, this is a C# code using the API.
Regards,
Pascal
I am new to Inventors and have started using API and iLogic recently!
Thank You,
Pramod
May I get the steps for, Where and how to use these codes in inventors.
Thankyou,
Pramod
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.
Can't find what you're looking for? Ask the community or share your knowledge.