Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Search for specific item and then change it's color

edufourGCYZK
Contributor

Search for specific item and then change it's color

edufourGCYZK
Contributor
Contributor

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

Screenshot 2023-06-19 155024.png

0 Likes
Reply
Accepted solutions (1)
592 Views
4 Replies
Replies (4)

jabowabo
Mentor
Mentor
Accepted 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);
}

 

 

 

alexisDVJML
Collaborator
Collaborator

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.

Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
0 Likes

edufourGCYZK
Contributor
Contributor

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

0 Likes

jabowabo
Mentor
Mentor

@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);