Jump to content

How to get Attribute information for multiple blocks


JJtre
 Share

Recommended Posts

I have been working on a lisp program that will change one or multiple attributes on one or more blocks. I would however like to be able to add the current attribute values to the .dcl program, however I cannot manage to get attribute values for more than one block at a time. For example if you had two identical blocks with two separate attribute values (values not tags) and you pick both at the same time, when you open your properties window it will list the identical values (if any) and list the different values as "varies". Is there any way I can get this exact thing in autolisp? I am using vanilla lisp not visual, any help would be appreciated.

Link to comment
Share on other sites

Thanks for the reply but these links work for only one block at a time (or they are visual lisp). I was kind of hoping for a way to get attribute values for several identical blocks at one time. This would allow me to tell the user if there already is a value and if there is different values for the same attribute. However I can get it to work but it ends up being about a hundred lines of text. thanks anyway

Link to comment
Share on other sites

I never knew about that command, very cool, but i don't think i can fit that into my program. I was kind of hoping for it to run internally and display it using DCL coding. ACAD already displays the info I want inside the properties window under attributes when the blocks are selected, I just need some way to pull that info out. Is there any way to get lisp to put all of the properties of selected objects into a list or string exactly the same a ACAD displays it?

Link to comment
Share on other sites

I am using the following routine which made by Mr Tharwat .

 

;;; This program is working almost as well as the Autocad command attout
;;; so I did this program to help people who do not have the Express tools
;;; to use my Autolisp Program instead.
;;; Hope this would help people as much as it is possible.
;;; Author *** THARWAT AL SHOUFI ***
;;; Date of creating the program November 17th. 2010
;;; Tested with Autocad 2010
(defun c:THattout (/ Att fNme ents e)
 ; THARWAT Nov. 17.2010
 (prompt "\n Select Attributed Block: ")
 (if
    (setq Att (ssget "_+.:S:L" '((0 . "INSERT")(66 . 1))))
   (progn
     (setq fNme
        (open "D://attributes.txt" "w"))
      (setq ents (ssname Att 0))
       (write-line
        (strcat "HANDLE" "\t" "BLOCKNAME" "\t" "\n"
       (strcat "'" (cdr (assoc 5 (entget ents))))
            "\t"
              (cdr (assoc 2 (entget ents)))
                "\t")
        fNme
        )
     (write-line
        (strcat "\n" "TAG" "\t" "VALUE")
        fNme
        )
     (while
   (not
     (eq
       "SEQEND"
           (cdr (assoc 0
                 (setq e (entget (setq ents (entnext ents)))))
            )
       )
     )
            (write-line
             (strcat (cdr (assoc 2 e))
               "\t"
                  (cdr (assoc 1 e)))
         fNme
         )
     )
     (close fNme)
   )
 (princ "\n No Attributed Block Selected")
   )
 (princ "\nWritten by Tharwat Al Shoufi")
 (princ)
)

 

Good luck.

 

Michaels

Link to comment
Share on other sites

Thanks for the help,that last one was close, but I am starting to assume that my original assumption was correct and that there is no way for vanilla lisp to display and compare attribute values from multiple blocks. Thanks for all the help, if I find anything I will defiantly post it back here.:(

Link to comment
Share on other sites

Thanks for the help,that last one was close, but I am starting to assume that my original assumption was correct and that there is no way for vanilla lisp to display and compare attribute values from multiple blocks. Thanks for all the help, if I find anything I will defiantly post it back here.:(

 

Of course there is - you just have to give it more thought. The link I posted provides attribute subfunctions for a single block, but the methods utilised are applicable to any number of blocks, you just have to structure the code differently.

Link to comment
Share on other sites

Of course there is - you just have to give it more thought. The link I posted provides attribute subfunctions for a single block, but the methods utilised are applicable to any number of blocks, you just have to structure the code differently.

 

OK I'll give another shot, but I have one question what does this mean/do

"_+.:E:S" ? I have never seen this until I started on this task. Thanks Lee Mac for the confidence boost.

Link to comment
Share on other sites

what does this mean/do "_+.:E:S" ?

 

That is a combination of ssget mode strings, a couple of which are undocumented:

 

_  = allow for language compatibility
+. = force point selection (similar to PICKAUTO=0)
:E = select everything in the cursor aperture
:S = forces single entity selection

 

With regards to your task, are you looking to retrieve the values for a specific tag for all blocks in a selection? Or all values for all tags? Either could be achieved, you just need to think about how you want to structure your list output.

 

Lee

Link to comment
Share on other sites

An example of retrieving multiple values, uses the same methods as demonstrated by my earlier link.

 

A list is constructed and printed to the command line following selection, the list takes the form:

 

((<tag1> <value1> ... <valueN>) (<tag2> <value1> ... <valueN>) ... (<tagN> <value1> ... <valueN>))

(defun c:test ( / _assoc++ ss )
 ;; Example by Lee Mac 2010 www.lee-mac.com

 (defun _assoc++ ( key value lst )
   (
     (lambda ( pair )
       (if pair
         (subst (cons key (cons value (cdr pair))) pair lst)
         (cons  (list key value) lst)
       )
     )
     (assoc key lst)
   )
 )

 (if (setq ss (ssget '((0 . "INSERT") (66 . 1))))
   (
     (lambda ( i / e el l )
       (while (setq e (ssname ss (setq i (1+ i))))
         (while
           (not
             (eq "SEQEND"
               (cdr
                 (assoc 0
                   (setq el
                     (entget
                       (setq e (entnext e))
                     )
                   )
                 )
               )
             )
           )
           (setq l (_assoc++ (cdr (assoc 2 el)) (cdr (assoc 1 el)) l))
         )
       )
       (print l)
     )
     -1
   )
 )

 (princ)
)

Link to comment
Share on other sites

Thanks, this is almost exactly what I was looking for. Thanks for your help Lee Mac.

 

You're welcome JJtre - I'm sure you can manipulate it to suit your needs.

 

Next time, don't give up so easy :P

Link to comment
Share on other sites

  • 4 years later...
An example of retrieving multiple values, uses the same methods as demonstrated by my earlier link.

 

A list is constructed and printed to the command line following selection, the list takes the form:

 

((<tag1> <value1> ... <valueN>) (<tag2> <value1> ... <valueN>) ... (<tagN> <value1> ... <valueN>))

(defun c:test ( / _assoc++ ss )
 ;; Example by Lee Mac 2010 www.lee-mac.com

 (defun _assoc++ ( key value lst )
   (
     (lambda ( pair )
       (if pair
         (subst (cons key (cons value (cdr pair))) pair lst)
         (cons  (list key value) lst)
       )
     )
     (assoc key lst)
   )
 )

 (if (setq ss (ssget '((0 . "INSERT") (66 . 1))))
   (
     (lambda ( i / e el l )
       (while (setq e (ssname ss (setq i (1+ i))))
         (while
           (not
             (eq "SEQEND"
               (cdr
                 (assoc 0
                   (setq el
                     (entget
                       (setq e (entnext e))
                     )
                   )
                 )
               )
             )
           )
           (setq l (_assoc++ (cdr (assoc 2 el)) (cdr (assoc 1 el)) l))
         )
       )
       (print l)
     )
     -1
   )
 )

 (princ)
)

 

Hi,

 

this code is useful for me too but i want to list the values to a text file with this arrangement:

 

Capture.JPG

 

DN200-VA-002

DN200-VA-003

 

i've a schematic dwg file and i want to list the valves, stainers etc.

 

valve attr. block name:

Valve Label_block

in the block it has two titles:

#(TargetObject.Size)

#(TargetObject.Tag)

 

Could you help me please ?

Edited by sanalmakina
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...