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: 

NavisWorks API .net Color Question

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
2850 Views, 4 Replies

NavisWorks API .net Color Question

Quick Easy Question. (Thou I can not find a answer in the docs & sample Code. I am probably not looking in the right area.)

 

How Do you reset the the Appearance for a SINGLE ModelItem? 

 

Also What is the Coordinate Units that you need to use to create a sectioning box thru the COM Layer???? (End user would like to enter in imperail or metric to size the box).

 

 

 

Colin

4 REPLIES 4
Message 2 of 5
saikat
in reply to: Anonymous

Hi Colin:

 

NavisWorks API colors are floating point in the range 0 to 1. Therefore such as RED=1,0,0. Grey in your case should be 0.5,0.5,0.5.

Following code shows how to override color for example -

private void applyColor_Click(object sender, EventArgs e)
{
//Get the ModelItemCollection to work on
ModelItemCollection newCollection = GetModelItemCollection();

//Create a Color representation
Autodesk.Navisworks.Api.Color newColor = new Autodesk.Navisworks.Api.Color(
Convert.ToDouble(color.ForeColor.R) / 255.0,
Convert.ToDouble(color.ForeColor.G) / 255.0,
Convert.ToDouble(color.ForeColor.B) / 255.0);

//Override the Color
Autodesk.Navisworks.Api.Application.ActiveDocument.Models.
OverridePermanentColor(newCollection, newColor);
}

 

 

Regarding the units, sectioning box should be using the same units as shown in the current Display Units

 

Hope this helps

Saikat



Saikat Bhattacharya
Senior Manager - Technology Consulting
Message 3 of 5
Anonymous
in reply to: saikat

Saikat,

 

  In regards to the coloring a single item that is what I assumed you have to generate a ModelItemCollection with 1 object then you are passing the collection back to the ActiveDocument.Models for appearance overriding. I was checking to see if there was an easier way like having a method exposed from the ModelItem object to override the appearance.

 

In regards to sectioning box I have been told that is not entirly true. If you could shed some light on it that would GREATLY be appreciated. 

 

Regards,

Colin Kemp

 

 

Message 4 of 5
Anonymous
in reply to: Anonymous

If you look at the properties you are wanting to modify (ModelItem.ModelGeometry.PermanentColor), you'll find that there is only a {get} and no {set}.  You have to use the InterOp to do the work for you.  Essentially, this is the error checking to make sure you set it right, amoung other checks I'm sure, ensuring that the object can have the type of override you wish to apply.

 

If based on user selection, then have the user select the item, and then grab the collection of ModelItems via (Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentSelection.SelectedItems) or (Autodesk.Navisworks.Api.Selection.GetSelectedItems(Autodesk.Navisworks.Api.ActiveDocument)

Message 5 of 5
xiaodong_liang
in reply to: Anonymous

The property PermanentColor is read-only because .NET API of Navisworks does not permit to modify the property directly. To modify it, we need to use the methods in DocumentPart. e.g. as my colleague Saikat demoed,

 

Autodesk.Navisworks.Api.Application.ActiveDocument.Models.
OverridePermanentColor(newCollection, newColor);

 

OverridePermanentColor is a method in the DocumentPart “DocumentModels”.

 

So, please note: both .NET and COM API can modify the permanent Color. You do not need to use Interop (COM) to modify color if you are developing in .NET.

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report