omer111 Posted May 2, 2023 Posted May 2, 2023 I am tryin to alter more than a few dozens in a lisp code, I need all of the to change the value of a single attribute into a specific value (defun c:SETATT (/ blkname ss atts attval) (setq blkname "0-TTL_A0-NTI") (setq ss (ssget "_X" (list (cons 0 "INSERT") (cons 2 blkname)))) (setq i 0) (while (< i (sslength ss)) (setentprop ss i "LAST_REVISION" 01) (setq i (1+ i)) ) ) (princ) ) that is the name of the block as inserted, I need the code to set the "LAST_REVISION" attribute into be 01, int or string for now it doesn't matter. later on I will need a code that increments the number by 1, but I will work on that later. so I know that function "setentprop" doesn't exist, which is basically my problem, I need either a similar function, or a way to define setentprop into basically setting the properties of an entity like proposed in the code any help would be appreciated Quote
BIGAL Posted May 2, 2023 Posted May 2, 2023 This may be a useful starting point. You need block name and attribute tagname. ; simple update 1 attribute across all layouts ; By Alan H Nov 2020 (defun c:1rev ( / len lay plotabs newstr tabname oldtagn ss1 att x y) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (setq tabs (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object)))) (setq y 0) (setq ent (nentsel "\nPick an attribute ")) (setq ent2 (ssname (ssget (cadr ent)) 0)) (setq bname (cdr (assoc 2 (entget ent2)))) (setq oldtagn (cdr (assoc 2 (entget (car ent))))) (SETQ NEWSTR (getstring "\nEnter new string ")) (repeat (vla-get-count tabs) (vlax-for lay tabs (setq x (vla-get-taborder lay)) (setq tabname (vla-get-name lay)) (if (and (= y x) (/= tabname "Model")) (progn (setvar "ctab" tabname) (if (setq ss1 (ssget "x" (list (cons 0 "INSERT") (cons 2 bname)(cons 410 tabname)))) (foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 0 )) 'getattributes) (if (= oldtagn (strcase (vla-get-tagstring att))) (vla-put-textstring att newstr) ) ) ) ) ) ) (setq y (+ y 1)) ) ) (c:1rev) 2 Quote
omer111 Posted May 3, 2023 Author Posted May 3, 2023 thank you for your reply, this looks quite good, but I couldn't find where I write the block's name or attribute's tag, I need it to be embedded in the code so I wouldn't have to ask for user prompts Quote
BIGAL Posted May 3, 2023 Posted May 3, 2023 (edited) Ok pulling this apart with explanations (setq ent (nentsel "\nPick an attribute ")) ; using nentsel allows you to pick the attribute rather than a block (setq ent2 (ssname (ssget (cadr ent)) 0)) ; does a reselect and selects block based on attribute (setq bname (cdr (assoc 2 (entget ent2)))) ; gets block name (setq oldtagn (cdr (assoc 2 (entget (car ent))))) ; gets tag name of attribute selected So if you don't want any picking remove the 4 lines and hard code the blockname and tagname. Bname & oldtagn It is coded to look in layouts not model. Edited May 3, 2023 by BIGAL 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.