bug of intersectWith()

bug of intersectWith()

syx_lemans
Enthusiast Enthusiast
1,827 Views
11 Replies
Message 1 of 12

bug of intersectWith()

syx_lemans
Enthusiast
Enthusiast

I used these methods above to check entities' intersection

 

AcDbEntity* selectEntity(const ACHAR* prompt,
                         AcDbObjectId& id,
                         AcGePoint3d& pick,
                         AcDb::OpenMode openMode )
{
    AcDbEntity* ent = NULL;
    ads_name ename;
    
    if(acedEntSel(prompt, ename, asDblArray(pick) ) == RTNORM)
    {
        if(acdbGetObjectId(id,ename)==Acad::eOk)
            {
            if(acdbOpenAcDbEntity(ent,id,openMode)==Acad::eOk)
                return ent;
            }
    }
    return ent;
}

void Test()
{
    // TODO: Implement the command
    AcDbEntity* pEnt1;
    AcDbEntity* pEnt2;
    AcGePoint3d pick;
    AcDbObjectId id;
    Acad::ErrorStatus es;
    AcGePoint3dArray is;
    
    if((pEnt1 = selectEntity(_T("\nSelect 1st entity : "),
                             id,pick,AcDb::kForRead))== NULL)
    {
        acutPrintf(L"\nSelection failed");
        return;
    }
    
    if((pEnt2 = selectEntity(_T("\nSelect 2nd entity : "),
                             id,pick,AcDb::kForRead))== NULL)
    {
        acutPrintf(_T("\nSelection failed"));
        pEnt1->close();
        return;
    }
    
    es = pEnt1->intersectWith(pEnt2,AcDb::kOnBothOperands,is);
    
    if(es != Acad::eOk)
    {
        acutPrintf(_T("\nIntersectWith failed : es = %s"),
                   acadErrorStatusText(es));
    }
    else
    {
        acutPrintf(_T("\nGot %d intersections"),is.length());
        for(int i= 0;i<is.length();i++)
            {
            acutPrintf(_T("\nIntersection[%d] :(%.3lf,%.3lf,%3.lf)"),
                       i,is[i].x,is[i].y,is[i].z);
            }
    }
    pEnt1->close();
    pEnt2->close();
}

 

When I selection two entities with no intersection, it works well. However, when I take two entities with intersection, it crashes. It's apparently a issue from the intersectWith method., but I don't know why.

0 Likes
Accepted solutions (2)
1,828 Views
11 Replies
Replies (11)
Message 2 of 12

Alexander.Rivilis
Mentor
Mentor
Accepted solution

I can not reproduce your issue.

 

Code:

 

//-----------------------------------------------------------------------------
//----- acrxEntryPoint.cpp
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"

//-----------------------------------------------------------------------------
#define szRDS _RXST("")

//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CTestIntersectApp : public AcRxArxApp {

public:
	CTestIntersectApp () : AcRxArxApp () {}

	virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
		AcRx::AppRetCode retCode = AcRxArxApp::On_kInitAppMsg (pkt) ;
		return (retCode) ;
	}

	virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {
		AcRx::AppRetCode retCode = AcRxArxApp::On_kUnloadAppMsg (pkt) ;
		return (retCode) ;
	}

	virtual void RegisterServerComponents () {	}

  static AcDbEntity* selectEntity(const ACHAR* prompt,
    AcDbObjectId& id,
    AcGePoint3d& pick,
    AcDb::OpenMode openMode)
  {
    AcDbEntity* ent = NULL;
    ads_name ename;

    if (acedEntSel(prompt, ename, asDblArray(pick)) == RTNORM)
    {
      if (acdbGetObjectId(id, ename) == Acad::eOk)
      {
        if (acdbOpenAcDbEntity(ent, id, openMode) == Acad::eOk)
          return ent;
      }
    }
    return ent;
  }

	static void MyGroupMyCommand () {
    AcDbEntity* pEnt1;
    AcDbEntity* pEnt2;
    AcGePoint3d pick;
    AcDbObjectId id;
    Acad::ErrorStatus es;
    AcGePoint3dArray is;

    if ((pEnt1 = selectEntity(_T("\nSelect 1st entity : "),
      id, pick, AcDb::kForRead)) == NULL)
    {
      acutPrintf(L"\nSelection failed");
      return;
    }

    if ((pEnt2 = selectEntity(_T("\nSelect 2nd entity : "),
      id, pick, AcDb::kForRead)) == NULL)
    {
      acutPrintf(_T("\nSelection failed"));
      pEnt1->close();
      return;
    }

    es = pEnt1->intersectWith(pEnt2, AcDb::kOnBothOperands, is);

    if (es != Acad::eOk)
    {
      acutPrintf(_T("\nIntersectWith failed : es = %s"),
        acadErrorStatusText(es));
    }
    else
    {
      acutPrintf(_T("\nGot %d intersections"), is.length());
      for (int i = 0;i < is.length();i++)
      {
        acutPrintf(_T("\nIntersection[%d]: (%.3lf,%.3lf,%3.lf)"),
          i, is[i].x, is[i].y, is[i].z);
      }
    }
    pEnt1->close();
    pEnt2->close();
	}

	
} ;

//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CTestIntersectApp)

ACED_ARXCOMMAND_ENTRY_AUTO(CTestIntersectApp, MyGroup, MyCommand, MyCommandLocal, ACRX_CMD_MODAL, NULL)

Video:

 

 

 

1. What AutoCAD version you using? Have you all updates installed?
2. What ObjectARX SDK version you using?
3. What Visual Studio version you using?
 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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

Message 3 of 12

syx_lemans
Enthusiast
Enthusiast

Thank you for your reply.

I am using objectarx2011 and AutoCAD 2011. Perhaps it's too old.

When I ran the code, I got an issue:

acrxEntryPoint.cpp(71): error C2248: 'AcDbEntity::subIntersectWith' : cannot access protected member declared in class 'AcDbEntity'

And I found this in "sdk_map_names.h":

Capture.JPG

So I comment this line. Then it's compiled successfully.

But it crashed when I picked two intersecting lines

 

0 Likes
Message 4 of 12

Alexander.Rivilis
Mentor
Mentor

@syx_lemans wrote:

Thank you for your reply.

I am using objectarx2011 and AutoCAD 2011. Perhaps it's too old.

 


I can not check with AutoCAD 2011 but can recommend install all updates and check again:

https://knowledge.autodesk.com/support/autocad/downloads?release=2011

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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 5 of 12

tbrammer
Advisor
Advisor
Accepted solution

@syx_lemans wrote:

I am using objectarx2011 and AutoCAD 2011.

When I ran the code, I got an issue:

acrxEntryPoint.cpp(71): error C2248: 'AcDbEntity::subIntersectWith' : cannot access protected member declared in class 'AcDbEntity'

And I found this in "sdk_map_names.h":

Capture.JPG

So I comment this line. Then it's compiled successfully.

But it crashed when I picked two intersecting lines

 


I suppose you implemented your own custom entity class. I also suppose you have ported your project from a pre-ARX2010 version.

Starting with ARX 2010 many of the virtual AcDbEntity methods (like subIntersectWith()) became  sealed  (ADESK_SEALED), which means that they can not be overridden. DBX modules must instead override the sub*() methods (like subIntersectWith()) in custom entity classes.

On the other hand your ARX application still must call pEnt->intersectWith() - not  pEnt->subIntersectWith()!

I still have the ARX2010 SDK on my machine and searched for sdk_map_names.h. I don't have this header. Have you created it yourself?

Make sure that you use it's #defines in your DBX / custom entity code only - not in your ARX command implementation.

 

 


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

Message 6 of 12

syx_lemans
Enthusiast
Enthusiast

I updated my AutoCAD, but nothing changed.

[video]

The same code works for bricsCAD. I don't quite understand

0 Likes
Message 7 of 12

syx_lemans
Enthusiast
Enthusiast

I don't develop a lot for CAD. So I just pick the sample code and change something.

This may cause my problem.

When I comment the line of "subIntersectwith"

My program can be successfully compiled. But it got a fatal error when I use it for two intersecting entities. I didn't override this function.

0 Likes
Message 8 of 12

Alexander.Rivilis
Mentor
Mentor

1. Install ObjectARX Wizard 2011

2. Create new project with help of ObjectARX Wizard

3. Change content of acrxEntryPoint.cpp with my code

4. Compile and link this project with Visual Studio 2008 SP1

5. Check again

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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 9 of 12

Alexander.Rivilis
Mentor
Mentor

I've checked code with AutoCAD 2012, VS 2008 SP1 and ObjectARX SDK 2010. No errors: http://autode.sk/2nh5iqG

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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 10 of 12

syx_lemans
Enthusiast
Enthusiast

It's a problem with my AutoCAD. It works with other version.

There is no problem with the code.

Thank you so much for your replies

0 Likes
Message 11 of 12

syx_lemans
Enthusiast
Enthusiast

I didn't succeed to install objectarx wizard for vs2008 sp1. I got an issue " there is a problem with this windows installer package ".

Could I send my code to you to compile it and send me the arx file?

0 Likes
Message 12 of 12

syx_lemans
Enthusiast
Enthusiast

Sorry it's solved.

It's a User Account Control problem

0 Likes