suetolog Posted September 25, 2023 Posted September 25, 2023 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. Quote
BIGAL Posted September 25, 2023 Posted September 25, 2023 Post a dwg with block, where are the values coming from, what happens if more values than empty attributes ? Quote
Steven P Posted September 26, 2023 Posted September 26, 2023 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 1 Quote
suetolog Posted September 26, 2023 Author Posted September 26, 2023 (edited) 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 September 26, 2023 by suetolog 1 Quote
Steven P Posted September 26, 2023 Posted September 26, 2023 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 ) 1 Quote
Recommended Posts
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.