public override DBObject DeepClone( DBObject dbObject, DBObject ownerObject, IdMapping idMap, bool isPrimary ) { // First we deep clone the object via the parent DBObject res = base.DeepClone(dbObject, ownerObject, idMap, isPrimary); // Then we check for our XData if (PipeDrawOverrule.PipeRadiusForObject(res) > 0.0) { // A transaction is needed by the set function to access // the RegApp table - we could also assume the app name // is registered and have a separate implementation // not taking the transaction... // Just as we might also have chosen to remove the XData Transaction tr = dbObject.Database.TransactionManager.StartTransaction(); using (tr) { PipeDrawOverrule.SetPipeRadiusOnObject(tr, res, 0.0); tr.Commit(); } } return(res); }
public void MakePipe() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; // Ask the user to select the entities to make into pipes PromptSelectionOptions pso = new PromptSelectionOptions(); pso.AllowDuplicates = false; pso.MessageForAdding = "\n选择对象变为管道: "; PromptSelectionResult selRes = doc.Editor.GetSelection(pso); // If the user didn't make valid selection, we return if (selRes.Status != PromptStatus.OK) { return; } SelectionSet ss = selRes.Value; // Ask the user for the pipe radius to set PromptDoubleOptions pdo = new PromptDoubleOptions( "\n指定管道半径:" ); // Use the previous value, if if already called if (_radius > 0.0) { pdo.DefaultValue = _radius; pdo.UseDefaultValue = true; } pdo.AllowNegative = false; pdo.AllowZero = false; PromptDoubleResult pdr = ed.GetDouble(pdo); // Return if something went wrong if (pdr.Status != PromptStatus.OK) { return; } // Set the "last radius" value for when // the command is called next _radius = pdr.Value; // Use a transaction to edit our various objects Transaction tr = db.TransactionManager.StartTransaction(); using (tr) { // Loop through the selected objects foreach (SelectedObject o in ss) { // We could choose only to add XData to the objects // we know will use it (Lines and Circles, for now) DBObject obj = tr.GetObject(o.ObjectId, OpenMode.ForWrite); PipeDrawOverrule.SetPipeRadiusOnObject(tr, obj, _radius); } tr.Commit(); } }