Author Topic: Subtract Name from Entity  (Read 322 times)

0 Members and 1 Guest are viewing this topic.

MeasureUp

  • Bull Frog
  • Posts: 436
Subtract Name from Entity
« on: May 24, 2019, 02:44:34 AM »
I am trying to get info from entity. I notice that I will get error when the data is not a number. Here is what I mean:

Entity = Point
Code: [Select]
(setq EntName (car (entsel "Select a point: ")))
(setq EntData (entget EntName))
(setq Value (nth 1 (assoc 0 EntData)))

Here is what I get
If last line was (setq Value (nth 1 (assoc 0 EntData)))
; error: bad list: "POINT"

If last line was (setq Value (nth 1 (assoc 0 EntData)))
; error: bad list: "D1DE"

If last line was (setq Value (nth 1 (assoc 8 EntData)))
; error: bad list: "Hidden"

If last line was (setq Value (nth 1 (assoc 10 EntData)))
177.543

What the code should be?
Thank you in advance.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 986
  • Marco
Re: Subtract Name from Entity
« Reply #1 on: May 24, 2019, 04:40:16 AM »
Comando: (setq Value (cdr (assoc 0 EntData)))
"POINT"

BIGAL

  • Bull Frog
  • Posts: 258
  • 30 + years of using Autocad
Re: Subtract Name from Entity
« Reply #2 on: May 24, 2019, 08:27:01 PM »
A vl answer also

Code: [Select]
(setq obj (vlax-ename->vla-object (car (entsel "pick object"))))
(setq name (vla-get-name obj))
A man who never made a mistake never made anything

Lee Mac

  • Seagull
  • Posts: 12214
  • London, England
Re: Subtract Name from Entity
« Reply #3 on: May 25, 2019, 11:46:51 AM »
The reason that you receive an error when using nth is because when two atoms are cons'd, the result is a dotted pair as opposed to a linked list. As such, when a dotted pair is supplied to the nth function, since the decrement register contains a pointer to an atom rather than a pointer to the tail of the list, the nth function will error; whereas, the cdr function will successfully return either an atom (for the case of a dotted pair), or the tail of the list (for the case of a singly linked list).

Observe the following -
Code - Auto/Visual Lisp: [Select]
  1. _$ (setq x (list 1 2)) ;; Singly linked list
  2. (1 2)
  3. _$ (car x) ;; Contents of the address register returns atom
  4. 1
  5. _$ (cdr x) ;; Contents of the decrement register returns tail of list
  6. (2)
  7. _$ (nth 0 x) ;; nth traverses the linked list a number of times equal to the index
  8. 1
  9. _$ (nth 1 x)
  10. 2
Code - Auto/Visual Lisp: [Select]
  1. _$ (setq y (cons 1 2)) ;; Dotted pair
  2. (1 . 2)
  3. _$ (car y) ;; Contents of the address register returns atom
  4. 1
  5. _$ (cdr y) ;; Contents of the decrement register returns atom
  6. 2
  7. _$ (nth 0 y) ;; nth traverses the linked list a number of times equal to the index
  8. 1
  9. _$ (nth 1 y) ;; nth cannot traverse the list since the decrement register contains an atom --> error
  10. ; error: bad list: 2
« Last Edit: May 25, 2019, 11:51:19 AM by Lee Mac »

MeasureUp

  • Bull Frog
  • Posts: 436
Re: Subtract Name from Entity
« Reply #4 on: May 26, 2019, 09:44:55 PM »
Thanks to Lee for your informative explanation. And thanks to all other's replies.

Another one.
Use the example (point) again.
Quote
((-1 . <Entity name: 7ff6cca13850>) (0 . "POINT") (330 . <Entity name: 7ff6cca0c1e0>) (5 . "D1DE") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "Hidden") (100 . "AcDbPoint") (10 177.543 210.206 5.0) (210 0.0 0.0 1.0) (50 . 0.0))

(cdr (assoc 100 EntData)) always returns "AcDbEntity".
How to get the second one "AcDbPoint"?

gile

  • Water Moccasin
  • Posts: 2211
  • Marseille, France
Re: Subtract Name from Entity
« Reply #5 on: May 27, 2019, 03:28:13 AM »
Hi

The 100 DXF code group is used for the sub class names reflecting the class inheritance (e.g. AcDbPoint is derived from AcDbentity).
The DXF list displays the properties according to the this inheritance: from the start of the list to the first 100 group are the properties common to every database object, then the properties which are common to the base class (e.g. AcDbEntity, AcDbSymbolTableRecord) until the effective class group of the object (AcDbPoint, AcDbLayerTableRecord) and finally the properties which are specific to this type.
You have to keep in mind an entity may have more than one base class (AcDbAttributereference inherits from AcDbText which inherits from AcDbEntity), so the safer way to get the effective class name of an object is to get the last 100 group value:
Code - Auto/Visual Lisp: [Select]
  1. (cdr (assoc 100 (reverse EntData)))
Speaking English as a French Frog

MeasureUp

  • Bull Frog
  • Posts: 436
Re: Subtract Name from Entity
« Reply #6 on: May 27, 2019, 07:41:28 PM »
Thanks. You help by using "reverse" and explain the 100 group. It is very informative. Thank you again.  :-D

Lee Mac

  • Seagull
  • Posts: 12214
  • London, England
Re: Subtract Name from Entity
« Reply #7 on: May 28, 2019, 08:08:56 AM »
Good explanation Gile  :-)

gile

  • Water Moccasin
  • Posts: 2211
  • Marseille, France
Re: Subtract Name from Entity
« Reply #8 on: May 28, 2019, 09:00:25 AM »
May be like this it is more clear:
Inheritance of an AcDbAttribute:
Code - Text: [Select]
  1. AcRxObject
  2.    AcGiDrawable
  3.    AcHeapOperators
  4.        AcDbObject
  5.            AcDbEntity
  6.                AcDbText
  7.                    AcDbAttribute

DXF data list of an AcDbAttribute instance
Code - Text: [Select]
  1. (
  2. (-1 . <Entity name: 7ffffb065c0>) ; AcDbObject property
  3.  (0 . "ATTRIB") ; AcDbObject property
  4.  (330 . <Entity name: 7ffffb06580>) ; AcDbObject property
  5.  (5 . "33C") ; AcDbObject property
  6.  (100 . "AcDbEntity")
  7.  (67 . 0) ; AcDbEntity property
  8.  (410 . "Model") ; AcDbEntity property
  9.  (8 . "7") ; AcDbEntity property
  10.  (100 . "AcDbText")
  11.  (10 125.211 37.8495 0.0) ; AcDbText property
  12.  (40 . 2.5) ; AcDbText property
  13.  (1 . "Some value") ; AcDbText property
  14.  (50 . 0.0) ; AcDbText property
  15.  (41 . 1.0) ; AcDbText property
  16.  (51 . 0.0) ; AcDbText property
  17.  (7 . "Standard") ; AcDbText property
  18.  (71 . 0) ; AcDbText property
  19.  (72 . 0) ; AcDbText property
  20.  (11 0.0 0.0 0.0) ; AcDbText property
  21.  (210 0.0 0.0 1.0) ; AcDbText property
  22.  (100 . "AcDbAttribute")
  23.  (280 . 0) ; AcDbAttribute property
  24.  (2 . "FOO") ; AcDbAttribute property
  25.  (70 . 0) ; AcDbAttribute property
  26.  (73 . 0) ; AcDbAttribute property
  27.  (74 . 0) ; AcDbAttribute property
  28.  (280 . 1) ; AcDbAttribute property
  29. )
Speaking English as a French Frog

MeasureUp

  • Bull Frog
  • Posts: 436
Re: Subtract Name from Entity
« Reply #9 on: June 03, 2019, 08:27:44 PM »
Much appreciated for your explanation.
Cheers!