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
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,
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
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)
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.