lisp for creating paper size

lisp for creating paper size

Anonymous
Not applicable
2,726 Views
7 Replies
Message 1 of 8

lisp for creating paper size

Anonymous
Not applicable

Hi, I would LOVE to have some lisp that would generate a custom paper size automatically by the user picking a window on the screen (in model space) - lets say i picked a window size of 900/5000 (drawing units) & because my units are set to millimeters then i would get a paper size of 90/500 centimeters...

ANY IDEAS??

thanks!!

0 Likes
2,727 Views
7 Replies
Replies (7)
Message 2 of 8

patrick_35
Collaborator
Collaborator

Hi

 

The solution am interested
I had researched at the time, but nothing conclusive

 

@+

0 Likes
Message 3 of 8

CADaSchtroumpf
Advisor
Advisor

Hi,

 

I don't known if I have good understand, but you can try this, don't use "Enter" for options, use simply key.

Generating muliple size of A4 dimension with selection scale (+/-), move cursor at screen for draw the box.

 

(defun des_vec (lst col / lst_sg)
  (setq lst_sg (list (cadr lst) (car lst)))
  (setq lst (cdr lst))
  (while lst
    (if (cadr lst)
      (setq lst_sg (cons (cadr lst) (cons (car lst) lst_sg)))
      (setq lst_sg (cons (last lst_sg) (cons (car lst) lst_sg)))
    )
    (setq lst (cdr lst))
  )
  (setq lst_sg (cons col lst_sg))
  (grvecs lst_sg)
)
(defun c:A4_dyn ( / unit_draw hview old_snapang pt_ins dx dy pt_tmp ang l_scale format_scale coeff key pt_key n nb_column nb_raw pt_row count s_ang)
  (if (or (eq (getvar "USERS5") "") (not (eq (substr (getvar "USERS5") 1 2) "qz")))
    (progn
      (initget "KM ME CM MM")
      (if (not(setq unit_draw (getkword "\nDessin réalisé en [KM/ME/CM/MM] <ME>: ")))
        (setq unit_draw "ME")
      )
      (cond
        ((eq unit_draw "KM")
          (setq unit_draw 1000000)
        )
        ((eq unit_draw "ME")
          (setq unit_draw 1000)
        )
        ((eq unit_draw "CM")
          (setq unit_draw 10)
        )
        ((eq unit_draw "MM")
          (setq unit_draw 1)
        )
      )
      (setvar "USERS5" (strcat "qz" (itoa unit_draw)))
    )
    (setq unit_draw (atoi (substr (getvar "USERS5") 3)))
  )
  (setq
    hview (getvar "VIEWSIZE")
    old_snapang (getvar "SNAPANG")
    pt_ins (list (- (car (getvar "VIEWCTR")) (* hview 0.5)) (- (cadr (getvar "VIEWCTR")) (* hview 0.5)))
    dx 210.0 dy (* 210.0 (sqrt 2)) pt_tmp pt_ins ang (getvar "SNAPANG")
    l_scale '(1.0 1.25 2.0 2.5 5.0 7.5)
    format_scale (car l_scale)
    coeff 1.0
  )
  (if (> (fix (/ hview dy)) 3)
    (while (> (fix (/ hview dy)) 3)
      (foreach value l_scale
        (if (> (fix (/ hview dy)) 3)
          (setq format_scale value dx (* 210.0 format_scale) dy (* 210.0 (sqrt 2) format_scale))
        )
      )
      (if (> (fix (/ hview dy)) 3)
        (setq
          coeff (* coeff 10.0)
          l_scale (mapcar '(lambda (x) (* x coeff)) l_scale)
          format_scale (car l_scale)
        )
      )
    )
  )
  (if (< (fix (/ hview dy)) 1)
    (while (< (fix (/ hview dy)) 1)
      (foreach value (reverse l_scale)
        (if (< (fix (/ hview dy)) 1)
          (setq format_scale value dx (* 210.0 format_scale) dy (* 210.0 (sqrt 2) format_scale))
        )
      )
      (if (< (fix (/ hview dy)) 1)
        (setq
          coeff (* coeff 0.1)
          l_scale (mapcar '(lambda (x) (* x coeff)) l_scale)
          format_scale (last l_scale)
        )
      )
    )
  )
;(print format_scale)
  (princ (strcat "\nSpécifiez le coin haut droit ou [R] pour effectuer une rotation, [D] un déplacement, [+/-] un changement d'échelle <" (rtos (* unit_draw format_scale) 2 3) ">: "))
  (while (and (setq key (grread T 4 0)) (/= (car key) 3))
    (cond
      ((eq (car key) 5)
        (setq pt_key (cadr key))
        (setq n
          (*
            (setq nb_column (fix (/ (+ (* (- (car pt_key) (car pt_ins)) (cos ang)) (* (- (cadr pt_key) (cadr pt_ins)) (sin ang))) dx)))
            (setq nb_raw (fix (/ (- (* (- (cadr pt_key) (cadr pt_ins)) (cos ang)) (* (- (car pt_key) (car pt_ins)) (sin ang))) dy)))
          )
          pt_row pt_ins count 0
        )
        (redraw)
        (repeat n
          (des_vec
            (list
              (list (car pt_ins) (cadr pt_ins))
              (list (+ (car pt_ins) (* dx (cos ang))) (+ (cadr pt_ins) (* dx (sin ang))))
              (setvar "LASTPOINT"
                (list
                  (+ (car pt_ins) (- (* dx (cos ang)) (* dy (sin ang))))
                  (+ (cadr pt_ins) (+ (* dy (cos ang)) (* dx (sin ang))))
                )
              )
              (list (- (car pt_ins) (* dy (sin ang))) (+ (cadr pt_ins) (* dy (cos ang))))
            )
            3
          )
          (setq count (1+ count))
          (if (< count nb_column)
            (setq pt_ins (list (+ (car pt_ins) (* dx (cos ang))) (+ (cadr pt_ins) (* dx (sin ang)))))
            (setq pt_ins (list (- (car pt_row) (* dy (sin ang))) (+ (cadr pt_row) (* dy (cos ang)))) pt_row pt_ins count 0)
          )
        )
        (setq pt_ins pt_tmp)
      )
      ((or (eq (cadr key) 114) (eq (cadr key) 82))
        (initget 0)
        (setq s_ang
          (getorient pt_ins
            (strcat
              "\nNouvel angle<"
              (angtos (getvar "SNAPANG"))
              ">: "
            )
          )
        )
        (if (not s_ang) (setq s_ang ang))
        (if (and (> s_ang (/ pi 2)) (<= s_ang (/ (* 3 pi) 2)))
          (setq ang (+ s_ang pi))
          (setq ang s_ang)
        )
        (setvar "SNAPANG" ang)
        (princ (strcat "\nSpécifiez le coin haut droit ou [R] pour effectuer une rotation, [D] un déplacement, [+/-] un changement d'échelle <" (rtos (* unit_draw format_scale) 2 3) ">: "))
      )
      ((or (eq (cadr key) 100) (eq (cadr key) 68))
        (initget 9)
        (setq pt_ins (getpoint "\nSpécifiez le coin bas gauche: "))
        (setq pt_ins (list (car pt_ins) (cadr pt_ins)) pt_tmp pt_ins)
        (princ (strcat "\nSpécifiez le coin haut droit ou [R] pour effectuer une rotation, [D] un déplacement, [+/-] un changement d'échelle <" (rtos (* unit_draw format_scale) 2 3) ">: "))
      )
      ((eq (cadr key) 43)
        (setq format_scale (cadr (member format_scale l_scale)))
        (if (not format_scale) (setq format_scale (car (setq l_scale (mapcar '(lambda (x) (* x 10.0)) l_scale)))))
        (setq dx (* 210.0 format_scale) dy (* 210.0 (sqrt 2) format_scale))
        (princ (strcat "\nSpécifiez le coin haut droit ou [R] pour effectuer une rotation, [D] un déplacement, [+/-] un changement d'échelle <" (rtos (* unit_draw format_scale) 2 3) ">: "))
      )
      ((eq (cadr key) 45)
        (setq format_scale (cadr (member format_scale (reverse l_scale))))
        (if (not format_scale) (setq format_scale (last (setq l_scale (mapcar '(lambda (x) (* x 0.1)) l_scale)))))
        (setq dx (* 210.0 format_scale) dy (* 210.0 (sqrt 2) format_scale))
        (princ (strcat "\nSpécifiez le coin haut droit ou [R] pour effectuer une rotation, [D] un déplacement, [+/-] un changement d'échelle <" (rtos (* unit_draw format_scale) 2 3) ">: "))
      )
    )
  )
  (princ "\n")
  (redraw)
  (princ (setq toto (list (list pt_ins (getvar "LASTPOINT")) (getvar "SNAPANG") (* unit_draw format_scale))))
  (command "_.rectang" "_none" (caar toto) "_rotation" (angtos (getvar "SNAPANG")) "_none" (cadar toto))
  (setvar "SNAPANG" old_snapang)
  (prin1)
)
0 Likes
Message 4 of 8

Anonymous
Not applicable

hi, thank you so much but this is not what i'm looking for

i wanna make a CUSTOM paper size (not A4) just by clicking a window on the screen - it should be simple & will save a lot of time! wonder why autodesk didn't do that yet... 😞

0 Likes
Message 5 of 8

Anonymous
Not applicable

attached is what i want to have...

 

0 Likes
Message 6 of 8

Anonymous
Not applicable

Hi did you find what you were looking for?

I also searched all over the internet and found nothing similar.

0 Likes
Message 7 of 8

andkal
Collaborator
Collaborator

Here is a "PAPER_SHEET_FORMAT" Lisp routine for automatic generatig Paper Sizes. The program recognises the units of a drawing and inserts a choosen Paper Size in correct dimmensions. You can download a Demo version to see if it suits your needs. The application you can download it from autolisps.blogspot.com or from the Autodesk App Store. Links below:

http://autolisps.blogspot.com/p/papersheetformat.html
https://apps.autodesk.com/pl/Publisher/PublisherHomepage?ID=201102061247225


• www.autolisps.blogspot.com - Productivity plugins for Autocad and Autocad MEP
• Autodesk AppStore
0 Likes
Message 8 of 8

hak_vz
Advisor
Advisor

@andkalNice work.

I didn't tested it but from your screenshots it looks OK. I have my own script for this purpose, and that is actually one of my first autolisp scripts I've written many years ago.

What I would add to your code is variable size internal frame. For example on standard A4 we have 25 5 5 5 where 25 is binding margin. Check this link for explanation.

Also there would be option to add drawing title block, or at least a rectangle in bottom right or top right corner and and some rectangle are to eventually place a legend. This would help when positioning and utilizing paper "free space".  Since larger size drawings are usually folded to smaller size (let say A1 to A4 upright) adding folding marks may be of help to some users. There are now automated folding machines but quality of their works is not always the best so folding has to be done manually.

And finally, I would add option to create a layout out from defined rectangles.  

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes