If you want to search the model items within a volume, the bounding box could help you. Bounding Box is the extents which aligns 3D Axis. It Identifies a cuboid-shaped bounded area in 3D space.
- ModelGeometry.BoundingBox: extents of a model item
- ModelItemCollection.BoundingBox: maximum extents of all items contained in the collection
The code below searches the model items whose bounding box are within the specific box and transforms them. The code is tested with <Navisworks Simulate/Manage>\ Samples\gatehouse\ gatehouse_pub.nwd. Its units is millimeters. The bounding box uses the units of the document Modal.Units. While the UI uses meter.
using Autodesk.Navisworks.Api;
using ComApiBridge = Autodesk.Navisworks.Api.ComApi;
using ComApi = Autodesk.Navisworks.Api.Interop.ComApi;
private void transObjWithBox()
{
// get current document
Document oDoc =
Autodesk.Navisworks.Api.Application.ActiveDocument;
//create the box (volume) you want to check
BoundingBox3D oNewBox = new BoundingBox3D(
new Point3D(-1000, -1000, 0),
new Point3D(1000, 1000, 1000));
// in the first model, check the items whose boxes are
// within the specified box.
IEnumerable<ModelItem> items =
oDoc.Models[0].RootItem.DescendantsAndSelf.
Where(x =>
oNewBox.Contains(x.BoundingBox())
);
// Select the items in the model that are
// contained in the collection
oDoc.CurrentSelection.CopyFrom(items);
// create a collection to store the items
ModelItemCollectionoModelColl =new ModelItemCollection();
oModelColl.CopyFrom(items);
//transform the objects. Currently this needs COM API
ComApi.InwOpState10oState =ComApiBridge.ComApiBridge.State;
ComApi.InwOpSelection oSel =
ComApiBridge.ComApiBridge.ToInwOpSelection(oModelColl);
// create transform matrix
ComApi.InwLTransform3f3 oTrans =
(ComApi.InwLTransform3f3)oState.ObjectFactory
(ComApi.nwEObjectType.eObjectType_nwLTransform3f,
null, null);
ComApi.InwLVec3f oVec =
(ComApi.InwLVec3f)oState.ObjectFactory
(ComApi.nwEObjectType.eObjectType_nwLVec3f,
null, null);
oVec.SetValue(5000, 5000, 0);
oTrans.MakeTranslation(oVec);
// transform
oState.OverrideTransform(oSel, oTrans);
}