ObjectIDtoObject

ObjectIDtoObject

john.uhden
Mentor Mentor
2,046 Views
12 Replies
Message 1 of 13

ObjectIDtoObject

john.uhden
Mentor
Mentor

I'ved used that method plenty in 2002, but Civil 3D 2014 is giving me...

 

"; error: Exception occurred: 0xC0000005 (Access Violation)
; warning: unwind skipped on unknown exception"

 

It seems to not matter whether I use (vlax-invoke ...) or (vla-ObjectID...).

Does this method no longer work?  Must I go back to chasing 330 codes?

John F. Uhden

0 Likes
Accepted solutions (1)
2,047 Views
12 Replies
Replies (12)
Message 2 of 13

Ranjit_Singh
Advisor
Advisor
See if below helps...objectidtoobject_error.gif
0 Likes
Message 3 of 13

john.uhden
Mentor
Mentor

That's insane.  This is AutoLisp.  What can be the difference between 42 and a function that evaluates to 42?!

John F. Uhden

0 Likes
Message 4 of 13

Ranjit_Singh
Advisor
Advisor

I would imagine that's the way the contract of objectIDtoObject works. If you see the error, it states access violation. Somehow the access is only provided when accessing it through the vla-getobjectid function. Just a guess.

0 Likes
Message 5 of 13

john.uhden
Mentor
Mentor

Well of course you need the ObjectId function to get the ID, but it's still 42 (in your example).  It's just an evaluation.

I mean no big deal; if that's the rule I can live with that.  It's just stupid.

 

Sam:  "Knock 3 times so I know it's you."

Fred:  Knocks 3 times.

Sam:  "No, you idiot.  Not like that.  Use the (knock) function!"

John F. Uhden

0 Likes
Message 6 of 13

dgorsman
Consultant
Consultant

Might want to do some checking; the object ID returned on a 64-bit system might be a long rather than an INT.  Maybe test with 42.0?

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


0 Likes
Message 7 of 13

Ranjit_Singh
Advisor
Advisor

@john.uhden wrote:

............

I mean no big deal; if that's the rule I can live with that.  It's just stupid.



I agree. You might say (eval objid) is the same as the integer 45, but this specific function does not see it like that. if objid is the pointer to subject object id then even this works

Command: (vla-objectidtoobject (vla-get-activedocument (vlax-get-acad-object)) (eval objid))
#<VLA-OBJECT IAcadLWPolyline 000000004714da48>

just like

Command: (vla-objectidtoobject (vla-get-activedocument (vlax-get-acad-object)) objid)
#<VLA-OBJECT IAcadLWPolyline 000000004714da48>

 

but this does not work

Command: (vla-objectidtoobject (vla-get-activedocument (vlax-get-acad-object)) 45)
; error: Exception occurred: 0xC0000005 (Access Violation)
; warning: unwind skipped on unknown exception

So technically you do not need the objectID function, as long as you pass some symbol that evaluates to the objectID

Command: (vl-symbolp 'objid)
T
Command: (vl-symbolp 'eval)
T
Command: (vl-symbolp '45)
nil
Command: (vl-symbolp 45)
nil

 

0 Likes
Message 8 of 13

john.uhden
Mentor
Mentor

Knock 3 times if you need me.

OR...

If you need me, I'll give you a call.

OR...

"All of you who believe in telekenesis, raise my hand"

John F. Uhden

0 Likes
Message 9 of 13

john.uhden
Mentor
Mentor

Hi, Ranjit.

 

I was just thinking... there must be some difference between what the objectid or ownerid property returns to AutoLisp vs. what it returns to the objectidtoobject function, or maybe how AutoLisp interprets the evaluation.

 

Maybe it's actually a long integer that AutoLisp takes as a short integer.  I dunno; just thinking is all.

John F. Uhden

0 Likes
Message 10 of 13

Ranjit_Singh
Advisor
Advisor

Pick a polyline

(itoa (vla-get-objectid (vlax-ename->vla-object (car (entsel)))))

(itoa 45) definitely does not return thatSmiley Happy

Command: (vla-objectidtoobject *adoc* 45)
; error: Exception occurred: 0xC0000005 (Access Violation)
; warning: unwind skipped on unknown exception
Command: (itoa (vla-get-objectid (vlax-ename->vla-object (car (entsel))))) Select object: "8796083183968" Command: (vla-objectidtoobject *adoc* 8796083183968) #<VLA-OBJECT IAcadLWPolyline 0000000074e8a438>

 

 

Message 11 of 13

john.uhden
Mentor
Mentor

I should have been more forward with my objective.  I actually want to freeze. layers by picking objects.  No, not necessarily the layer of the object returned by (entsel) nor by the object returned by (nentsel), but in between.  If a line on layer "0" is embedded in a block named "X" that is inserted in layer "1" in an xref, then I want to freeze layer "xref|1."  I thought the OwnerId was the path to take, but alas it takes you to the block record table, not the reference.

 

To complicate things more, block "X" might be inserted on layers "1" "2" and/or "3" in the xref.  Or even block "X" might be inserted into block "Y" on layers "4" "5" and/or "6" in the xref.  I probably don't want to freeze layer "0."

 

I guess I need a (parents) or (ancestors) function.

John F. Uhden

0 Likes
Message 12 of 13

_gile
Consultant
Consultant
Accepted solution

Hi,

 

You can use nentsel. If the selected entity is nested an is not an attribute reference, the last item of the returned list is the list of the ancestors.

In your example, this list should contain 2 items: the X block reference ename and the xref ename.

 

A little example:

 

(defun getAncestors (/ nent elst)
  (if (setq nent (nentsel))
    (cond
      ((cadddr nent))
      ((= "ATTRIB" (cdr (assoc 0 (setq elst (entget (car nent))))))
       (list (cdr (assoc 330 elst)))
      )
    )
  )
)

(mapcar '(lambda (ent) (cdr (assoc 8 (entget ent)))) (getAncestors))

About the ObjectId, this behavior is due to the fact on a 64-bit AutoCAD the ObjectIds are coded with 64-bit integers and AutoLISP only have 32-bit integers so it cannot return the value as an integer (as it does with 32-bit AutoCAD versions).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 13 of 13

john.uhden
Mentor
Mentor

You know, I am stupider than I look.  I had just looked back to some very old code of mine, and there it was.

Thank you, @_gile for confirming something I had already known but just forgot after 18 years.  I feel much better now.

John F. Uhden

0 Likes