[CommandMethod("0DrawProjectionmanhole")]
public void DrawProjection()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Database db = HostApplicationServices.WorkingDatabase;
using ( Transaction tr = db.TransactionManager.StartTransaction() )
{
// A selection filter to select only block references
SelectionFilter filter = new SelectionFilter(new TypedValue[ 1 ]
{
new TypedValue(0, "INSERT")
});
PromptSelectionOptions opts = new PromptSelectionOptions();
opts.MessageForAdding = "Select block references:";
PromptSelectionResult res = ed.GetSelection(opts);
if ( res.Status != PromptStatus.OK )
{
return;
}
SelectionSet selSet = res.Value;
ObjectId[] ids = selSet.GetObjectIds();
foreach ( ObjectId blkId in ids )
{
if ( blkId != null )
{
// Open the Block reference for read (no need for type checking because as the selection filter did it)
BlockReference acBlkRef = (BlockReference) tr.GetObject(blkId, OpenMode.ForRead) as BlockReference;
// Open the Block table record of the selected reference for read
BlockTableRecord acBlkTblRec = (BlockTableRecord) tr.GetObject(acBlkRef.BlockTableRecord, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
// Step through the Block table record
// ed.WriteMessage("\n\n{0}", acBlkRef.Name);
foreach ( ObjectId asObjId in acBlkTblRec )
{
Entity ent = (Entity) tr.GetObject(asObjId, OpenMode.ForRead);
// ed.WriteMessage("\n{0}", e);
if (ent is Polyline)
{
Polyline pl = (Polyline)tr.GetObject(ent.ObjectId, OpenMode.ForRead);
if (Math.Round(pl.Area) == 205664)
{
Polyline clone = (Polyline)pl.Clone();
double shift = 1500;
Point3d resultPoint = new Point3d(pl.GetPoint3dAt(0).X, pl.GetPoint3dAt(0).Y - shift, 0);
Vector3d vector3d = pl.GetPoint3dAt(0).GetVectorTo(resultPoint);
Matrix3d displacement = Matrix3d.Displacement(vector3d);
clone.TransformBy(displacement);
btr.AppendEntity(clone);
tr.AddNewlyCreatedDBObject(clone, true);
}
}
}
}
}
tr.Commit();
}
}