In the past, we have to use COM interop to override the transformation of the objects by the method State.OverrideTransform. Here is a blog on how to transform the whole model. It is similar if you transform an object.
http://adndevblog.typepad.com/aec/2012/08/transform-nodes-of-a-loaded-model.html
2014 .NET API provides the direct ways.
- DocumentModels.OverridePermanentTransform (
IEnumerable<ModelItem> items,
Transform3D transform,
bool updateModelTransform)
this method applies an incremental transform to a selection with a transform matrix.
- DocumentModels.ResetAllPermanentTransforms()
this method reset incremental transforms for all model items contained in the entire model.
In addition, .NET API allows you to access the transformation information of the objects. While in the past, we cannot know the override value.
- ModelGeometry.OriginalTransform: Returns the original transform of the geometry when it was loaded.
- ModelGeometry.PermanentOverrideTransform: Transform applied to the original transform of the model geometry
- ModelGeometry.PermanentTransform : Permanent transform for the model geometry. The transform formed as a result of combining the original transform with the override transform
public override int Execute(params string[] parameters)
{
Document doc = Autodesk.Navisworks.Api.Application.MainDocument;
// current selection
ModelItemCollection coll = doc.CurrentSelection.SelectedItems;
if (coll.Count == 0)
return 0;
//build a vector for moving
Vector3D oNewVector3d = new Vector3D(1, 1, 0);
// optional way 1: orthogonal transforms + translation
//*********
//build an identity matrix which represents orthogonal transforms
Matrix3 oNewIndentityM = new Matrix3();
//create a transform from a matrix with a vector.
Transform3D oNewOverrideTrans = new Transform3D(oNewIndentityM, oNewVector3d);
//***********
// optional way 2: direct static function
//********
Transform3D oNewOverrideTrans1 = Transform3D.CreateTranslation(oNewVector3d);
//*********
//override the transformation of the selection
doc.Models.OverridePermanentTransform(coll, oNewOverrideTrans1, true);
return 0;
}