.NET

Reply
Distinguished Contributor
jmaeding
Posts: 971
Registered: ‎12-27-2006
Message 1 of 11 (596 Views)

convert entity name to objectID

596 Views, 10 Replies
01-03-2012 11:12 AM

I commonly send serialized data to .net functions.

One of the items I send in the entity name of something as a string.

Once my .net function is done, it constructs a resultbuffer to send back to lisp.

I had been doing this:

AcDb.ObjectId id = new ObjectId(Convert.ToInt32(ename));

 

but the Convert function is throwing an exception.

I do not recall this happening before, but forget if I ever tested it.

I am on win 7 64 bit.

I thought the ename was a hex number, but am confused on it now.

Anyone got ideas to make it work?

*Expert Elite*
Alfred.NESWADBA
Posts: 9,070
Registered: ‎06-29-2007
Message 2 of 11 (579 Views)

Re: convert entity name to objectID

01-03-2012 02:26 PM in reply to: jmaeding

Hi,

 

looking into the signature of the construction method I see:

Public Sub New(oldId As Integer)

There is nothing written about "Int32" :smileywink:

 

HTH, - alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 11 (574 Views)

Re: convert entity name to objectID

01-03-2012 03:03 PM in reply to: jmaeding

May be I don't understand your task

but this is from working code:

 

                        long lg = System.Convert.ToInt64(kvp.Key, 16);//kvp.Key contains Handle as string


                        Handle hd = new Handle(lg);

 

                        //get then the ObjectId from the Handle


                        ObjectId blkId = db.GetObjectId(false, hd, -1);

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Mentor
fieldguy
Posts: 371
Registered: ‎03-31-2005
Message 4 of 11 (571 Views)

Re: convert entity name to objectID

01-03-2012 03:06 PM in reply to: jmaeding
Distinguished Contributor
jmaeding
Posts: 971
Registered: ‎12-27-2006
Message 5 of 11 (565 Views)

Re: convert entity name to objectID

01-03-2012 03:55 PM in reply to: fieldguy

I saw the handle to objectid posts, but I am not dealing with a handle, but an entity name that you would get from the -1 group of and entget list from:

(entget (car (entsel)))

 

I have the entity name as a string in my .net prog, and want to send back a resultbuffer with the ename:

new TypedValue(-1, new ObjectId(Convert.ToInt32(ename)))

 

So I am wondering if the same tricks apply to handles and enames, in terms of data conversion.

Active Member
ricky.medley
Posts: 6
Registered: ‎08-29-2008
Message 6 of 11 (429 Views)

Re: convert entity name to objectID

10-25-2012 09:13 AM in reply to: jmaeding

jmaeding wrote:

I saw the handle to objectid posts, but I am not dealing with a handle, but an entity name that you would get from the -1 group of and entget list from:

(entget (car (entsel)))

 

I have the entity name as a string in my .net prog, and want to send back a resultbuffer with the ename:

new TypedValue(-1, new ObjectId(Convert.ToInt32(ename)))

 

So I am wondering if the same tricks apply to handles and enames, in terms of data conversion.


My interpretation...
The first post says you are having issues with taking in the ename and converting to an ObjectId.

The second post says you are having issues sending the ename back.

 

The first post...


//check lisp arguments here
//then convert to an array
TypedValue[] args = rb.AsArray();
if (args[0].TypeCode != (short)LispDataType.ObjectId)
ObjectId objId = (ObjectId)args[0].Value
//start using transaction with try/catch...
//I'm usin a BlockTableRecord in my example.
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(objId, OpenMode.ForRead, false);
//----------------------
//or just skip a step if you're not going to reuse ObjectId elsewhere
//BlockTableRecord btr = (BlockTableRecord)tr.GetObject((ObjectId)args[0].Value, OpenMode.ForRead, false);


  

For the secod post...

If your ename is the hex ename we see in autolisp, then...

ObjectId newObjId = new ObjectId(new IntPtr(Convert.ToInt64(hexEname, 16)));

If your ename is the string form of decimal for of the ename, then it's pretty much the same...

ObjectId newObjId = new ObjectId(new IntPtr(Convert.ToInt64(strDecEname)));

 

No need to send back a ResultBuffer if your just sending back the lisp ename object.  Just return the TypedValue.

 

Hope this helps.

Distinguished Contributor
jmaeding
Posts: 971
Registered: ‎12-27-2006
Message 7 of 11 (422 Views)

Re: convert entity name to objectID

10-25-2012 10:01 AM in reply to: jmaeding

I'll try that, its been a while since I posted this.

thanks

*Expert Elite*
_gile
Posts: 2,084
Registered: ‎04-29-2006
Message 8 of 11 (405 Views)

Re: convert entity name to objectID

10-25-2012 10:23 PM in reply to: jmaeding

Hi,

 

While using the LispFunction argument to define a LISP function or using the Application.Invoke() method (or P/Invoking acedInvoke) to call a LISP function from .NET, an ename is automatically converted from or to a TypedValue with TypeCode = LispDataType.ObjectId.

Gilles Chanteau
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 9 of 11 (400 Views)

Re: convert entity name to objectID

10-26-2012 12:03 AM in reply to: jmaeding

As you said above

>> I commonly send serialized data to .net functions.

Would be good in this case to hold Handles instead of ObjectIds

in this case?

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Distinguished Contributor
jmaeding
Posts: 971
Registered: ‎12-27-2006
Message 10 of 11 (384 Views)

Re: convert entity name to objectID

10-26-2012 07:53 AM in reply to: jmaeding

possibly, but one of my goals was to send all data from entget to .net, and back to lisp.

I do use handles, though, for anything that needs to recall another entity's name.

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.