Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

modifying a lisp for rename the layouts

waseemtarik
Advocate

modifying a lisp for rename the layouts

waseemtarik
Advocate
Advocate

hello everyone,

 

I have download this lisp from on of the website, I'm just looking if someone can modify it to make it more smart and fast to work, this lisp is to change the layout name as per the template attribute or text or mtext. 

however this does it one by one, is there a way to make it for all the layouts in the viewports. 

thanks 

 

0 Likes
Reply
Accepted solutions (1)
1,660 Views
14 Replies
Replies (14)

pbejse
Mentor
Mentor

@waseemtarik wrote:

hello everyone,

 

I have download this lisp from on of the website, I'm just looking if someone can modify it to make it more smart and fast to work, this lisp is to change the layout name as per the template attribute or text or mtext. 

however this does it one by one, is there a way to make it for all the layouts in the viewports. 

thanks 


 

I take it there is a block on the layout tab as the source for the new layout name? or are ou wanting to prompt the user per layout tab? maybe because its not always an attribute but TEXT or MTEXT? 

 

?? And that somehow confuse us more ??

 

Need more info @waseemtarik  a sample perhaps?

 

0 Likes

waseemtarik
Advocate
Advocate

@pbejse Hi, this lisp can change the layout name into titleblock name but I only can do it one by one.

I need a way of having it as automatically. so I don't need to select each layout and run the lisp

0 Likes

waseemtarik
Advocate
Advocate

@pbejse I don't know how to do screenshare or screen video, but here's a website maybe it can help. as you can see it changes one by one 

 

https://autocadtips1.com/2012/02/16/autolisp-select-text-rename-layout-tab/

 

regards

0 Likes

pbejse
Mentor
Mentor

@waseemtarik wrote:

this lisp can change the layout name into titleblock name


So its from a block then? and if somehow the name already exist and cannot be use again for another layout what will happen then?

 

0 Likes

waseemtarik
Advocate
Advocate

usually the titleblock name won't be repeated, however I want once I select the text/Mtext/attribute of the titleblock, it will generate all layouts to be upgraded as per the name of the titleblock. 

let me know if this can be modified. 

thanks 

0 Likes

devitg
Advisor
Advisor

@waseemtarik For better understanding, and maybe get further help, please upload such sample.dwg

0 Likes

waseemtarik
Advocate
Advocate

@devitg I uploaded a file, as you can see that layouts name don't match titleblock. I have more than 200 layouts. I don't want to rename each one, it'll take time. with this lisp I can rename one by one, by selecting the attribute.

looking for a way to make it rename all of the layouts to match my titleblock name or text. thanks

0 Likes

pbejse
Mentor
Mentor

Only now that this statement makes sense:

"make it for all the layouts in the viewports."

 

"I have more than 200 layouts." a

Are you saying that all 200 titleblock is on model space? how are arrange? left to right ? or in rows?  All the layout tabs already exist and matches the number of titile block on model space?

How is the titleblock numbered? always with a "-" and a number? "E7-12" ?

 

0 Likes

waseemtarik
Advocate
Advocate

@pbejse sorry I didn't understand also I'm not familiar with lisp language. 

0 Likes

waseemtarik
Advocate
Advocate

@pbejse IN A ROW, ALL TITLEBLOCK ARE IN MODEL SPACE. 

0 Likes

waseemtarik
Advocate
Advocate

@pbejse yes always E(number)-(number) 

example E1-1 

E1-2

E1-3

E45-1

E45-2

E45-3

E45-4

etc... 

0 Likes

Sea-Haven
Mentor
Mentor

If your dwg with 200 layouts matches the sample with a layout containing the single title block this may work, but its very driven by an exact match in same location for the attribute dwg#

 

(defun rlayouts ( / pt2 pt3 ss lst)
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(vlax-for lay (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object)))
(setq layname (vla-get-name lay))
(if (/= "Model" layname)
(progn
(setvar 'ctab layname)
(command "._mspace")
(setq pt2 (trans (list 865 22) 3 0))
(setq pt3 (trans (list 835 37) 3 0))
(setq lst (list pt2 pt3))
(if (setq ss (ssget "F" lst))
(progn
(setq ent (ssname ss 0))
(command "chspace" ent "" )
(command "._pspace")
(foreach att (vlax-invoke (vlax-ename->vla-object (entlast)) 'getattributes)
        (if (= "DWG#" (strcase (vla-get-tagstring att)))
		(command "layout" "R" (getvar 'ctab) (vla-get-textstring att))
		)
)
)
)
(command "._pspace")
)
)
)
(setvar 'osmode oldsnap)
(princ)
)
(rlayouts)

 

pbejse
Mentor
Mentor
Accepted solution
;; WCS2PCS (gile)
;; Translates a point WCS coordinates to the PaperSpace CS according to
;; the specified Viewport
;;
;; (WCS2PCS pt vp) is the same as (trans (trans pt 0 2) 2 3) when vp is active
;;
;; Arguments
;; pt : a point
;; vp : the viewport (ename or vla-object)

(defun WCS2PCS (pt vp / elst ang nor scl mat)
  (vl-load-com)
  (and (= (type vp) 'VLA-OBJECT)
       (setq vp (vlax-vla-object->ename vp))
  )
  (setq	pt   (trans pt 0 0)
	elst (entget vp)
	ang  (cdr (assoc 51 elst))
	nor  (cdr (assoc 16 elst))
	scl  (/ (cdr (assoc 41 elst)) (cdr (assoc 45 elst)))
	mat  (mxm
	       (list (list (cos ang) (- (sin ang)) 0.0)
		     (list (sin ang) (cos ang) 0.0)
		     '(0.0 0.0 1.0)
	       )
	       (mapcar (function (lambda (v) (trans v nor 0 T)))
		       '((1.0 0.0 0.0) (0.0 1.0 0.0) (0.0 0.0 1.0))
	       )
	     )
  )
  (mapcar '+
	  (vxs (mxv mat (mapcar '- pt (cdr (assoc 17 elst)))) scl)
	  (vxs (cdr (assoc 12 elst)) (- scl))
	  (cdr (assoc 10 elst))
  )
)

;; PCS2WCS (gile)
;; Translates a point PaperSpace coordinates to WCS coordinates
;; according to the specified viewport
;;
;; (PCS2WCS pt vp) is the same as (trans (trans pt 3 2) 2 0) when vp is active
;;
;; Arguments
;; pt : a point
;; vp : the viewport (ename or vla-object)

(defun PCS2WCS (pt vp / ang nor scl mat)
  (vl-load-com)
  (and (= (type vp) 'VLA-OBJECT)
       (setq vp (vlax-vla-object->ename vp))
  )
  (setq	pt   (trans pt 0 0)
	elst (entget vp)
	ang  (- (cdr (assoc 51 elst)))
	nor  (cdr (assoc 16 elst))
	scl  (/ (cdr (assoc 45 elst)) (cdr (assoc 41 elst)))
	mat  (mxm
	       (mapcar (function (lambda (v) (trans v 0 nor T)))
		       '((1.0 0.0 0.0) (0.0 1.0 0.0) (0.0 0.0 1.0))
	       )
	       (list (list (cos ang) (- (sin ang)) 0.0)
		     (list (sin ang) (cos ang) 0.0)
		     '(0.0 0.0 1.0)
	       )
	     )
  )
  (mapcar '+
	  (mxv mat
	       (mapcar '+
		       (vxs pt scl)
		       (vxs (cdr (assoc 10 elst)) (- scl))
		       (cdr (assoc 12 elst))
	       )
	  )
	  (cdr (assoc 17 elst))
  )
)

;; VXS Multiply a vector by a scalar
;;
;; Arguments : a vector and a real

(defun vxs (v s) (mapcar (function (lambda (x) (* x s))) v))

;; VXV (gile)
;; Returns the dot product of two vectors (real)
;;
;; Arguments : two vectors
;; return : a real number

(defun vxv (v1 v2) (apply '+ (mapcar '* v1 v2)))

;; TRP
;; transposes a matrix -Doug Wilson-
;;
;; Argument : a matrix
;; return : a matrix

(defun trp (m) (apply 'mapcar (cons 'list m)))

;; MXV
;; Applies a transformation matrix to a vector  -Vladimir Nesterovsky-
;;
;; Arguments : une matrice et un vecteur
;; return : a vector

(defun mxv (m v)
  (mapcar '(lambda (r) (vxv r v)) m)
)

;; MXM
;; Multiplies (combinates) two matrices -Vladimir Nesterovsky-
;;
;; Arguments : deux matrices
;; return : a matrix

(defun mxm (m q)
  (mapcar '(lambda (r) (mxv (trp q) r)) m)
)


(defun c:MNlay ( / dx Match bname Tagname vpts i ve fourTen ll ur tblock tbdata)
(setq dx (lambda (d e)(Cdr (assoc d (entget e)))))
	 
(if
  (and
    (setq Match (entsel "\nSelect Attribute"))
    (eq "INSERT" (dx 0 (Car Match)))
    (setq bname (dx 2 (Car Match)))
    (eq "ATTRIB" (dx 0 (setq match (car (nentselp (cadr Match))))))
    (setq Tagname (dx 2  match))
    (setq vpts (ssget "_X" '((0 . "VIEWPORT")(8 . "TA-VIEWPORT"))))
    )
    (repeat (sslength vpts)
      	(setq ve (ssname vpts 0))
        (setq fourTen (dx 410 ve))
	(vla-GetBoundingBox (vlax-ename->vla-object ve) 'll 'ur)
	(setq ll (PCS2WCS (vlax-safearray->list ll) ve)
	      ur (PCS2WCS (vlax-safearray->list ur) ve))
		(if (and
		      (setq tblock (ssget "_X" (append
				       '((0 . "INSERT")(66 . 1)(410 . "Model"))
				       (list (cons 2 bname)
					     '(-4 . ">=,>=,*")(cons 10 ll)
					     '(-4 . "<=,<=,*")
					     (cons 10 ur)))))
	      	      (setq tbdata  (getpropertyvalue (ssname tblock 0) Tagname))
		      (not (member tbdata (layoutlist)))
		      )
		(command "_Layout" "_Rename" fourTen tbdata))
      (ssdel ve vpts)
      )
  )
  (princ)
  )
Command: MNLAY
Select Attribute

HTH

 

waseemtarik
Advocate
Advocate

@pbejse works perfect thank you

@Sea-Haven what is the command for your lisp? 

thanks to both of you for giving your time to work on this. 

 

0 Likes