.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

error while editing two solids with BoolSubtract

2 REPLIES 2
Reply
Message 1 of 3
ACDC09
363 Views, 2 Replies

error while editing two solids with BoolSubtract

Hi All,

I have basically the same problem as this post:
http://discussion.autodesk.com/forums/thread.jspa?threadID=728378&tstart=30
I have tried the to downgrade open the solid but still no result.
my code
{code}
[CommandMethod("MyGroup", "MyCommand", "MyCommandLocal", CommandFlags.Modal)]
public void MyCommand() // This method can have any name
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Transaction tr = doc.TransactionManager.StartTransaction();

using (tr)
{
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForWrite);
BlockTableRecord ms = (BlockTableRecord)tr.GetObject( bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite );

Solid3d sol = new Solid3d();
Solid3d sol2 = new Solid3d();
sol.RecordHistory = true;

sol.CreateBox(10, 10, 10);
sol2.CreateBox(10, 10, 10);
sol.BooleanOperation(BooleanOperationType.BoolSubtract, sol2);
ms.AppendEntity(sol);
tr.AddNewlyCreatedDBObject(sol, true);

tr.Commit();
}

}
{code}

Thanks in advance
2 REPLIES 2
Message 2 of 3
chiefbraincloud
in reply to: ACDC09

I was curious about this, since I have code which does boolean operations and I have never had this problem. So I played around with it a bit, and the difference between your code and mine is the RecordHistory option. If you remove the RecordHistory line, your code works. If the record history is important to you (for my purposes it should be false), then I played around and figured out that you must add the solids to the ModelSpace before performing the boolean operation. So this:
{code}
Solid3d sol = new Solid3d();
Solid3d sol2 = new Solid3d();
sol.RecordHistory = true;

sol.CreateBox(20, 20, 8);
sol2.CreateBox(10, 10, 10);
sol.BooleanOperation(BooleanOperationType.BoolSubtract, sol2);
ms.AppendEntity(sol);
tr.AddNewlyCreatedDBObject(sol, true);

tr.Commit();
{code}
Becomes This:
{code}
Solid3d sol = new Solid3d();
Solid3d sol2 = new Solid3d();
sol.RecordHistory = true;

sol.CreateBox(20, 20, 8);
sol2.CreateBox(10, 10, 10);
ms.AppendEntity(sol);
ms.AppendEntity(sol2);
sol.BooleanOperation(BooleanOperationType.BoolSubtract, sol2);
tr.AddNewlyCreatedDBObject(sol, true);

tr.Commit();
{code}
Dave O.                                                                  Sig-Logos32.png
Message 3 of 3
ACDC09
in reply to: ACDC09

Thank you very much for your help, this solved my problem.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost