DocumentCollection acDocMgr = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager;
int ct = 0;//cycle through quarters
int ct1 = 0;//cycle thorugh 16th
string file = cale + deTaiat + "\\" + deTaiat+"_"+quarter[0]+"_SOLID.dwg";
if (File.Exists(file))
{
Document almeu = acDocMgr.Open(file, false);
acDocMgr.MdiActiveDocument = almeu;
string drName = Path.GetFileName(almeu.Name);
}
else
{
acDocMgr.MdiActiveDocument.Editor.WriteMessage("File " + file+" does not exist.");
}
Document doc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
string drawingName = Path.GetFileName(doc.Name);
Editor ed = acDocMgr.MdiActiveDocument.Editor;
ed.WriteMessage(drawingName);
Database database = HostApplicationServices.WorkingDatabase;
using (Transaction transaction = database.TransactionManager.StartTransaction())
{
Point3d tileMin
= new Point3d
(grandOffset
.X+bigOffset
[ct
].X+smallOffset
[ct1
].X, grandOffset
.Y + bigOffset
[ct
].Y + smallOffset
[ct1
].Y,
0.0); Point3d tileMax
= new Point3d
(grandOffset
.X + bigOffset
[ct
].X + smallOffset
[ct1
].X+250.0, grandOffset
.Y + bigOffset
[ct
].Y + smallOffset
[ct1
].Y+250.0,
1000.0);
BlockTableRecord btRecord = (BlockTableRecord)transaction.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(database), OpenMode.ForWrite);
foreach (ObjectId id in btRecord)
{
Solid3d entity = (Solid3d)transaction.GetObject(id, OpenMode.ForWrite);
ObjectId intityId = entity.ObjectId;
Extents3d ext = entity.GeometricExtents;
////////// if entity intersects OS box, then create box and do boolean
if (((ext.MinPoint.X<tileMin.X)&& (ext.MaxPoint.X < tileMin.X))||
((ext.MinPoint.X > tileMax.X) && (ext.MaxPoint.X > tileMax.X)) ||
((ext.MinPoint.Y < tileMin.Y) && (ext.MaxPoint.Y < tileMin.Y)) ||
((ext.MinPoint.Y > tileMax.Y) && (ext.MaxPoint.Y > tileMax.Y)))//if outside
{
//delete entity
}
else if (!((ext.MinPoint.X>tileMin.X)&&(ext.MinPoint.Y>tileMin.Y)&&
(ext.MaxPoint.X < tileMax.X) && (ext.MaxPoint.Y < tileMax.Y)))//else if not completely inside
{
// start creating box
using (Transaction createBoxTrans = database.TransactionManager.StartTransaction())
{
Database db = HostApplicationServices.WorkingDatabase;
BlockTable acBlkTbl;
acBlkTbl = createBoxTrans.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
BlockTableRecord acBlkTblRec;
acBlkTblRec = createBoxTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
using (Solid3d myBox
= new Solid3d
()) {
myBox.CreateBox(250, 250, 800);
myBox
.TransformBy(Matrix3d
.Displacement(new Point3d
(100,
100,
0) - Point3d
.Origin)); acBlkTblRec.AppendEntity(myBox);
createBoxTrans.AddNewlyCreatedDBObject(myBox, true);
entity.BooleanOperation(BooleanOperationType.BoolIntersect, myBox);
}
createBoxTrans.Commit();
}
// end creating box
}
}
transaction.Commit();
}