Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

modifying a lisp for rename the layouts

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
waseemtarik
1397 Views, 14 Replies

modifying a lisp for rename the layouts

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 

 

14 REPLIES 14
Message 2 of 15
pbejse
in reply to: waseemtarik


@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?

 

Message 3 of 15
waseemtarik
in reply to: pbejse

@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

Message 4 of 15
waseemtarik
in reply to: waseemtarik

@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

Message 5 of 15
pbejse
in reply to: waseemtarik


@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?

 

Message 6 of 15
waseemtarik
in reply to: pbejse

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 

Message 7 of 15
devitg
in reply to: waseemtarik

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

Message 8 of 15
waseemtarik
in reply to: devitg

@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

Message 9 of 15
pbejse
in reply to: waseemtarik

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" ?

 

Message 10 of 15
waseemtarik
in reply to: pbejse

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

Message 11 of 15
waseemtarik
in reply to: waseemtarik

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

Message 12 of 15
waseemtarik
in reply to: pbejse

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

example E1-1 

E1-2

E1-3

E45-1

E45-2

E45-3

E45-4

etc... 

Message 13 of 15
Sea-Haven
in reply to: waseemtarik

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)

 

Message 14 of 15
pbejse
in reply to: waseemtarik

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

 

Message 15 of 15
waseemtarik
in reply to: pbejse

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

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


AutoCAD Beta