Author Topic: retrieving attribute values  (Read 5771 times)

0 Members and 1 Guest are viewing this topic.

Ashtray77

  • Guest
retrieving attribute values
« on: November 28, 2005, 10:13:20 AM »
I'm trying to get multiple attribute values from a titleblock and put them together and print them on the screen.  I'm having problems retrieving them from the title block.  I've looked a little bit through the forums and on www.smadsen.com, but I'm still confused.  this is what I have so far.  Please Help!!

(DEFUN QUICKJOBNAME ()
   (setq jobtextpoint (list (24 -15)))                              ;determines placement of text
   (getprojno)                                                            ;invokes getprojno
   (getpnlno)                                                  ;invokes getpnlno
   (Setq jobtext (strcat projno "-" pnlno))                      ;adds the 2 strings together
   (command "text" jobtextpoint jobtext "")                   ;puts text on screen
)
   
;;; HERE'S WHERE IM REALLY CONFUSED

(defun getprojno ()
   (setq projent (handent "3a99"))                      ;handle?
   (setq projentlist (entget projent))                    ;?
   (setq projno (cdr (assoc 1 projent)))      ;?
)

(defun getpnlno ()
   (setq pnlent (handent "3a9c"))                       ;handle?
   (setq pnlentlist (entget pnlent))                      ;?
   (setq pnlno (cdr (assoc 1 pnlent)))    ;?
)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: retrieving attribute values
« Reply #1 on: November 28, 2005, 10:19:10 AM »
I'd start >> here << as it's a very common topic.

For example, this.

PS: Welcome to the swamp.

:)
« Last Edit: November 28, 2005, 10:23:29 AM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: retrieving attribute values
« Reply #2 on: November 28, 2005, 10:34:57 AM »
Welcome to theswamp Ashtray!

Please let us know if you get confused with retrieving the attributes.
TheSwamp.org  (serving the CAD community since 2003)

Ashtray77

  • Guest
Re: retrieving attribute values
« Reply #3 on: November 28, 2005, 12:26:46 PM »
Thank you both for the warm welcome!

I think I'm confused even more now.  I've looked at those links for over an hour now and I still dont get it.   Its like reading chinese.  I'm such a novice at this stuff. (which is why I registered here) :mrgreen:

Im trying to get the value of the tag named "P.D.#" out of the block named "TITLEBLOCKTEXT" without having to select the block.  I should be able to select the block with SSGET, but beyond that, I'm clueless.  I noticed a bunch of commands starting with "vla".  I've never even seen those before, let alone understand how to use them.  Really I would think that this wouldnt be that hard.  maybe 5 lines max? 

line 1. find block using a selection set with a known value: in my case TITLEBLOCKTEXT   ---> ssget function
line 2. find tag using a known tag value:  in my case P.D.#  --->  DUNNO WHAT TO DO
line 3. extract value from previously found tag  ---->  DUNNO WHAT TO DO
line 4. maybe convert value to a string if needed

My brain hurts. 

I appreciate all of your help, 
Aaron


     


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: retrieving attribute values
« Reply #4 on: November 28, 2005, 12:55:29 PM »
Perhaps this post (and discussion) will help, it starts easy and goes into a little detail.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: retrieving attribute values
« Reply #5 on: November 28, 2005, 12:57:25 PM »
First we get the block using ssget and create 'obj' so it will work with my example code. MST-attribute_list
Code: [Select]
(if (setq ss (ssget "_x" '((0 . "INSERT") (2 . "TITLEBLOCKTEXT"))))
  (setq obj (vlax-ename->vla-object (ssname ss 0))) ; assuming only one block exists
  )

Output should look something like this
#<VLA-OBJECT IAcadBlockReference2 08ca00b4>

Next we'll run 'obj' through MST-attribute_list and see what we get.
Code: [Select]
(defun MST-attribute_list (Obj / attribs attrib-list attribute-list)
  (vl-load-com)

 (if (= (type Obj) 'VLA-OBJECT)
   (if (= (vlax-get-property Obj 'ObjectName) "AcDbBlockReference")
     (if (= (vlax-get-property Obj 'HasAttributes) :vlax-true)
       (progn
         (setq attribs
               (vla-GetAttributes Obj)
               attrib-list
               (vlax-safearray->list (vlax-variant-value attribs))
               ); setq

         (foreach X attrib-list
                  (setq attribute-list
                        (append
                          (list
                            (cons
                              (vlax-get-property X 'TagString)
                              (vlax-get-property X 'TextString)
                              )
                            )
                          attribute-list)
                        )
                  ); foreach
         ); progn
       )
     )
   )
 attribute-list
 )

Code: [Select]
(setq att_vals (MST-ATTRIBUTE_LIST obj))
Might return something like this.

(("P.D.#" . "152") ("NAME" . "Mark"))

Help?

TheSwamp.org  (serving the CAD community since 2003)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: retrieving attribute values
« Reply #6 on: November 28, 2005, 01:18:53 PM »
Aron,
Welcome to the swamp..

Here is another version?

Code: [Select]
(defun get_pd (/ ss titleblock attributes att pd)
  (setq ss (ssget "_X" '((0 . "INSERT") (66 . 1) (2 . "TITLEBLOCKTEXT"))))
  (if ss
    (progn
      (setq titleblock (vlax-ename->vla-object (ssname ss 0)))
      (setq attributes (vlax-invoke titleblock 'getattributes))


      (foreach att attributes
        (if (= "P.D.#" (vla-get-tagstring att))
          (progn
            (setq pd (vla-get-textstring att))
          )
        )
      )
    )
  )
  pd
)


(defun c:test (/ tmp)
  (if (setq tmp (get_pd))
    (alert (strcat "Value found [ " tmp " ]"))
  )
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: retrieving attribute values
« Reply #7 on: November 28, 2005, 01:24:24 PM »
OK, here is a better one.
Code: [Select]
(defun get_pd (/ ss titleblock attributes att pd)
  (setq ss (ssget "_X" '((0 . "INSERT") (66 . 1) (2 . "TITLEBLOCKTEXT"))))
  (if (and ss
           (setq titleblock (vlax-ename->vla-object (ssname ss 0)))
           (setq attributes (vlax-invoke titleblock 'getattributes))
      )
    (foreach att attributes
      (if (= "P.D.#" (vla-get-tagstring att))
        (setq pd (vla-get-textstring att))
      )
    )
  )
  pd
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: retrieving attribute values
« Reply #8 on: November 28, 2005, 02:07:11 PM »
Here are some good examples too.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: retrieving attribute values
« Reply #9 on: November 28, 2005, 02:10:45 PM »
OK after reading from that link I added some more error checking. :-)
Code: [Select]
(defun get_pd (/ ss titleblock attributes att pd)
  (setq ss (ssget "_X" '((0 . "INSERT") (66 . 1) (2 . "TITLEBLOCKTEXT"))))
  (if (and ss
           (setq titleblock (vlax-ename->vla-object (ssname ss 0)))
           (= (vla-get-objectname titleblock) "AcDbBlockReference")
           (= (vla-get-hasattributes titleblock) :vlax-true)           
           (setq attributes (vlax-invoke titleblock 'getattributes))
      )
    (foreach att attributes
      (if (= "P.D.#" (vla-get-tagstring att))
        (setq pd (vla-get-textstring att))
      )
    )
  )
  pd
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Ashtray77

  • Guest
Re: retrieving attribute values
« Reply #10 on: November 28, 2005, 02:14:45 PM »
Thanks for all of your replies.  I think I should be able to figure something out from this!  8-)

Looks like I might have to buy a new Lisp book, as mine is for AutoCad R14.  :lmao: - It doesnt have any of the vla functions in it.

Cheers,

Aaron

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: retrieving attribute values
« Reply #11 on: November 28, 2005, 02:31:26 PM »
It doesnt have any of the vla functions in it.
Try this ebook It is one of the best I've seen.

And welcome to theSwamp!

Ashtray77

  • Guest
Re: retrieving attribute values
« Reply #12 on: November 28, 2005, 03:13:51 PM »
Cool, I'll give it a look, thanks!

Andrea

  • Water Moccasin
  • Posts: 2372
Re: retrieving attribute values
« Reply #13 on: November 30, 2005, 07:46:19 PM »
Hi Ashtray77 and welcome..

I'm not good like some other here...but i've made this...maybe can help you. :kewl:

Code: [Select]
(defun c:getbat ()
(setq bname (getstring "Enter your block name : "))
  (if (tblsearch "BLOCK" bname) (getdata)
    (alert (strcat "No block named " bname " was detected on this drawing."))
  );;if
)
(defun getdata () 
(setq edata (entget (ssname (ssget "X" (list (cons 0 "INSERT") (cons 2 bname))) 0)))
(if edata
  (progn
    (setq x T)
    (setq edata (entget (entnext (dxf -1 edata))))
  (while x
(setq eb1 (dxf 1 edata));; = Attribute Value
        (setq eb2 (dxf 2 edata));; = Attribute TAG
        (alert (strcat "Tag = " eb2 "\nValue = " eb1))
        (setq edata (entget (entnext (dxf -1 edata))))
        (if (eq (dxf 0 edata) "SEQEND") (setq x nil))
    );;while
 );;progn
);;if
  (princ)
)
(defun dxf (code elist)
(cdr (assoc code elist))
);defun
Code: [Select]
Keep smile...

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: retrieving attribute values
« Reply #14 on: November 30, 2005, 08:51:07 PM »
Andrea , the logic is flawed.

the conditional you use is " Does the block exist in the Block Table"
If this is true you assume the block has been inserted in the drawing.

This is not necessarily correct.

You should also be testing the return value from the SSGET function, if NIL then nothing has been selected.

Also .. you blindly assume the block has attributes. This may not be the case.

.. I wont touch on the issue of only extracting the first object in the selection set, irrespective of the instance the user may be interested in querying.

Please note I am not picking on you personally.
There are certain logic rules to follow when writing computer programs, you've just missed a few here.



kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.