could someone help with this lisp ... change attribute value by layout if specific value change

could someone help with this lisp ... change attribute value by layout if specific value change

mduvalAA6EJ
Enthusiast Enthusiast
566 Views
6 Replies
Message 1 of 7

could someone help with this lisp ... change attribute value by layout if specific value change

mduvalAA6EJ
Enthusiast
Enthusiast

hello 

with this function they are "main" variable value

if the main variable change

they are change on line 1.. 

...

the change was made for each line to line 14 but the this is the short version of the lisp function

 

just want to change variable dependant to layout 

 

for this example the lisp program consider layout 1 and 2

 

could someone could help please

 

thankyou very much

 

and i hope we win to the covid-19!

 

excuse my english

0 Likes
567 Views
6 Replies
Replies (6)
Message 2 of 7

mduvalAA6EJ
Enthusiast
Enthusiast

could i do something with that?

 

https://www.cadtutor.net/forum/topic/50360-move-layout-rename-layouts-goto-layout/

; go to any layout by its page number
; By Alan H Feb 2014

(defun C:goto ( / alllayouts lay x num)
(setq num (getint "\nEnter tab number"))
(setq alllayouts (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object))))
(SETQ LAYNUM 0)
(vlax-for x alllayouts
(Setq laynum (+ 1 laynum))
) ;total number of layouts
(if (> num laynum)
(setq num (- laynum 1))
)
(vlax-for lay alllayouts
(if (= num (vla-get-taborder lay))
(setvar "ctab" (vla-get-name lay))
) ; if
) ; for
) ; defun
(C:goto)

0 Likes
Message 3 of 7

mduvalAA6EJ
Enthusiast
Enthusiast

could someone can help

 

autocad return a arror non facultative parametre

 

;;; revision 2022-jan-18-b

;;; THEY ARE MULTIPLE POSSIBILITY OF REVISION IN A DRAWING OR PROJECT

;;; DRAWING MAY CONTAIN MULTIPLE INFINITE TABS(LAYOUT)
;;; BLOCK SSREVISION ARE REQUIRED AND COULD BE ON ANY LAYOUT
;;; THIS PROGRAM ATOMATICALY MAKE REVISION (ADD A LINE) IN THE BLOCK IF REVISION ARE MADE IN SHREV_# TAG
;;; THIS PROGRAM IS NOT COMPLETE AND HAVE BUG BUT ITS A IDEA TO DOING THE FUNCTION

(vl-load-com)

(defun :GetRevList (blkname / :BuildName :Layorder lays lst)

(defun :BuildName (att)
(setq att (strcase att))
(if (zerop (atoi att))
(strcat "" att)
(strcat "REV"
(substr att 1 (vl-string-search "_" att))
(cond ((wcmatch att "*NO*"
) "NO")
((wcmatch att "*DATE*") "DATE")
((wcmatch att "*MIS*") "EMIS")
((wcmatch att "*PAR*") "PAR")
(T "X")))))

; pbejse https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/layout-order/td-p/3749964
(defun :Layorder (/ order)
(vlax-for lay (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq order (cons (list (vla-get-name lay) (vla-get-taborder lay)) order)))
(mapcar 'car (cdr (vl-sort order '(lambda (j k) (< (cadr j) (cadr k)))))))

; ---------------------------------------------------------------------------------------------------
; main func
(foreach lay (setq lays (:Layorder))
(if (setq sel (ssget "_X" (list '(0 . "INSERT") (cons 2 blkname) (cons 410 lay))))
(foreach att (vlax-invoke (vlax-ename->vla-object (ssname sel 0)) 'GetAttributes)
setq lst (cons (cons (strcat (:BuildName (vla-get-TagString att)) (itoa (1+ (vl-position lay lays))))
(vla-get-TextString att))
lst)))))
(setq lst (reverse lst))


;; Set Attribute Value - Lee Mac
;; Sets the value of the first attribute with the given tag found within the block, if present.
;; blk - [vla] VLA Block Reference Object
;; tag - [str] Attribute TagString
;; val - [str] Attribute Value
;; Returns: [str] Attribute value if successful, else nil.

(defun LM:vl-setattributevalue ( blk tag val )

(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)
)
)


;;;; SETATTRIB

(defun setAttrib ( blkname att val / ss vla-obj)

;(setq lays (:Layorder))
(if(setq ss (ssget "X" (list (cons 2 blkname)(cons 0 "INSERT")(cons 410 (nth sheetlay (layoutlist))))))
(progn
(setq vla-obj (vlax-ename->vla-object (ssname ss 0)))
(if (not (LM:vl-setattributevalue vla-obj att val))
(prompt "\nAttribute not present")
)
)
(prompt "\nBlock not found")
)
(princ)
)

 

 

;;;testing variables....


(defun c:ReadExamples ( / lst)

(setq lst (:GetRevList "SSREVISION"))

(foreach e lst
(princ "\n") (princ e)) ; list all values (associated list)
;;;
;;; (princ "\n")
;;; (princ (cdr (assoc "REV3DATE1" lst))) ; princ value from associted list


;;; below - IMHO this is ridiculuos, associated list should serve the puPARose.

(foreach e lst
(set (read (car e)) (cdr e))) ;; set all variables from associated list

;;; (princ "\n")
;;; (princ (eval (read "REV3DATE1"))) ;; princ a value from variable
;;;
(princ)

)

 

(defun c:REC_REVUP ()

(c:ReadExamples)

;layout 1

(if

(/= SHREV_NO1 "%%")
(and
(setq sheetlay 1)
(setAttrib "SSREVISION" "SS_BAKNO" SHREV_NO1)
(setq SNO1 oui)
);end and
);end if

(if

(= SHREV_NO1 "%%")

(setq SNO1 non)
);end if

(if
(and
(/= SHREV_NO1 "%%")
(/= SHREV_BAKNO1 "%%")
(= REV1NO1 "%%")
);end and

(and
(setq sheetlay 1)
(setAttrib "SSREVISION" "1_NO" SHREV_NO1)
(setq R1NO1 oui)
);end and
);end if

(if
(and
(= SHREV_NO1 "%%")
(= SHREV_BAKNO1 "%%")
(/= REV1NO1 "%%")
);end and

(setq R1NO1 non)

);end if

 

;layout 2

(if

(/= SHREV_NO2 "%%")
(and
(setq sheetlay 2)
(setAttrib "SSREVISION" "SS_BAKNO" SHREV_NO2)
(setq SNO2 oui)
);end and
);end if

(if

(= SHREV_NO2 "%%")

(setq SNO2 non)
);end if

(if
(and
(/= SHREV_NO2 "%%")
(/= SHREV_BAKNO2 "%%")
(= REV1NO2 "%%")
);end and

(and
(setq sheetlay 2)
(setAttrib "SSREVISION" "1_NO" SHREV_NO2)
(setq R1NO2 oui)
);end and
);end if

(if
(and
(= SHREV_NO2 "%%")
(= SHREV_BAKNO2 "%%")
(/= REV1NO2 "%%")
);end and

(setq R1NO2 non)

);end if


(princ)

)

0 Likes
Message 4 of 7

mduvalAA6EJ
Enthusiast
Enthusiast

sorry i have correct the program now i can have list but autocad tel me "bad SSGET list value"

 

;;; revision 2022-jan-18-b

;;; THEY ARE MULTIPLE POSSIBILITY OF REVISION IN A DRAWING OR PROJECT

;;; DRAWING MAY CONTAIN MULTIPLE INFINITE TABS(LAYOUT)
;;; BLOCK SSREVISION ARE REQUIRED AND COULD BE ON ANY LAYOUT
;;; THIS PROGRAM ATOMATICALY MAKE REVISION (ADD A LINE) IN THE BLOCK IF REVISION ARE MADE IN SHREV_# TAG
;;; THIS PROGRAM IS NOT COMPLETE AND HAVE BUG BUT ITS A IDEA TO DOING THE FUNCTION

(vl-load-com)

(defun :GetRevList (blkname / :BuildName :Layorder lays lst)

(defun :BuildName (att)
(setq att (strcase att))
(if (zerop (atoi att))
(strcat "" att)
(strcat "REV"
(substr att 1 (vl-string-search "_" att))
(cond ((wcmatch att "*NO*"
) "NO")
((wcmatch att "*DATE*") "DATE")
((wcmatch att "*MIS*") "EMIS")
((wcmatch att "*PAR*") "PAR")
(T "X")))))

; pbejse https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/layout-order/td-p/3749964
(defun :Layorder (/ order)
(vlax-for lay (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq order (cons (list (vla-get-name lay) (vla-get-taborder lay)) order)))
(mapcar 'car (cdr (vl-sort order '(lambda (j k) (< (cadr j) (cadr k)))))))

; ---------------------------------------------------------------------------------------------------
; main func
(foreach lay (setq lays (:Layorder))
(if (setq sel (ssget "_X" (list '(0 . "INSERT") (cons 2 blkname) (cons 410 lay))))
(foreach att (vlax-invoke (vlax-ename->vla-object (ssname sel 0)) 'GetAttributes)
(setq lst (cons (cons (strcat (:BuildName (vla-get-TagString att)) (itoa (1+ (vl-position lay lays))))
(vla-get-TextString att))
lst)))))
(setq lst (reverse lst)))


;; Set Attribute Value - Lee Mac
;; Sets the value of the first attribute with the given tag found within the block, if present.
;; blk - [vla] VLA Block Reference Object
;; tag - [str] Attribute TagString
;; val - [str] Attribute Value
;; Returns: [str] Attribute value if successful, else nil.

(defun LM:vl-setattributevalue ( blk tag val )

(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)
)
)


;;;; SETATTRIB


(defun setAttrib ( blkname att val / ss vla-obj)


(setq sheetlayname (nth sheetlay (layoutlist)))
(if (setq ss (ssget "X" (list (cons 2 blkname)(cons 0 "INSERT")(cons 410 sheetlayname))))
(progn
(setq vla-obj (vlax-ename->vla-object (ssname ss 0)))
(if (not (LM:vl-setattributevalue vla-obj att val))
(prompt "\nAttribute not present")
)
)
(prompt "\nBlock not found")
)
(princ)
)

 

 


;;;testing variables....


(defun c:ReadExamples ( / lst)

(setq lst (:GetRevList "SSREVISION"))

(foreach e lst
(princ "\n") (princ e)) ; list all values (associated list)
;;;
;;; (princ "\n")
;;; (princ (cdr (assoc "REV3DATE1" lst))) ; princ value from associted list


;;; below - IMHO this is ridiculuos, associated list should serve the puPARose.

(foreach e lst
(set (read (car e)) (cdr e))) ;; set all variables from associated list

;;; (princ "\n")
;;; (princ (eval (read "REV3DATE1"))) ;; princ a value from variable
;;;
(princ)

)

 

(defun c:REC_REVUP ()

(c:ReadExamples)

;layout 1

(if

(/= SS_NO1 "%%")
(and
(setq sheetlay 1)
(setAttrib "SSREVISION" "SS_BAKNO" SS_NO1)
(setq SNO1 "oui")
);end and
);end if

(if

(= SS_NO1 "%%")

(setq SNO1 "non")
);end if

(if
(and
(/= SS_NO1 "%%")
(/= SS_BAKNO1 "%%")
(= REV1NO1 "%%")
);end and

(and
(setq sheetlay 1)
(setAttrib "SSREVISION" "1_NO" SS_NO1)
(setq R1NO1 "oui")
);end and
);end if

(if
(and
(= SS_NO1 "%%")
(= SS_BAKNO1 "%%")
(/= REV1NO1 "%%")
);end and

(setq R1NO1 "non")

);end if

 

;layout 2

(if

(/= SS_NO2 "%%")
(and
(setq sheetlay 2)
(setAttrib "SSREVISION" "SS_BAKNO" SS_NO2)
(setq SNO2 "oui")
);end and
);end if

(if

(= SS_NO2 "%%")

(setq SNO2 "non")
);end if

(if
(and
(/= SS_NO2 "%%")
(/= SS_BAKNO2 "%%")
(= REV1NO2 "%%")
);end and

(and
(setq sheetlay 2)
(setAttrib "SSREVISION" "1_NO" SS_NO2)
(setq R1NO2 "oui")
);end and
);end if

(if
(and
(= SS_NO2 "%%")
(= SS_BAKNO2 "%%")
(/= REV1NO2 "%%")
);end and

(setq R1NO2 "non")

);end if


(princ)

)

0 Likes
Message 5 of 7

mduvalAA6EJ
Enthusiast
Enthusiast

now i can run the program

 

but.. that not working to change variable for all layout

could help me ?

 

thanks

 

;;; revision 2022-jan-18-b

;;; THEY ARE MULTIPLE POSSIBILITY OF REVISION IN A DRAWING OR PROJECT

;;; DRAWING MAY CONTAIN MULTIPLE INFINITE TABS(LAYOUT)
;;; BLOCK SSREVISION ARE REQUIRED AND COULD BE ON ANY LAYOUT
;;; THIS PROGRAM ATOMATICALY MAKE REVISION (ADD A LINE) IN THE BLOCK IF REVISION ARE MADE IN SHREV_# TAG
;;; THIS PROGRAM IS NOT COMPLETE AND HAVE BUG BUT ITS A IDEA TO DOING THE FUNCTION

(vl-load-com)

(defun :GetRevList (blkname / :BuildName :Layorder lays lst)

(defun :BuildName (att)
(setq att (strcase att))
(if (zerop (atoi att))
(strcat "" att)
(strcat "REV"
(substr att 1 (vl-string-search "_" att))
(cond ((wcmatch att "*NO*"
) "NO")
((wcmatch att "*DATE*") "DATE")
((wcmatch att "*MIS*") "EMIS")
((wcmatch att "*PAR*") "PAR")
(T "X")))))

; pbejse https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/layout-order/td-p/3749964
(defun :Layorder (/ order)
(vlax-for lay (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq order (cons (list (vla-get-name lay) (vla-get-taborder lay)) order)))
(mapcar 'car (cdr (vl-sort order '(lambda (j k) (< (cadr j) (cadr k)))))))

; ---------------------------------------------------------------------------------------------------
; main func
(foreach lay (setq lays (:Layorder))
(if (setq sel (ssget "_X" (list '(0 . "INSERT") (cons 2 blkname) (cons 410 lay))))
(foreach att (vlax-invoke (vlax-ename->vla-object (ssname sel 0)) 'GetAttributes)
(setq lst (cons (cons (strcat (:BuildName (vla-get-TagString att)) (itoa (1+ (vl-position lay lays))))
(vla-get-TextString att))
lst)))))
(setq lst (reverse lst)))


;; Set Attribute Value - Lee Mac
;; Sets the value of the first attribute with the given tag found within the block, if present.
;; blk - [vla] VLA Block Reference Object
;; tag - [str] Attribute TagString
;; val - [str] Attribute Value
;; Returns: [str] Attribute value if successful, else nil.

(defun LM:vl-setattributevalue ( blk tag val )

(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)
)
)


;;;; SETATTRIB


(defun setAttrib ( blkname att val / ss vla-obj)


(setq sheetlayname (setvar 'ctab (nth sheetlay (layoutlist))))
(if (setq ss (ssget "X" (list (cons 2 blkname)(cons 0 "INSERT")(cons 410 sheetlayname))))
(progn
(setq vla-obj (vlax-ename->vla-object (ssname ss 0)))
(if (not (LM:vl-setattributevalue vla-obj att val))
(prompt "\nAttribute not present")
)
)
(prompt "\nBlock not found")
)
(princ)
)

 

 


;;;testing variables....


(defun c:ReadExamples ( / lst)

(setq lst (:GetRevList "SSREVISION"))

(foreach e lst
(princ "\n") (princ e)) ; list all values (associated list)
;;;
;;; (princ "\n")
;;; (princ (cdr (assoc "REV3DATE1" lst))) ; princ value from associted list


;;; below - IMHO this is ridiculuos, associated list should serve the puPARose.

(foreach e lst
(set (read (car e)) (cdr e))) ;; set all variables from associated list

;;; (princ "\n")
;;; (princ (eval (read "REV3DATE1"))) ;; princ a value from variable
;;;
(princ)

)

 

(defun c:REC_REVUP ()

(c:ReadExamples)

;layout 1

(if

(/= SS_NO1 "%%")
(and
(setq sheetlay 1)
(setAttrib "SSREVISION" "SS_BAKNO" SS_NO1)
(setq SNO1 "oui")
);end and
);end if

(if

(= SS_NO1 "%%")

(setq SNO1 "non")
);end if

(if
(and
(/= SS_NO1 "%%")
(/= SS_BAKNO1 "%%")
(= REV1NO1 "%%")
);end and

(and
(setq sheetlay 1)
(setAttrib "SSREVISION" "1_NO" SS_NO1)
(setq R1NO1 "oui")
);end and
);end if

(if
(and
(= SS_NO1 "%%")
(= SS_BAKNO1 "%%")
(/= REV1NO1 "%%")
);end and

(setq R1NO1 "non")

);end if

 

;layout 2

(if

(/= SS_NO2 "%%")
(and
(setq sheetlay 2)
(setAttrib "SSREVISION" "SS_BAKNO" SS_NO2)
(setq SNO2 "oui")
);end and
);end if

(if

(= SS_NO2 "%%")

(setq SNO2 "non")
);end if

(if
(and
(/= SS_NO2 "%%")
(/= SS_BAKNO2 "%%")
(= REV1NO2 "%%")
);end and

(and
(setq sheetlay 2)
(setAttrib "SSREVISION" "1_NO" SS_NO2)
(setq R1NO2 "oui")
);end and
);end if

(if
(and
(= SS_NO2 "%%")
(= SS_BAKNO2 "%%")
(/= REV1NO2 "%%")
);end and

(setq R1NO2 "non")

);end if


(princ)

)

0 Likes
Message 6 of 7

mduvalAA6EJ
Enthusiast
Enthusiast

now that working !!! 🙂 

 

;;; revision 2022-jan-18-b

;;; THEY ARE MULTIPLE POSSIBILITY OF REVISION IN A DRAWING OR PROJECT

;;; DRAWING MAY CONTAIN MULTIPLE INFINITE TABS(LAYOUT)
;;; BLOCK SSREVISION ARE REQUIRED AND COULD BE ON ANY LAYOUT
;;; THIS PROGRAM ATOMATICALY MAKE REVISION (ADD A LINE) IN THE BLOCK IF REVISION ARE MADE IN SHREV_# TAG
;;; THIS PROGRAM IS NOT COMPLETE AND HAVE BUG BUT ITS A IDEA TO DOING THE FUNCTION

(vl-load-com)

(defun :GetRevList (blkname / :BuildName :Layorder lays lst)

(defun :BuildName (att)
(setq att (strcase att))
(if (zerop (atoi att))
(strcat "" att)
(strcat "REV"
(substr att 1 (vl-string-search "_" att))
(cond ((wcmatch att "*NO*"
) "NO")
((wcmatch att "*DATE*") "DATE")
((wcmatch att "*MIS*") "EMIS")
((wcmatch att "*PAR*") "PAR")
(T "X")))))

; pbejse https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/layout-order/td-p/3749964
(defun :Layorder (/ order)
(vlax-for lay (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq order (cons (list (vla-get-name lay) (vla-get-taborder lay)) order)))
(mapcar 'car (cdr (vl-sort order '(lambda (j k) (< (cadr j) (cadr k)))))))

; ---------------------------------------------------------------------------------------------------
; main func
(foreach lay (setq lays (:Layorder))
(if (setq sel (ssget "_X" (list '(0 . "INSERT") (cons 2 blkname) (cons 410 lay))))
(foreach att (vlax-invoke (vlax-ename->vla-object (ssname sel 0)) 'GetAttributes)
(setq lst (cons (cons (strcat (:BuildName (vla-get-TagString att)) (itoa (1+ (vl-position lay lays))))
(vla-get-TextString att))
lst)))))
(setq lst (reverse lst)))


;; Set Attribute Value - Lee Mac
;; Sets the value of the first attribute with the given tag found within the block, if present.
;; blk - [vla] VLA Block Reference Object
;; tag - [str] Attribute TagString
;; val - [str] Attribute Value
;; Returns: [str] Attribute value if successful, else nil.

(defun LM:vl-setattributevalue ( blk tag val )

(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)
)
)


;;;; SETATTRIB


(defun setAttrib (blkname att val / ss vla-obj sheetlayname)

(setq sheetlay (- sheetlay 1))
(setq sheetname (setvar 'ctab (nth sheetlay (layoutlist))))
(if (setq ss (ssget "X" (list (cons 2 blkname)(cons 0 "INSERT")(cons 410 sheetname))))
(progn
(setq vla-obj (vlax-ename->vla-object (ssname ss 0)))
(if (not (LM:vl-setattributevalue vla-obj att val))
(prompt "\nAttribute not present")
)
)
(prompt "\nBlock not found")
)
(princ)
)

 

 


;;;testing variables....


(defun c:ReadExamples ( / lst)

(setq lst (:GetRevList "SSREVISION"))

(foreach e lst
(princ "\n") (princ e)) ; list all values (associated list)
;;;
;;; (princ "\n")
;;; (princ (cdr (assoc "REV3DATE1" lst))) ; princ value from associted list


;;; below - IMHO this is ridiculuos, associated list should serve the puPARose.

(foreach e lst
(set (read (car e)) (cdr e))) ;; set all variables from associated list

;;; (princ "\n")
;;; (princ (eval (read "REV3DATE1"))) ;; princ a value from variable
;;;
(princ)

)

 

(defun c:REC_REVUP ()

(c:ReadExamples)

;layout 1

(if

(/= SS_NO1 "%%")
(and
(setq sheetlay 1)
(setAttrib "SSREVISION" "SS_BAKNO" SS_NO1)
(setq SNO1 "oui")
);end and
);end if

(if

(= SS_NO1 "%%")
(setq SNO1 "non")
);end if

(if
(and
(/= SS_NO1 "%%")
(/= SS_BAKNO1 "%%")
(= REV1NO1 "%%")
);end and

(and
(setq sheetlay 1)
(setAttrib "SSREVISION" "1_NO" SS_NO1)
(setq R1NO1 "oui")
);end and
);end if

(if
(and
(= SS_NO1 "%%")
(= SS_BAKNO1 "%%")
(/= REV1NO1 "%%")
);end and

(setq R1NO1 "non")

);end if

(c:ReadExamples)

;layout 2

(if

(/= SS_NO2 "%%")
(and
(setq sheetlay 2)
(setAttrib "SSREVISION" "SS_BAKNO" SS_NO2)
(setq SNO2 "oui")
);end and
);end if

(if

(= SS_NO2 "%%")
(setq SNO2 "non")
);end if

(if
(and
(/= SS_NO2 "%%")
(/= SS_BAKNO2 "%%")
(= REV1NO2 "%%")
);end and

(and
(setq sheetlay 2)
(setAttrib "SSREVISION" "1_NO" SS_NO2)
(setq R1NO2 "oui")
);end and
);end if

(if
(and
(= SS_NO2 "%%")
(= SS_BAKNO2 "%%")
(/= REV1NO2 "%%")
);end and

(setq R1NO2 "non")

);end if


(princ)

)

0 Likes
Message 7 of 7

mduvalAA6EJ
Enthusiast
Enthusiast

my cad project contain multiple drawing

 

how can i run the lisp for multiple dwg ?

 

thank you

0 Likes