[CommandMethod("ACAClassCode", "ExModelerModifyBody", CommandFlags.Modal)]
public static void ModifyBody()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
// get a mass element to modify
PromptEntityOptions prEntOpts = new PromptEntityOptions("\nSelect duct fitting to modify");
prEntOpts.SetRejectMessage("\nSelected entity must be of type duct fitting");
//prEntOpts.AddAllowedClass(typeof(Autodesk.Aec.DatabaseServices.MassElement), false);
prEntOpts.AddAllowedClass(typeof(AecBldgHvacDbSvcs.DuctFitting), false);
PromptEntityResult prEntRes = ed.GetEntity(prEntOpts);
if (prEntRes.Status != PromptStatus.OK)
return;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
// add code from AModelerSample Init method
BlockTableRecord btrModelSpace =
(BlockTableRecord)SymbolUtilityServices.GetBlockModelSpaceId(db).GetObject(OpenMode.ForWrite);
Autodesk.Aec.DatabaseServices.MassElement me =
Autodesk.Aec.DatabaseServices.MassElement.Create(AecDbSvcs.ShapeType.BoundaryRepresentation);
// end added AModelerSample code
// open the duct fitting
//Autodesk.Aec.DatabaseServices.MassElement me =
//(Autodesk.Aec.DatabaseServices.MassElement)trans.GetObject(prEntRes.ObjectId, OpenMode.ForWrite);
AecBldgHvacDbSvcs.DuctFitting df =
(AecBldgHvacDbSvcs.DuctFitting)trans.GetObject(prEntRes.ObjectId, OpenMode.ForWrite);
// get the body from the duct fitting
Autodesk.Aec.Modeler.Body bBase = df.Body;
// add code from AModelerSample Init method
me.SetBody(bBase, false);
btrModelSpace.AppendEntity(me);
trans.AddNewlyCreatedDBObject(me, true);
// end added AModelerSample code
// setup a location to hold the new body
Autodesk.Aec.Modeler.Body bNew = null;
// create two new bodies
Autodesk.Aec.Modeler.Body b1 =
Autodesk.Aec.Modeler.Body.Cone(new LineSegment3d(new Point3d(0, 0, 0), new Point3d(0, 0, 5)), 2, 1.5, 10);
Autodesk.Aec.Modeler.Body b2 = Autodesk.Aec.Modeler.Body.Sphere(new Point3d(0, 0, 5), 0.5, 10);
// perform a boolean union via the plus operator... In this case we are unioining the two new bodys we created above
bNew = b1 + b2;
me.SetBody(bNew, false); // added
// now take the oginal body and subtract our new body
//bNew = bBase - bNew;
bNew = bBase + bNew;
me.SetBody(bNew, false); // added
// finally, since we are working on a copy, we need to assign the final body back to the mass element
//me.SetBody(bNew, true);
me.Body.Combine(bNew);
trans.Commit();
}
}
[CommandMethod("ACAClassCode", "ExModelerModifyBody", CommandFlags.Modal)]
public static void ModifyBody()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptEntityOptions prEntOpts = new PromptEntityOptions("\nSelect duct fitting to modify");
prEntOpts.SetRejectMessage("\nSelected entity must be of type duct fitting");
prEntOpts.AddAllowedClass(typeof(AecBldgHvacDbSvcs.DuctFitting), false);
PromptEntityResult prEntRes = ed.GetEntity(prEntOpts);
if (prEntRes.Status != PromptStatus.OK)
return;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
AecDbSvcs.MassElement me = AecDbSvcs.MassElement.Create(AecDbSvcs.ShapeType.BoundaryRepresentation);
Autodesk.Aec.Modeler.Body bNew = null;
Autodesk.Aec.Modeler.Body b1 = Autodesk.Aec.Modeler.Body.Cone(new LineSegment3d(new Point3d(0, 0, 8), new Point3d(0, 0, 13)), 2, 1.5, 10);
Autodesk.Aec.Modeler.Body b2 = Autodesk.Aec.Modeler.Body.Sphere(new Point3d(0, 0, 13), 0.5, 10);
Autodesk.Aec.Modeler.Body b3 = Autodesk.Aec.Modeler.Body.Cone(new LineSegment3d(new Point3d(0, 0, 0), new Point3d(0, 0, 8)), 2, 2, 10);
bNew = b1 + b2 + b3;
me.SetBody(bNew, true);
me.Body.Combine(bNew);
BlockTableRecord btrModelSpace = (BlockTableRecord)SymbolUtilityServices.GetBlockModelSpaceId(db).GetObject(OpenMode.ForWrite);
btrModelSpace.AppendEntity(me);
trans.AddNewlyCreatedDBObject(me, true);
AecBldgHvacDbSvcs.DuctFitting df = (AecBldgHvacDbSvcs.DuctFitting)trans.GetObject(prEntRes.ObjectId, OpenMode.ForRead);
if (df.AnchorId.IsNull)
{
ed.WriteMessage("\nAnchoring MassElement to DuctFitting.\n");
AecBldgDbSvcs.AnchorEntityToMember anchor = new AecBldgDbSvcs.AnchorEntityToMember();
anchor.SubSetDatabaseDefaults(db);
anchor.SetToStandard(db);
anchor.AnchorX.OffsetDistance = 15;
anchor.CurveId = df.ObjectId;
me.SetAnchor(anchor);
anchor.ForceUpdateToAnchorEntityToCurve = true;
}
trans.Commit();
}
}