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

AcDbMPolygon

6 REPLIES 6
Reply
Message 1 of 7
Anonymous
340 Views, 6 Replies

AcDbMPolygon

Can somebody tell me the how to get the are and perimeter of a polygon using AcDbMPolygon?

I tried the following code but it is not working.
Can somebody please tell me what I am doing wrong?

#include "dbMPolygon.h"


void getPolyPeri (AcDbObjectId id) {
float Perimeter;
AcDbEntity* pEnt = NULL;
if (acdbOpenObject(pEnt, id, AcDb::kForRead) == Acad::eOk) {
Perimeter = pEnt->getPerimeter();

acutPrintf(Perimeter);

}

Please let me know what you think.
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: Anonymous

getPerimeter are not a function on AcDbEntity.
Cast it to an AcDbMPolygon (make sure the cast is ok) and then get the
perimeter.

/Matt


wrote in message news:5107143@discussion.autodesk.com...
Can somebody tell me the how to get the are and perimeter of a polygon using
AcDbMPolygon?

I tried the following code but it is not working.
Can somebody please tell me what I am doing wrong?

#include "dbMPolygon.h"


void getPolyPeri (AcDbObjectId id) {
float Perimeter;
AcDbEntity* pEnt = NULL;
if (acdbOpenObject(pEnt, id, AcDb::kForRead) == Acad::eOk) {
Perimeter = pEnt->getPerimeter();

acutPrintf(Perimeter);

}

Please let me know what you think.
Message 3 of 7
OysteinW
in reply to: Anonymous

Try this:

#include "dbMPolygon.h"
void getPolyPeri (AcDbObjectId id) {
double Perimeter; //getPerimeter returns a double
AcDbMPolygon* pEnt = NULL; // Declare it as a AcDbMPolygon instead..
if (acdbOpenObject(pEnt, id, AcDb::kForRead) == Acad::eOk) {
Perimeter = pEnt->getPerimeter();

acutPrintf("Perimeter =%f",Perimeter); // acutPrintf doesn't accept just a double I think.. You have to format the message ..

pEnt->close(); // Remember to close the object when you're done!
} Message was edited by: OysteinW
Message 4 of 7
Anonymous
in reply to: Anonymous

Thanks for the help.
I however have another question.
If I open an existing drawing with lots of polylines and call the application with the above code, will it wait for the user to select a polyline?
I expect that something like this should happen? Hopefully there are no surprises here!

Please advice me on this.
Message 5 of 7
Anonymous
in reply to: Anonymous

Nothing is selected here.
This just works on a objectId gotten somewhere.

You can either ask the user to select polyline(s) or scan the entire
database.

/M


wrote in message news:5107251@discussion.autodesk.com...
Thanks for the help.
I however have another question.
If I open an existing drawing with lots of polylines and call the
application with the above code, will it wait for the user to select a
polyline?
I expect that something like this should happen? Hopefully there are no
surprises here!

Please advice me on this.
Message 6 of 7
Anonymous
in reply to: Anonymous

Does that mean that the actual code I am looking at should look like this:

AcDbObjectId id;
ads_name ssname;
ads_point pt;
acedEntSel("\nSelect Defined polygon", ssname, pt);
acdbGetObjectId(objId, ssname);

double Perimeter;
AcDbMPolygon* pEnt = NULL;
if (acdbOpenObject(pEnt, id, AcDb::kForRead) == Acad::eOk) {
pEnt->getPerimeter(Perimeter);\\ or Perimeter = pEnt->getPerimeter();

pEnt->close();

acutPrintf(Perimeter);

}
Thanks for the help again.
Message 7 of 7
Anonymous
in reply to: Anonymous

Except for the printf.



wrote in message news:5107301@discussion.autodesk.com...
Does that mean that the actual code I am looking at should look like this:

AcDbObjectId id;
ads_name ssname;
ads_point pt;
acedEntSel("\nSelect Defined polygon", ssname, pt);
acdbGetObjectId(objId, ssname);

double Perimeter;
AcDbMPolygon* pEnt = NULL;
if (acdbOpenObject(pEnt, id, AcDb::kForRead) == Acad::eOk) {
pEnt->getPerimeter(Perimeter);\\ or Perimeter = pEnt->getPerimeter();

pEnt->close();

acutPrintf(Perimeter);

}
Thanks for the help again.

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

Post to forums  

Autodesk Design & Make Report

”Boost