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

Problem while modifying Solid once created.....

2 REPLIES 2
Reply
Message 1 of 3
SamPersi
386 Views, 2 Replies

Problem while modifying Solid once created.....

Hello Everyone,


i have written function which is responsible for returning solid object (Box). Once box is created i have taken one more function which is responsible for returning 'Cylinder'.

Now i wanted to subtract Cylinder from Box. But i got error "Autodesk.AutoCAD.Runtime.Exception: eWasOpenForWrite".

So i used method UpgradeOpen for Box object, still not working.

Why? Is this error because i have returning from function...........

Thanks

{code}
private Solid3d drawSolidBox(double dblLengthAlongX, double dblLengthAlongY, double dblLengthAlongZ)
{
Solid3d solidBox;
try
{
solidBox = new Solid3d();
solidBox.RecordHistory = true;
solidBox.CreateBox(dblLengthAlongX, dblLengthAlongY, dblLengthAlongZ);
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
return null;
}
return solidBox;
}

private Solid3d drawCylinder()
{
Solid3d solidCylinder;
try
{
solidCylinder = new Solid3d();
solidCylinder.RecordHistory = true;
solidCylinder.CreateFrustum(40, 5, 5, 5);
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
return null;
}
return solidCylinder;

}


void MainFunction()
{
Solid3d solidBox = new Solid3d();
solidBox.RecordHistory = true;
solidBox = drawSolidBox(this.dblLength, this.dblWidth, this.dblHeight);

Solid3d solidCylinder = new Solid3d();
solidCylinder = drawCylinder();

solidBox.BooleanOperation(BooleanOperationType.BoolSubtract, solidCylinder);

blockTableRecord.AppendEntity(solidCylinder);
tran.AddNewlyCreatedDBObject(solidCylinder, true);
blockTableRecord.AppendEntity(solidBox);
tran.AddNewlyCreatedDBObject(solidBox, true);
}

{code}
2 REPLIES 2
Message 2 of 3
chiefbraincloud
in reply to: SamPersi

I have some questions about your code, which can't be complete as posted, but the exception indicates something should Not be open for write but was... The only thing that makes any sense to me is if it doesn't want the cylinder open for write so you might try to DowngradeOpen on the Cylinder. I have no idea where your transaction is coming from, and unless you declared a variable somewhere with a name of "blockTableRecord", you aren't adding the objects to anything meaningful. Unless I misunderstand the desired result, you should not add the cylinder to the transaction or the "blockTableRecord".
Why? Is this error because i have returning from function..
I definitely try to avoid passing or returning opened or temporary objects, in favor of passing ObjectID's when needed and keeping the transactions succinct. However, based on the code you have shown, I don't see you breaking the rules. I did just catch the fact that you declared solidBox and solidCylinder as New solid3d in the main function, then set them equal to the return value of the two draw functions, thereby replacing one New solid3d with another and dropping the first one. You should not use the New constructor on the declaration in the main function, but just set the value equal to the return from the draw function. Then you can't set any properties on it before it is created so you take out the RecordHistory line in the main function.
this:{code}Solid3d solidBox = new Solid3d();
solidBox.RecordHistory = true;
solidBox = drawSolidBox(this.dblLength, this.dblWidth, this.dblHeight);{code}
becomes:{code}Solid3d solidBox = drawSolidBox(this.dblLength, this.dblWidth, this.dblHeight);{code}
Dave O.                                                                  Sig-Logos32.png
Message 3 of 3
ACDC09
in reply to: SamPersi

Hallo,

Did you find solution for your problem?

I have the same problem while modifying the solid I get the same error, and I also tried to DowngradeOpen the solid but I get "eNodatabase".


Any help welcome.
Thanks

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