Issue
I will call a series of functions/methods. Some of them will take effect at once on the model. So the speed becomes slow. I want to group these operations and just update the model once.
Solution
With COM, you can use state.BeginEdit, do all the calls, and then call state.EndEdit. Calling BeginEdit/EndEdit bundles up undo information. It also bundles up internal notifications. In certain circumstances, this can make things a lot faster as big parts of the NavisWorks internals/GUI will defer updating.
With .NET API, you can use the transaction.
using Autodesk.Navisworks.Api; using ComApi = Autodesk.Navisworks.Api.Interop.ComApi; using ComBridge = Autodesk.Navisworks.Api.ComApi.ComApiBridge;
// group operations in COM private void groupOpers_COM() { ComApi.InwOpState oState = ComBridge.State; //start group oState.BeginEdit("MyOpers"); // // a series operations // // end group oState.EndEdit(); }
// group operations in NET private void groupOpers_NET() { // start a Transaction Transaction oNWTrans = Autodesk.Navisworks.Api.Application. ActiveDocument.BeginTransaction("MyGroupOper"); try { // // a series operations // } catch (Exception ex) { MessageBox.Show("error! " + ex.ToString()); oNWTrans.Dispose(); } finally { oNWTrans = null; } }

Leave a Reply