Boolean Operation

Boolean Operation

Anonymous
Not applicable
2,115 Views
6 Replies
Message 1 of 7

Boolean Operation

Anonymous
Not applicable

HI COM,

 

In this code i want to subtract to solid a solid clone.

 

//open main entity

if(acdbOpenObject(entMain,idMainAcDb::kForWrite)==Acad::eOk)

{

AcDb3dSolid *myMainSolid=AcDb3dSolid::cast(entMain);

 

//open tool entity

       if(acdbOpenObject(entTool,idTool,AcDb::kForWrite)==Acad::eOk)

       {

             //clone tool entity

             AcDb3dSolid *myCloneSolid=AcDb3dSolid::cast(entTool->clone());

entTool ->close(); //close tool entity

            

 

es= myMainSolid->booleanOper(AcDb::kBoolSubtract, myCloneSolid);

                                                                  

            

myCloneSolid->close();

             delete myCloneSolid;

             myCloneSolid=NULL;

}

 

entMain->close();

                                                     

}

 

 

I have two objectS in the model space and i open each in the write mode.

The first object is the main solid, the second is the "tool" solid.

I clone the tool solid and in this way the boolean operation doesn’t work.

 

The error code is ‘eWasOpendedForWrite’ but the tool entity is been closed before the operation.

 

If I add the solid clone to model space  and re-open the Id, the operation works. is it right? why?

 

Regards,

 

Bruno

 

0 Likes
Accepted solutions (1)
2,116 Views
6 Replies
Replies (6)
Message 2 of 7

owenwengerd
Advisor
Advisor

Maybe you have solid history enabled, and the shallow clone still references the solid history sub-object of the source solid?

--
Owen Wengerd
ManuSoft
0 Likes
Message 3 of 7

tbrammer
Advisor
Advisor

Owen is right. Your code works well for solids without history - but not for those with history.

I tried to disable history using myCloneSolid->setRecordHistory(false)/setShowHistory(false) but that didn't help. It seems there is no other way to subtract solids with history than to append them to the DB. I found no other API to handle the history.

I still wonder why this happens. The AcDb3dSolid is a "hard owner" of its AcDbShHistory. In fact the original solid and its shallow clone both point to the same history object during the boolean operation. But why is this a problem?

But the more important question is: How can we handle this problem other than appending the clone to the DB and erase() it afterwards?


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

0 Likes
Message 4 of 7

Anonymous
Not applicable

we found the solution disabling hystory on both solids:

 

if(acdbOpenObject(entMain,idMainAcDb::kForWrite)==Acad::eOk)

{

AcDb3dSolid *myMainSolid=AcDb3dSolid::cast(entMain);

 

//open tool entity

       if(acdbOpenObject(entTool,idTool,AcDb::kForWrite)==Acad::eOk)

       {

             //clone tool entity

             AcDb3dSolid *myCloneSolid=AcDb3dSolid::cast(entTool->clone());

entTool ->close(); //close tool entity

            

myMainSolid->setRecordHistory(false);

             myCloneSolid->setRecordHistory(false);

 

es= myMainSolid->booleanOper(AcDb::kBoolSubtract, myCloneSolid);

                                                                  

            

myCloneSolid->close();

             delete myCloneSolid;

             myCloneSolid=NULL;

}

 

entMain->close();

                                                     

}

 

In this way it works.

 

Regards,

 

Bruno

0 Likes
Message 5 of 7

Alexander.Rivilis
Mentor
Mentor

This line of code:

myCloneSolid->close();

is superfluous as myCloneSolid is not database resident object.

 

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

0 Likes
Message 6 of 7

Alexander.Rivilis
Mentor
Mentor
Accepted solution

@Anonymous

It is look like enough to clear history of main 3DSOLID:

 

static void RivilisBoolSub () {
  ads_name en1, en2;  ads_point p;
  Acad::ErrorStatus es;
  if (acedEntSel(L"\nSelect main 3DSOLID: ", en1, p) == RTNORM &&
      acedEntSel(L"\nSelect tool 3DSOLID: ", en2, p) == RTNORM) {
    AcDbObjectId id1, id2;
    acdbGetObjectId(id1, en1); acdbGetObjectId(id2, en2);
    AcDbObjectPointer<AcDb3dSolid> pMainSol(id1, AcDb::kForWrite);
    AcDbObjectPointer<AcDb3dSolid> pToolSol(id2, AcDb::kForWrite);
    if (pMainSol.openStatus() == Acad::eOk && pToolSol.openStatus() == Acad::eOk) {
      AcDb3dSolid *pCloneTool = new AcDb3dSolid();
      // Creating clone of pToolSolid:
      pCloneTool->setASMBody(pToolSol->ASMBodyCopy(false));
      pToolSol->close();
      // Clear history of main Solid
      if (pMainSol->recordHistory())
        pMainSol->setRecordHistory(false);
      es = pMainSol->booleanOper(AcDb::kBoolSubtract, pCloneTool);
      delete pCloneTool;
    }
  }
}

AutoCAD 2017 video:

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

0 Likes
Message 7 of 7

Anonymous
Not applicable

Hi Alexander,

 

thank you so much. Great work.

 

Regards,

 

Bruno

0 Likes