Community
Navisworks API
Welcome to Autodesk’s Navisworks API Forums. Share your knowledge, ask questions, and explore popular Navisworks API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Search for specific item and then change it's color

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
edufourGCYZK
434 Views, 4 Replies

Search for specific item and then change it's color

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

Tags (1)
4 REPLIES 4
Message 2 of 5
jabowabo
in reply to: edufourGCYZK

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

 

 

 

Message 3 of 5
alexisDVJML
in reply to: edufourGCYZK

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
Message 4 of 5
edufourGCYZK
in reply to: edufourGCYZK

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

Message 5 of 5
jabowabo
in reply to: edufourGCYZK


@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.

Post to forums  

Rail Community


 

Autodesk Design & Make Report