Problem find all intersection of Lines!

Problem find all intersection of Lines!

D_D_K
Advocate Advocate
900 Views
9 Replies
Message 1 of 10

Problem find all intersection of Lines!

D_D_K
Advocate
Advocate

Hi, I am trying to create a simple code to find all the intersection points of the lines, but the code was unable to loop next second time, where did I go wrong:

I use 2 arrays: arrPts to hold intersections and arrPts0 to hold all intersections, no duplicate checks

This is my code:

ads_name sname;
int isok=acedSSGet(NULL, NULL, NULL, NULL, sname);
if (isok!= RNORM)
        return;
Adesk::Int32 length=0; acedSSLength(sname, &length);
AcGePoint3dArray arrPts0;
for (int i = 0; i < length-1; i++) {
        //get first entity from ssname -> adsname
        AcDbObjectId id = AcDbObjectId::kNull; ads_name adse;
        acedSSName(sname, i, adse);
//get entity from adsname -> AcDbObjectId -> ent AcDbEntity* pEnt; openEntity(adse, id, pEnt, fR); // combine getobjectID+getentity //loop extant selectionset -> get intersect -> add to array for (int j=++i;j<length;j++) { AcDbObjectId id1 = AcDbObjectId::kNull; ads_name adse1; acedSSName(sname, j, adse1); AcDbEntity* pEnt1; openEntity(adse1, id1, pEnt1, fR);
//get intersect point AcGePoint3dArray arrPts; if (pEnt->intersectWith(pEnt1, AcDb::kOnBothOperands, arrPts) == Acad::eOk) { if (arrPts.length() != 0) { for (AcGePoint3d pt : arrPts) arrPts0.append(pt); ///put all point to this array } pEnt1->close(); } } pEnt->close(); } //can't loop continue

please help me.

Thanks a lot!

 

 

 

 

0 Likes
901 Views
9 Replies
Replies (9)
Message 2 of 10

D_D_K
Advocate
Advocate

I have read this article https://forums.autodesk.com/t5/objectarx/orms-of-intersectwith/td-p/6975878 and use @Alexander.Rivilis 's code but still get the same error, I am build Vsto2019, Arx2020, Cad2020 and C ++ 1

This is the error I get, it seems to be related to closing point3darray ..., maybe

 

image.png

 

 

0 Likes
Message 3 of 10

Alexander.Rivilis
Mentor
Mentor

It is look like you using VS 2019 instead of VS 2017. You can use VS 2019 only if set Platform Toolset to Visual Studio 2017 (v141):

 

2020-01-19_18-14-14.png

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

D_D_K
Advocate
Advocate

image.png

I 'm using boths vsto 2017 and 2019 versions, I have used many ways but still can not prevent scalar deleting destructor

 

 

image.png

 

 

0 Likes
Message 5 of 10

Alexander.Rivilis
Mentor
Mentor

In your's code pEnt1->close() called only if pEnt and pEnt1 has intersection, but you have to close in both cases.

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

D_D_K
Advocate
Advocate

yes, but i'm speculating that point3darray when breaking out of block {} will free itself memory or something makes ~array  function automatically called and break code! 
I tried changing pent.close and pent1.close but the result is constant. But it was just my guess 

 

image.png

 

image.png

 

 

 

 

0 Likes
Message 7 of 10

Alexander.Rivilis
Mentor
Mentor

Try to build in Release configuration.

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

D_D_K
Advocate
Advocate

Hi, it sounds a bit strange, I tried changing the variable declaration to

AcGePoint3dArray *arrPts0 =new AcGePoint3dArray; AcGePoint3dArray *arrPts = new AcGePoint3dArray;

then use this for the rest of the code and it worked both on vsto2019 v142. Perhaps this is a temporary solution for me. 😅

 

 

0 Likes
Message 9 of 10

Alexander.Rivilis
Mentor
Mentor

@D_D_K 

You should not use Platform Toolset v142 with ObjectARX 2020. All problems with memory management is due to using incorrect Platform Toolset.

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

D_D_K
Advocate
Advocate

thanks for your suggestion, so I will keep 2017 .

 

 

0 Likes