Jump to content

Recommended Posts

Posted

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

Posted

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)

 

  • Like 2
Posted

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

Posted (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 by BIGAL
  • Like 1

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...