LISP to fully automatically create a layout from block

LISP to fully automatically create a layout from block

Anonymous
Not applicable
5,959 Views
5 Replies
Message 1 of 6

LISP to fully automatically create a layout from block

Anonymous
Not applicable

Hei there!

I want to write a LISP that creates a printable layout from a template. The layout template is chosen based on a paper frame block selected in Model space.

So basically it would be like this:

1. I load the app and move the paper.dwt (the paper.dwt contains layouts named A4-portrait, A4-landscape and so on) to the default template folder. (this is a one time event)


2. Lets name the application "NTL"


3. In modelspace, I have a drawing inside an A4-portrait custom block called KN, it has a parameter called "papername", the value is "A4-portrait".


4. I write NTL, autocad tells me to choose a block. I choose the block.


5. Now it should set a variable to A4-portrait, which means autocad selects a new layout template  from PAPER.dwt called A4-portrait.


6. Then it should create a viewport based on the position of the select block and also set the center of the viewport to be the center of the selected block (so basically half measurements of the paper).


7. There is a titleblock "TB" on the modelspace drawing which has an attribute "SCALE" which equals 1:10, so the viewports scale should be set also to 1:10


8. So autocad creates a layout from a template file according to the selected block parameters, this includes setting the scale from the titleblock and centering the created viewport.


9.Finally autocad should rename the new layout accoring to the parameters from the Titleblock "TB". The name should be "DRAWING NUMBER"_"DRAWING NAME".

 

My knowledge in Autocad LISP is not sufficient so I am asking for your help and advice. I ahve written a simpler one, but it needs to much user ineteraction and I want to fully automate it.

 

Thanks for any responses

(defun c:NTL (/	      doc      p1	p2	 temp	  mp
	     scl      SC       cd:DWG_LayoutsList	  res
	     a	      b	       vpp	vpdoc	 vp  Match Text
	    )
	(command "selectioncycling" "0")
	(initdia)
	(command "layout" "template" "")	
  (vl-load-com)
  (setq Doc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
  (setq p1 (getpoint "\Pick Corners:"))
  (setq p2 (getcorner p1))
  (if
    (< (car (trans p2 1 0)) (car (trans p1 1 0)))
     (setq tmp p1
	   p1  p2
	   p2  tmp
     )
     T
  )
  (setq	mp (list (/ (+ (car p1) (car p2)) 2)
		 (/ (+ (cadr p1) (cadr p2)) 2)
		 0.0
	   )
  )

  (setq	sc (cond ((getint (strcat "\Scale 1: <"
				  (itoa	(setq sc (cond (sc)
						       (10)
						 )
					)
				  )
				  ">: "
			  )
		  )
		 )
		 (sc)
	   )
  )
  (setq	cd:DWG_LayoutsList
	 (vlax-for % (vla-get-layouts Doc)
	   (setq res (cons (list (vla-get-name %)
				 (vla-get-TabOrder %)
				 %
			   )
			   res
		     )
	   )
	 )
  )
  (setvar "CTab"
	  (caar	(vl-sort cd:DWG_LayoutsList
			 '(lambda (a b) (> (cadr a) (cadr b)))
		)
	  )
  )

  (setq VPDoc (vla-get-PaperSpace doc))
  (setq VPp (vlax-3D-point (getpoint "\npick layout center")))
  (setq	VP (vla-AddPViewport
	     VPDoc
	     VPp
	     (/ (- (car p2) (car p1)) sc)
	     (/ (- (cadr p2) (cadr p1)) sc)
	   )
  )
  (vla-display VP :vlax-true)
  (vla-put-mspace doc :vlax-true)
  (vla-put-activepviewport Doc VP)
  (vla-zoomcenter
    (vlax-get-acad-object)
    (vlax-3d-point mp)
    1.0
  )
  (vl-cmdf "_.zoom" (strcat (RTOS (/ 1.0 SC)) "xp"))
  (vla-regen (vla-get-activedocument (vlax-get-acad-object))
	     acActiveViewport
  )
  (vla-put-mspace doc :vlax-FALSE)
  (VLA-PUT-DisplayLocked VP :vlax-true)
  
  ;chooses the created viewport ;
  (command "_.MSPACE")
  
  ;rename;
  (while (= Match nil)
		(setq Match (nentsel "\nChoose a name from the titleblock: "))
(if (= Match nil)(alert "Choose a name from the titleblock..."))
)
(if (/= nil Match)
(progn
(setq Match (entget (car Match)))
)
)
(if(setq Text(cdr(assoc 1 Match)))
(command "layout" "rename" "" Text)
)
(setvar "cmdecho" 1)
(princ)
(command "model")
(command "selectioncycling" "2")
)
(princ "\n write LOU")
(princ)

 

5,960 Views
5 Replies
Replies (5)
Message 2 of 6

saifumk8
Advocate
Advocate

Try Auto Layouts App from Autodesk App store: 

This app will help you to create Autodesk® AutoCAD® sheet layouts by automation.

Just prepare the first layout the way you want it and provide inputs like sheet frame height and width, Sheet number, and Viewport. 

 

https://apps.autodesk.com/ACAD_E/en/Detail/Index?id=8869324049075388295&appLang=en&os=Win32_64

 

0 Likes
Message 3 of 6

maratovich
Advisor
Advisor

@saifumk8 wrote:

Try Auto Layouts App from Autodesk App store: 

This topic is old. Your spam is ugly.

 

 

 

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 4 of 6

tanbqtb03
Contributor
Contributor

Please update when selection frame block or rectang, lisp will automatic creat auto all layouts

0 Likes
Message 5 of 6

Sea-Haven
Mentor
Mentor

Did you google ? Have a look at maratovich solution.

 

Something I have. Small fee as it needs to be end user customised for title blocks.

 

SeaHaven_0-1665445669424.png

 

 

 

Message 6 of 6

tanbqtb03
Contributor
Contributor

Yes I saw, thanks for your reply

0 Likes