Author Topic: Automatic layout LISP  (Read 1430 times)

0 Members and 1 Guest are viewing this topic.

renkor

  • Newt
  • Posts: 27
Automatic layout LISP
« on: August 25, 2018, 04:00:10 PM »
Hello,

 

I have been looking for a routine able to do this many time. I have a road axis and 188 blocks (viewports) align to it by the mid point. But making all layouts one by one it's a waste of time. So do you know a routine able to make all layouts automatically with the configuration of a template tab, and orientated to the respective UCS viewport?

 

Look at the example and I expect you understand my question.

Best regards,

Daniel.

slj.engenharia@gmail.com

  • Mosquito
  • Posts: 3
Re: Automatic layout LISP
« Reply #1 on: August 03, 2022, 10:04:23 AM »
hello renkor, i found your question and i have an answer after several years.
Of course you managed to solve it.
But I did it as a challenge.
(I'm sorry if I misspelled something, I used google translator)


Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ a cnt en entg entg_pline lista n num_str p1 p2 pini pins pline pt
  2.              ss1 ss2)
  3.   (setvar "cmdecho" 0)
  4.   (command ".ucs" "world")
  5.   (if (null (tblsearch "layer" "defpoints"))
  6.     (command ".layer" "m" "defpoints" "c" "7" "" "")
  7.   )
  8.   (if (setq pline (entsel "\nSelect the road axis:"))
  9.     (progn
  10.       (redraw (car pline) 3) ;_highlight object
  11.       (if (setq pini (getpoint
  12.                        "\nSelect a point near the beginning of the road pline: "
  13.                      )
  14.           )
  15.         (progn
  16.           (setq entg_pline (entget (car pline)))
  17.           (setq lista nil)
  18.           (mapcar '(lambda (a)
  19.                      (if (= (car a) 10)
  20.                        (setq lista (cons (cdr a) lista))
  21.                      )
  22.                    )
  23.                   entg_pline
  24.           )
  25.           (if (< (distance pini (last lista)) (distance pini (car lista)))
  26.             (setq lista (reverse lista))
  27.           )
  28.           (setq ss1 (ssget "f" lista (list (cons '2 "viewport"))))
  29.           (setq cnt (sslength ss1))
  30.           (if (> cnt 0)
  31.             (progn
  32.               (setq n 0)
  33.               (repeat cnt
  34.                 (setq entg (entget (setq en (ssname ss1 n))))
  35.                 (setq n (1+ n))
  36.                 (setq pins (cdr (assoc 10 entg)))
  37.                 (setq pt (polar pins (cdr (assoc 50 entg)) 400))
  38.                 (setq p1
  39.                        (polar pins (+ (* pi 0.5) (cdr (assoc 50 entg))) 291.7293)
  40.                 )
  41.                 (setq p2
  42.                        (polar pins (+ (* pi 1.5) (cdr (assoc 50 entg))) 291.7293)
  43.                 )
  44.                 (setq p2 (polar p2 (cdr (assoc 50 entg)) 844.4204))
  45.                 (setq num_str (rtos n 2 0))
  46.                 (if (= (strlen num_str) 1)
  47.                   (setq num_str (strcat "0" num_str))
  48.                 )
  49.                 ;;;_the number is for verification
  50.                 ;;;_layer defpoints does not plot
  51.                 (entmakex (list (cons 0 "TEXT")
  52.                                 (cons 1 num_str)
  53.                                 (cons 10 pt)
  54.                                 (cons 11 pt)
  55.                                 (cons 8 "defpoints")
  56.                                 (cons 40 200)
  57.                                 (cons 50 (cdr (assoc 50 entg)))
  58.                                 (cons 72 1)
  59.                                 (cons 73 2)
  60.                           )
  61.                 )
  62.                 (command ".-layout" "copy" "template" num_str)
  63.                 (command ".-layout" "set" num_str)
  64.                 (setq
  65.                   ss2 (ssget
  66.                         "x"
  67.                         (list (cons 0 "VIEWPORT") (cons 410 (getvar "ctab")))
  68.                       )
  69.                 )
  70.                 (vla-put-displaylocked (vlax-ename->vla-object (ssname ss2 0))
  71.                                        :vlax-false
  72.                 )
  73.                 (command ".mspace")
  74.                 (command ".ucs" "ob" en)
  75.                 (command ".plan" "")
  76.                 (command ".zoom" "w" (trans p1 0 1) (trans p2 0 1))
  77.                 (command ".pspace")
  78.                 (setvar "tilemode" 1)
  79.               )
  80.               (command ".-layout" "delet" "template")
  81.             )
  82.           )
  83.         )
  84.       )
  85.     )
  86.   )
  87.   (if pline
  88.     (redraw (car pline) 4) ;_unhighlight object
  89.   )
  90.   (princ)
  91. )


EDIT (John): Added code tags.
« Last Edit: August 03, 2022, 10:34:11 AM by JohnK »

BIGAL

  • Swamp Rat
  • Posts: 1037
  • 40 + years of using Autocad
Re: Automatic layout LISP
« Reply #2 on: August 03, 2022, 09:54:53 PM »
Something like this happy to talk more. Currently being rewritten for new dcl in progress.





A man who never made a mistake never made anything

MSTG007

  • Gator
  • Posts: 2562
  • I can't remeber what I already asked! I need help!
Re: Automatic layout LISP
« Reply #3 on: August 04, 2022, 07:42:10 AM »
I gotta a question. How is slj.engenharia so much more slower then how your video executes your code? Both are really impressive. Great Job. Really cool.
Civil3D 2020

BIGAL

  • Swamp Rat
  • Posts: 1037
  • 40 + years of using Autocad
Re: Automatic layout LISP
« Reply #4 on: August 04, 2022, 08:05:54 PM »
The code executes way faster than the video its as fast as you can do
pick menu option
pick size and orientation OK
pick pline

The rectangs are made, the reason for a 2nd step is this allows user to move, add, rotate the rectangs ie fine tune.

pick menu option
select all rectangs.

Watch the layouts get made.

The extra is clients details are added to the layout also.


Others just fill in 1 layout title block attributes, then this is copied to all others.
Do sheet X of Y etc.
Create index and so on.
A man who never made a mistake never made anything