Author Topic: boolean operation with newly created entity  (Read 243 times)

0 Members and 1 Guest are viewing this topic.

Adrian Baluta

  • Mosquito
  • Posts: 19
boolean operation with newly created entity
« on: April 12, 2019, 10:08:05 AM »
Hi

I'm trying to create a box and intersect it with an existing entity.

I don't know how to select the box as a solid3d, so that i can pas it to the boolean operation.

I tried Editor.SelecLast, but it doesn't return Solid3d.

Please help me!

Thank you!

Here's the code:
Code - C#: [Select]
  1. // start creating box
  2.                         using (Transaction createBoxTrans = database.TransactionManager.StartTransaction())
  3.                         {
  4.                             BlockTable acBlkTbl;
  5.                             acBlkTbl = createBoxTrans.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable;
  6.                             BlockTableRecord acBlkTblRec;
  7.                             acBlkTblRec = createBoxTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
  8.                             using (Solid3d myBox = new Solid3d())
  9.                             {
  10.                                 myBox.CreateBox(250, 250, 800);
  11.                                 myBox.TransformBy(Matrix3d.Displacement(new Point3d(100, 100, 0) - Point3d.Origin));
  12.                                 acBlkTblRec.AppendEntity(myBox);
  13.                                 createBoxTrans.AddNewlyCreatedDBObject(myBox, true);
  14.                             }
  15.                             createBoxTrans.Commit();
  16.                         }
  17.                         // end creating box
  18. entity.BooleanOperation(BooleanOperationType.BoolIntersect, ed.SelectLast);
  19.  

gile

  • Water Moccasin
  • Posts: 2218
  • Marseille, France
Re: boolean operation with newly created entity
« Reply #1 on: April 12, 2019, 10:27:53 AM »
Hi you do not show where 'entity' come from, but it would be opened in a transaction (opened with or add to this transaction). so, you should create the box using the same transaction so that you can simply do:
Code - C#: [Select]
  1. entity.BooleanOperation(BooleanOperationType.BoolIntersect, myBox);
Speaking English as a French Frog

Adrian Baluta

  • Mosquito
  • Posts: 19
Re: boolean operation with newly created entity
« Reply #2 on: April 12, 2019, 11:08:05 AM »
Thank you for the answer!
I didn't know if i can use the box before the creation transaction was closed.
I made the change as per your comment.
Now i can't create the box because i get a message saying 'eLockViolation' when i try to open the block table record for write.
I open an existing drawing and try to loop through all it's entities.

Thank you for the help!

Code - C#: [Select]
  1. DocumentCollection acDocMgr = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager;
  2.  
  3.             int ct = 0;//cycle through quarters
  4.             int ct1 = 0;//cycle thorugh 16th
  5.             string file = cale + deTaiat + "\\" + deTaiat+"_"+quarter[0]+"_SOLID.dwg";
  6.             if (File.Exists(file))
  7.             {
  8.                 Document almeu = acDocMgr.Open(file, false);
  9.                 acDocMgr.MdiActiveDocument = almeu;
  10.                 string drName = Path.GetFileName(almeu.Name);
  11.             }
  12.             else
  13.             {
  14.                 acDocMgr.MdiActiveDocument.Editor.WriteMessage("File " + file+" does not exist.");
  15.             }
  16.            
  17.             Document doc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
  18.             string drawingName = Path.GetFileName(doc.Name);
  19.             Editor ed = acDocMgr.MdiActiveDocument.Editor;
  20.             ed.WriteMessage(drawingName);
  21.             Database database = HostApplicationServices.WorkingDatabase;
  22.             using (Transaction transaction = database.TransactionManager.StartTransaction())
  23.             {
  24.                 Point3d tileMin = new Point3d(grandOffset.X+bigOffset[ct].X+smallOffset[ct1].X, grandOffset.Y + bigOffset[ct].Y + smallOffset[ct1].Y, 0.0);
  25.                 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);
  26.  
  27.                 BlockTableRecord btRecord = (BlockTableRecord)transaction.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(database), OpenMode.ForWrite);
  28.                 foreach (ObjectId id in btRecord)
  29.                 {
  30.  
  31.                     Solid3d entity = (Solid3d)transaction.GetObject(id, OpenMode.ForWrite);
  32.                     ObjectId intityId = entity.ObjectId;
  33.                     Extents3d ext = entity.GeometricExtents;
  34.  
  35.                     ////////// if entity intersects OS box, then create box and do boolean
  36.                     if (((ext.MinPoint.X<tileMin.X)&& (ext.MaxPoint.X < tileMin.X))||
  37.                         ((ext.MinPoint.X > tileMax.X) && (ext.MaxPoint.X > tileMax.X)) ||
  38.                         ((ext.MinPoint.Y < tileMin.Y) && (ext.MaxPoint.Y < tileMin.Y)) ||
  39.                         ((ext.MinPoint.Y > tileMax.Y) && (ext.MaxPoint.Y > tileMax.Y)))//if outside
  40.                     {
  41.                         //delete entity
  42.                     }
  43.                     else if (!((ext.MinPoint.X>tileMin.X)&&(ext.MinPoint.Y>tileMin.Y)&&
  44.                         (ext.MaxPoint.X < tileMax.X) && (ext.MaxPoint.Y < tileMax.Y)))//else if not completely inside
  45.                         {
  46.                         // start creating box
  47.                         using (Transaction createBoxTrans = database.TransactionManager.StartTransaction())
  48.                         {
  49.                             Database db = HostApplicationServices.WorkingDatabase;
  50.                             BlockTable acBlkTbl;
  51.                             acBlkTbl = createBoxTrans.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
  52.                             BlockTableRecord acBlkTblRec;
  53.                             acBlkTblRec = createBoxTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
  54.                             using (Solid3d myBox = new Solid3d())
  55.                             {
  56.                                 myBox.CreateBox(250, 250, 800);
  57.                                 myBox.TransformBy(Matrix3d.Displacement(new Point3d(100, 100, 0) - Point3d.Origin));
  58.                                 acBlkTblRec.AppendEntity(myBox);
  59.                                 createBoxTrans.AddNewlyCreatedDBObject(myBox, true);
  60.                                 entity.BooleanOperation(BooleanOperationType.BoolIntersect, myBox);
  61.                             }
  62.                             createBoxTrans.Commit();
  63.                         }
  64.                         // end creating box
  65.                     }
  66.                 }
  67.  
  68.                 transaction.Commit();
  69.             }
  70.  

gile

  • Water Moccasin
  • Posts: 2218
  • Marseille, France
Re: boolean operation with newly created entity
« Reply #3 on: April 12, 2019, 11:29:47 AM »
I replied you there.
Speaking English as a French Frog