Author Topic: Finding Entity from ObjectID  (Read 7505 times)

0 Members and 1 Guest are viewing this topic.

Rabbit

  • Guest
Finding Entity from ObjectID
« on: June 22, 2011, 12:36:08 PM »
I think it may be a syntax problem with vla-ObjectIDToObject32

;used to get Object Id from a field code
(setq PlineObjId (substr PlineFieldCode (+ (vl-string-search "ObjId" PlineFieldCode) 7) 13))
;returns the ObjectId numbers as a string

;I'm trying to use this to find the entity (lwpolyline) tied to the Object Id from above.
;I'm having trouble finding anything on the web which shows how to use vla-ObjectIDToObject32
;I've tried real, string and integer forms of the PlineObjectID
 (vla-ObjectIDToObject32 (vla-get-activedocument (vlax-get-acad-object)) (atoi PlineObjId))

Thanks,
Rabbit

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Finding Entity from ObjectID
« Reply #1 on: June 22, 2011, 01:41:07 PM »
The problem will most likely be using atoi, since I would think the ObjectIDtoObject32 method requires a long on 64-bit systems. I suffered the same problem using atoi with the SetBlockTableRecordID32 method on a table.
« Last Edit: June 22, 2011, 01:44:42 PM by Lee Mac »

Rabbit

  • Guest
Re: Finding Entity from ObjectID
« Reply #2 on: June 22, 2011, 02:00:08 PM »
I'm not sure what a LONG is.  Is it an iteger or real.  Or, is it an integer with decimal places, I.E. 12345.67

Cunfused,
Rabbit

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Finding Entity from ObjectID
« Reply #3 on: June 22, 2011, 02:16:32 PM »
A Long is a data type that holds an integer value but occupies more memory (8 bytes on a 64-bit machine) than the (Short) Integer data type. It is equivalent to a 64-bit Integer - this will give a better insight. When you use the atoi function, this truncates the string to the size of a 32-bit integer and so you lose some information.

Maybe the following will help - it will retrieve the Entity name of the entity referenced by the Field (which could then be converted to a VLA-Object if specifically required).

Code: [Select]
(defun Field->Entity ( en )
  (cond
    (
      (and
        (wcmatch (cdr (assoc 0 (setq en (entget en)))) "TEXT,MTEXT,ATTRIB")
        (setq en (cdr (assoc 360 en)))
        (setq en (dictsearch en "ACAD_FIELD"))
        (setq en (dictsearch (cdr (assoc -1 en)) "TEXT"))
        (setq en (cdr (assoc 360 en)))
        (setq en (cdr (assoc 331 (entget en))))
      )
      en
    )
  )
)

Supply it with the Ename of the entity containing the field (MText, Text, Attrib).
« Last Edit: June 22, 2011, 02:22:13 PM by Lee Mac »

Rabbit

  • Guest
Re: Finding Entity from ObjectID
« Reply #4 on: June 22, 2011, 02:30:27 PM »
I'm still not sure why I'm not able to put in a 13 digit number into the function as a LONG and it not work.


Here's all my code.  The table has acell with a field with the area of a closed lwpolyline.

Code: [Select]
(defun c:GetCellFieldCode  ( / eText oText)
  ;;;Selects a table
  ;;;
  ;;;Code:

  ;;;(setq id (IdMtextTable (car (entsel))))
  (setq id (IdMtextTable (setq TableEntity (ssname (ssget "X" (list (cons 0 "acad_table") '(8 . "E-LGHT-CALC-SCHEDULE"))) 0))))
  (setq TAbleRowCount (vlax-get-property (vlax-ename->vla-object TableEntity) 'Rows))
  (setq TAbleRowCount (vlax-get-property (vlax-ename->vla-object TableEntity) 'Columns))

  ;;;To find at row 4 and column 1
  ;;;
  ;;;Code:

  (setq ent (mapcar 'caddr (vl-remove-if-not '(lambda (x) (and (eq (car x) 3) (eq (cadr x) 2))) id)))

  (setq PlineFieldCode (vla-fieldcode (car ent)))

 
  (setq PlineObjId (substr PlineFieldCode (+ (vl-string-search "ObjId" PlineFieldCode) 7) 13))

 
  (vla-ObjectIDToObject32 (vla-get-activedocument (vlax-get-acad-object)) (atoi PlineObjId))

);defun

;;;--------------Sub Routine-------------
(defun IdMtextTable(tab / col ent fus id lig lst)
  (setq ent (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (cdr (assoc 2 (entget tab)))))
  (vlax-map-collection ent '(lambda (x) (and (vlax-property-available-p x 'AttachmentPoint) (setq lst (cons x lst)))))
  (setq lst (reverse lst) lig 0 tab (vlax-ename->vla-object tab))
  (while (< lig (vla-get-rows tab))
    (setq col 0)
    (while (< col (vla-get-columns tab))
      (or (eq (vla-ismergedcell tab lig col 0 0 0 0) :vlax-false)
   (eq lig 0)
   (eq (vla-ismergedcell tab (1- lig) col 0 0 0 0) :vlax-false)
   (not (eq (cadr (vlax-invoke tab 'GetAttachmentPoint lig col))(cadr (vlax-invoke tab 'GetAttachmentPoint (1- lig) col))))
        (setq fus T)
      )
      (or (eq (vla-ismergedcell tab lig col 0 0 0 0) :vlax-false)
   (eq col 0)
   (eq (vla-ismergedcell tab lig (1- col) 0 0 0 0) :vlax-false)
   (not (eq (car (vlax-invoke tab 'GetAttachmentPoint lig col))(car (vlax-invoke tab 'GetAttachmentPoint lig (1- col)))))
        (setq fus T)
      )
      (or fus
   (eq (vla-gettext tab lig col) "")
(setq id (cons (list lig col (car lst)) id)
       lst (cdr lst)
)
      )
      (setq col (1+ col) fus nil)
    )
    (setq lig (1+ lig))
  )
  (reverse id)
)


Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Finding Entity from ObjectID
« Reply #5 on: June 22, 2011, 02:34:09 PM »
I'm still not sure why I'm not able to put in a 13 digit number into the function as a LONG and it not work.

Because as I just explained, you are using atoi which will convert it to a 32-bit signed integer which can only hold 10 digits (2,147,483,647)

VVA

  • Newt
  • Posts: 166
Re: Finding Entity from ObjectID
« Reply #6 on: June 22, 2011, 02:44:51 PM »
Why instead of (atoi PlineObjId) not to use (read PlineObjId)?


PS Found Change Field Object in Mtext
« Last Edit: June 22, 2011, 02:57:01 PM by VVA »

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Finding Entity from ObjectID
« Reply #7 on: June 22, 2011, 02:50:04 PM »
Why instead of (atoi PlineObjId) not to use (read PlineObjId)?
Прослушать

Nice idea VVA.

Rabbit

  • Guest
Re: Finding Entity from ObjectID
« Reply #8 on: June 22, 2011, 03:13:32 PM »

Why instead of (atoi PlineObjId) not to use (read PlineObjId)?
[/quote]

Nice idea VVA.
[/quote]

Not working. I keep getting an error message "lisp has no coercion to VARIANT with this (I can't read the rest because the error box cut it off)"

How can I just take a 13 digit string and change it to a LONG data-type.  Is it a variant?  Do I use (vlax-make-variant PlineObjId vlax-vbLong) somehow?  I'm lost here.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Finding Entity from ObjectID
« Reply #9 on: June 22, 2011, 03:27:39 PM »
Hi,

AutoLISP do not know longs (only 32 bits integer between -2147483648 and 2147483648).
IMO there's no way to use the ObjectIdToObject32 with LISP but this can be done with other languages/environments which deal with the AutoCAD Automation API (as VB(A), .NET or objectARX).
« Last Edit: June 22, 2011, 03:35:56 PM by gile »
Speaking English as a French Frog

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Finding Entity from ObjectID
« Reply #10 on: June 22, 2011, 03:32:07 PM »
IMO there's no way to use the ObjectIdToObject32 with LISP but this can be done with other languages/environments which deals with COM/ActiveX (as VB(A), .NET or objectARX).

I can only think of perhaps:

Code: [Select]
(vla-objectidtoobject32 <doc> (vla-get-objectid32 <object>))
(vla-objectidtoobject32 <doc> (vla-getblocktablerecordid32 <object> <row> <column>))

But, since the first is pointless, the cases are limited I would think...
« Last Edit: June 22, 2011, 03:44:56 PM by Lee Mac »

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Finding Entity from ObjectID
« Reply #11 on: June 22, 2011, 03:37:46 PM »
Rabbit, why not use my earlier code to get the object directly without using the ObjectID?

Rabbit

  • Guest
Re: Finding Entity from ObjectID
« Reply #12 on: June 22, 2011, 03:57:27 PM »
Rabbit, why not use my earlier code to get the object directly without using the ObjectID?

(Field->Entity (vlax-vla-object->ename (car ent)))
It gave me a lwpolyline.  I got lucky somehow.  I couldn't get it work before.  I wasn't doing something right.
Now to see if I can use this to finish out my code.

I'll let ya' know if I get it to work

Thanks, Rabbit

SOFITO_SOFT

  • Guest
Re: Finding Entity from ObjectID
« Reply #13 on: June 23, 2011, 10:41:05 AM »
I'm still not sure why I'm not able to put in a 13 digit number into the function as a LONG and it not work.

Here's all my code.  The table has acell with a field with the area of a closed lwpolyline.

 
Hello ...
Can you post a table with a polyline for example?
  the subject is very interesting

Regards

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Finding Entity from ObjectID
« Reply #14 on: June 23, 2011, 10:52:35 AM »
Sofito,

To easily recreate the scenario, on a 64-bit machine, create an MText field referencing say, the area, of an LWPolyline. Then attempt to retrieve the LWPolyline object/entity from only the MText field.

Lee