Convert String data type to Objectid

Convert String data type to Objectid

waseefur.rahman
Advocate Advocate
3,468 Views
9 Replies
Message 1 of 10

Convert String data type to Objectid

waseefur.rahman
Advocate
Advocate

Hi Everyone,

Is there any way to convert string data type to objectid
i tried the below method to convert, but getting the error.

 
 

1.png

Could any one please advice, how to convert string data type to objectid.

Thanks in Advance

0 Likes
Accepted solutions (1)
3,469 Views
9 Replies
Replies (9)
Message 2 of 10

_gile
Consultant
Consultant

Hi,

I don't know where is this string from, but you can try something like this:

new ObjectId(new IntPtr(long.Parse(str)));


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 10

waseefur.rahman
Advocate
Advocate

Hi @_gile 

Actually i have stored Objectids in String collection,
and i want it to convert back string to object id.

can you please advice how to convert data type string to objectid.

Thanks

0 Likes
Message 4 of 10

waseefur.rahman
Advocate
Advocate

Hi @_gile 

I tried you  method but getting error as 'eUnknownHandle'
see the below image
1.png

could you please advice a where i am doing wrong?
Thanks

0 Likes
Message 5 of 10

_gile
Consultant
Consultant

Handle and ObjectId are two different identifiers.

Handles are unique per drawing persistant, ObjectIds are unique per session and not persistant (re-created and possibly different each time the drawing is opened).

You should show the code with which you get this string.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 6 of 10

jabowabo
Mentor
Mentor

If you are determined to use a list of object ids, why not just iterate all drawing objects, cast each of their ids to a string, then see if the list contains it? This is likely as fast as any other method.

0 Likes
Message 7 of 10

_gile
Consultant
Consultant
Accepted solution

We do not know what exactly Allobj_ids is (except it is a string array) and in which context is used.

If it is used within the same session of the drawing, you should not convert the ObjectId instances into strings and simply use an ObjectId array or an ObjectIdCollection.

If it used in a different session, the string array should be based on Handles instead of ObjectIds.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 8 of 10

waseefur.rahman
Advocate
Advocate

Hi Gile,

As per your suggestion i stored Handle to String Collection,
but when i tried to modify entity property, 
like changing the layer name,
i got the error as eKeyNotFound.

attached the Code Snip below,
1.png
Could you please advice where i am doing wrong.
Thanks

0 Likes
Message 9 of 10

_gile
Consultant
Consultant

This is a totally different error.

This time the error is due to the fact none LayerTableRecord named: Cur_NM + "_Split_" + Split_Lay.ToString() exists in the layer table.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 10 of 10

waseefur.rahman
Advocate
Advocate

Hi @_gile ,

That's onspot,
you nailed it,
Now i will have a pleasant sleep tonight..
have a good night..
really thankful for your help..

0 Likes