Jump to content

Filling empty attributes


suetolog

Recommended Posts

Hi all, need some help. What is the method to search and fill empty attributes in a certain block. Fill the first empty attribute with one value and then go to the next empty attribute and fill it with the second value, etc.

Link to comment
Share on other sites

What are your skills with LISP like? I often ask this to anyone with a few posts - and knowing this we can give a better answer. For example, do you just need a quick hint or a link and you can work out the rest or anything between to needing the full solution, the forums can generally help whichever way.

 

I'll post a link, see http://www.lee-mac.com/attributefunctions.html who details how to read attributes, get a list of attributes and set attributes, I think the basis of a LISP is all in there.

 

If I get chance later today I'll put them all together for you

  • Thanks 1
Link to comment
Share on other sites

Thanks for the reply, I will look into it. The problem is that, I need to give the code only the name of the block, so that it will find the first empty attribute and start filling the information initially given to it. I apologize for my English. My level is beginner(AutoLisp).

Edited by suetolog
  • Like 1
Link to comment
Share on other sites

Try this. It will ask you to select the blocks on the screen and will fill the empty or blank attributes with  numbers - this can be changed.

 

Post a sample drawing, this LISP can be modified further but that basic of what you want are here

 

(defun c:test ( / MySS acounter acount MyObj BlkAtts n)
  (defun LM:vl-getattributevalues ( blk ) ;;blk is object ;; refer to Lee Macs website
    (mapcar '(lambda ( att ) (cons (vla-get-tagstring att) (vla-get-textstring att))) (vlax-invoke blk 'getattributes))
  )

  (defun LM:vl-setattributevalue ( blk tag val )         ;;refer to Lee Macs website
    (setq tag (strcase tag))
    (vl-some
       '(lambda ( att )
            (if (= tag (strcase (vla-get-tagstring att)))
                (progn (vla-put-textstring att val) val)
            )
        )
        (vlax-invoke blk 'getattributes)
    )
  )
  (setq MySS (ssget '((0 . "INSERT"))))                 ;;Select only blocks
;;  (setq MySS (ssget '((0 . "INSERT")(2 . blkname))))    ;;Select only named blocks if block name supplied
  (setq acounter 0)                                     ;; A counter for looping through the selection set
  (while (< acounter (sslength MySS))                   ;; Start loop through selected blocks
    (setq MyObj (vlax-ename->vla-object (ssname MySS acounter)))  ;; Get the block object
    (setq BlkAtts (LM:vl-getattributevalues MyObj))     ;; use Lee Mac lisp above to list attributes and values
    (setq acount 0)                                     ;; A count for each empty attribute
    (foreach n BlkAtts                                  ;; Loop through the block atributes
      (if (= (cdr n) "")                                ;; If block attribute is empty
        (LM:vl-setattributevalue MyObj (car n) (rtos acount)) ;; set it to a value
      ) ; end if
      (setq acount (+ acount 1))                        ;;increment the value to attribute
    ) ; end foreach

    (setq acounter (+ acounter 1))                      ;; increment the selection set counter
  ) ; end while
)

 

  • Thanks 1
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...