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

Getting Polyline Data into a Custom Derived object(from polyline)

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
ChaosInACT
1338 Views, 3 Replies

Getting Polyline Data into a Custom Derived object(from polyline)

Hello again!

 

I've been working on a custom polyline object, and I've got it functioning!!!

 

Having said that, I plan to run its creation around picking a point for bounary selection.

 

(Other than trying to step through every vertecies) is there a technique I can thow the polyline data from a traceboundary result into my custom object? I've been trying to add the polyline from traceboundary to my object BEFORE it's added to the transaction by the way...I assume that's right, since I want to put it's data in my custom object then add my custom object to the transaction instead.

 

Thanks for any thought you might have,

ChaosInACT

Robot Happy

3 REPLIES 3
Message 2 of 4
hgasty1001
in reply to: ChaosInACT

Hi,

 

II think there is no way to create a custom entitiy with .NET API in AutoCAD, please explain in more detail what your "custom polyline object" is, can you share the code?

 

Gaston Nunez

Message 3 of 4
ChaosInACT
in reply to: hgasty1001

First off, thanks as always for the response!

 

"II think there is no way to create a custom entitiy with .NET API in AutoCAD,"

 

True enough! I'm creating [have created, woot!] a custom derived AcDbPolyline in C++ , then using a manged wrapper to insert it into vb.net (ala the SimpleSquare or even PolySamp project in the ObjectARX SDK, though not using COM at this stage).

 

I'm actually very happy to upload the lot but I would need to clean it down - it has a lot of commented out code I plan to renenact later once base testing is doen.

 

Anyway it works a treat, but I'm not feeding it through a jig like simple square - I'm trying to use TraceBoundary in vb to get a polyline and pass the polyline data straight into my custom object (though as I slept last night it dawned on me I probably need to write a c++ routine to receive it...but since it's a superset, so to speak, of polyline all the data slots are there and I can't help wonderinig if there is a easy way to put the data in there.

 

Any how is the relavent code calling the object in vb - again if you want to see the whole thing let me know, i'll clean it up for upload.

 

           

Dim vb_LotObject As mgLotObject

           

Try

               

'initalize the managed class

               

vb_LotObject = NewmgLotObject()

               

If vb_LotObject Is Nothing Then

                   

Throw New ApplicationException("Could not create LOT")

               

EndIf

               

vb_LotObject.SetDatabaseDefaults()

           

Catch ex As Exception

               

MsgBox("Error during ADDSQ Command: " + ex.Message)

               

Return

           

End Try

           

vb_LotObject.Normal = normal

 

 

'code polulating some dummy date etc

'....and then

'this works

 

           

btr.AppendEntity(vb_LotObject)

           

trans.AddNewlyCreatedDBObject(vb_LotObject, True)

 

So, short of writing a routine to receive in my custom object, is there some cheeky way i can try

to cast /throw /heck, beg my polyine caught from :

 

.....

           

resultTraceBoundary = ed.TraceBoundary(origin, False)

           

If resultTraceBoundary.Count > 0 Then

               

Try

Dim ent As Entity = CType(resultTraceBoundary.Item(0), Entity)

 

.....

 

into the mgLotObject above? I've tried a few ways of casting the polyline in or vice verca, but I'm totally guessing what AutoCAD will put up with here 😉

Message 4 of 4
ChaosInACT
in reply to: ChaosInACT

I never did find a manged -> un-manged direct solution, but if anyone else is ever in this boat, here was my solution:

 

I created a c++ function inside my custom object called ConstructPoly - I pass it the ObjectID of the polyline I've created though TraceBoundary through the managed wrapper like so:

 

Acad::ErrorStatusBCHF::LotObjectWrap::mgLotObject::ConstructPoly(Autodesk::AutoCAD::DatabaseServices::ObjectIdvalue)

{

Autodesk::AutoCAD::Runtime::Interop::Check(GetImpObj()->ConstructPoly(GETOBJECTID(value)));

returnAcad::eOk;

}

 

And then here is the actual unmanaged function that recieves it:

 

Acad::ErrorStatusBCHF_LotObject::ConstructPoly(AcDbObjectIdvalue)

{

//make sure objectID  not null

if(value==NULL)

returnAcad::eNullObjectId;//<-if is drop out

//declare an entity

AcDbEntity*ent=NULL;

//for debugging

acutPrintf(_T("\nEntering Vertex Constructor: ObjectID = %d"),value);

//open entity for read

if(acdbOpenAcDbEntity(ent,value,AcDb::kForRead)!=Acad::eOk)

returnAcad::eNotOpenForRead;//<-drop out if fail

//confirm entity is open for read

if(ent==NULL)

returnAcad::eNullEntityPointer;//<- it isn't drop out

//its all good, check type

if(ent->isKindOf(AcDbPolyline::desc()))

{

AcDbPolyline*pickPoly;

pickPoly=AcDbPolyline::cast(ent);

acutPrintf(_T("\nPassed Test, Entity IS a AcDbPolyline"));

 

// Use a for loop to get each vertex, one by one

intvx=pickPoly->numVerts();

for(inti=0;i<=vx-1;i++)

{

AcGePoint2dpt;

pickPoly->getPointAt(i,pt);

doublebulgeNow;

pickPoly->getBulgeAt(i,bulgeNow);

doubleSwidth;

doubleEwidth;

pickPoly->getWidthsAt(i,Swidth,Ewidth);

this->addVertexAt(i,pt,bulgeNow,Swidth,Ewidth,0);

}

this->setClosed(pickPoly->isClosed());

pickPoly->upgradeOpen();

pickPoly->erase();

pickPoly->close();

}

else

{

acutPrintf(_T("\nFailed Test, Entity is NOT an AcDbPolyline"));

returnAcad::eNotAnEntity;

}

if(ent!=NULL)

ent->close();

returnAcad::eOk;

}

 

 

and then you can do this:

 

myCustomObjectName.ConstructPoly(polyID)

 

in vb.net and it creates the drived polyline object and deletes the polyline handed it.

 

Hope that helps someone 🙂

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