Hello,
I am new to the Navisworks API and programming in C#. I would like to create a plugin that searches for a specific item and changes its color. However, I am struggling to locate a particular item. I'm not sure which method to use or what parameters to provide. Can someone please explain it to me?
The item I want to change in Navisworks is the piping, and the designer has assigned the same name to each pipe in the selection tree (I have attached a picture to clarify).
Thank you for your response !
Edward Dufour
Solved! Go to Solution.
Solved by jabowabo. Go to Solution.
To search for items by property:
https://adndevblog.typepad.com/aec/2012/05/navisworks-net-api-find-item.html
For color override:
public static void OverrideTempColor(ModelItem item, Color color)
{
Document doc = NavisApp.ActiveDocument;
doc.Models.OverrideTemporaryColor(new ModelItemCollection() { item }, color);
}
or:
public static void OverridePermColor(ModelItem item, Color color)
{
Document doc = NavisApp.ActiveDocument;
doc.Models.OverridePermanentColor(new ModelItemCollection() { item }, color);
}
Just to complement @jabowabo excellent reply.
"ACPPPIPE" you see in the tree and in category "Item", property "Type" is set by Autocad Plant3D for pipe parts.
To search for them, you need to do a Search with a SearchCondition for:
- category internal name: "LcOaNode"
- property internal name: "LcOaSceneBaseClassName"
- property display string equals to: "ACPPPIPE"
Should be as below:
new SearchCondition(new NamedConstant(@"LcOaNode"), new NamedConstant(@"LcOaSceneBaseClassName"), SearchConditionOptions.IgnoreCategoryDisplayName | SearchConditionOptions.IgnorePropertyDisplayName, SearchConditionComparison.Equal, VariantData.FromDisplayString(@"ACPPPIPE));
Note:I use internal names for category and property, instead of DisplayName, to avoid any issues with localized versions.
My goal is to create a plugin that allows me to search for an item and change its color. However, when I perform the search for the item, the search result is of type ModelItemCollection, whereas I need to have an item of type ModelItem in order to change its color. Do you have a solution?
@alexisDVJML are you suggesting this method because it is more efficient in finding the item that I am looking for?
Thank you for all your response
@edufourGCYZK wrote:
My goal is to create a plugin that allows me to search for an item and change its color. However, when I perform the search for the item, the search result is of type ModelItemCollection, whereas I need to have an item of type ModelItem in order to change its color.
The two methods I posted above use a single ModelItem as a parameter but the API methods OverrideTemporaryColor and OverridePermanentColor both use a ModelItemCollection as the first argument. You can use whichever makes sense in the context of your program.
Note that in the code blocks above, a new ModelItemCollection is created from the single item in order to use the API method:
doc.Models.OverridePermanentColor(new ModelItemCollection() { item }, color);
Can't find what you're looking for? Ask the community or share your knowledge.