Jump to content

Number and values ​​of block attributes in Autolisp.


Xyzzy

Recommended Posts

Hello, 

I need a function that determines the number and values of block attributes in Autolisp.

 

I have no idea how to write this, can you help me?

 

 

 

Link to comment
Share on other sites

In express tools their is a command attout select the blocks you want to export the attributes of. it wil create a txt file. just drag and drop that file in an open excel. it will have every attribute for you to edit/update. once done save the file and use command attin

Link to comment
Share on other sites

@mhupp I meant that I need to write a program, for example, to replace blocks with one name with blocks with a different name:

(defun c:proj4()
   (setq str (getstring "block' name:"))
   (setq zb (ssget "X" (list(cons 2 str))))
   (setq lzb (sslength zb))
   (setq nw (getstring "new block' name:"))
   (setq i 0)
   (while (< i lzb)
      (setq stri (ssname zb i))
      (setq dstri (entget stri))
      (setq dstri
         (subst (cons 2 nw)
         (assoc 2 dstri)
         dstri)
         )
      (entmod dstri)
      (setq i (1+ i))
   )
)

Link to comment
Share on other sites

@mhupp I meant that I need to write a program, for example, to replace blocks with one name with blocks with a different name:

 

(defun c:proj4

   (setq str (getstring "block' name:")

   (setq zb (ssget "X" (list(cons 2 str)))

   (setq lzb (sslength zb)

   (setq nw (getstring "new block' name:")

   (setq i 0

   (while (< i lzb

      (setq stri (ssname zb i)

      (setq dstri (entget stri)

      (setq dstr

         (subst (cons 2 nw

         (assoc 2 dstri

         dstri

         

      (entmod dstri

      (setq i (1+ i)

   

))))))))i))))))))()

Link to comment
Share on other sites

@mhupp

I need to write a script in Autolisp, which determines the number and values of block attributes in Autolisp. I think that it ,,enter the number of arguments" ,,enter the value of the attribute one" etc.

Link to comment
Share on other sites


@mhupp

So for now, I have this:

1. Count attributes(defun c:Test (/ s ss)
  (if (and (princ "\n Select FIRST Attributed Block :")
           (setq s (ssget "_+.:S:E" '((0 . "INSERT") (66 . 1))))
           (princ "\n Select the SECOND Attributed Block :")
           (setq ss (ssget "_+.:S:E" '((0 . "INSERT") (66 . 1))))
      )
    (mapcar
      'length
      (mapcar
        '(lambda (a)
           (mapcar
             '(lambda (x) (vla-get-textstring x))
             (vlax-invoke (vlax-ename->vla-object a) 'getattributes)
           )
         )
        (list (ssname s 0) (ssname ss 0))
      )
    )
  )
)

2. Retrieve values of attributes
(defun c:Test (/ ss n e x)
  (while (progn (princ "\n Select single attributed block :")
                (setq ss (ssget "_+.:S" '((0 . "INSERT") (66 . 1))))
         )
    (setq n (entnext (ssname ss 0)))
    (while (not (eq (cdr (assoc 0 (setq e (entget n)))) "SEQEND" ))
       (if (eq (cdr (assoc 0 e)) "ATTRIB")
         (print (cdr (assoc 1 e)))
       )
       (setq n (entnext n))
    )
  )
  (princ)
)

How can i combine them?

Edited by Xyzzy
Link to comment
Share on other sites

 

Different method but your on right path when you (vlax-invoke (vlax-ename->vla-object a) 'getattributes) it does just that in creation order. You can get each attribute and look at "Textstring" which is attribute value, you can also get how many attributes so if updating block 2 can control which attributes get updated.

 

So lets start again

 

(setq blk (vlax-ename->vla-object (car (entsel "\nPick block "))))

(setq atts (vlax-invoke blk 'getattributes))
(princ (strcat "how many " (rtos (length atts) 2 0) "\n"))
(setq lst '())
(foreach att atts
(princ (strcat "\n" (vla-get-textstring att)))
(setq lst (cons (vla-get-textstring att) lst))
)
(setq lst (reverse lst))

 

(setq blk2 (vlax-ename->vla-object (car (entsel "\nPick block2 "))))

(setq x 0)
(setq atts2 (vlax-invoke blk2 'getattributes))
(foreach att2 atts2
(vla-put-textstring att2 (nth x lst))
(setq x (1+ x))
)

No error checks does block 2 have same or more attributes, uses creation order. 

 

ps (vlax-property-available-p blk "hasattributes")

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

×
×
  • Create New...