Author Topic: Help - Create new viewport lisp  (Read 2647 times)

0 Members and 1 Guest are viewing this topic.

PM

  • Guest
Help - Create new viewport lisp
« on: February 11, 2022, 11:27:31 AM »
Hi i find this lisp code in this post

https://www.theswamp.org/index.php?topic=47145.0;all

The problem is that this lisp code not working well my template units and viewport scale units. I try to change it but i failed. Can any one help me ??  i upload the original lisp code with original lisp template and i upload my template with a drawing (look at viewport scales and template unit settings)

thanks


PM

  • Guest
Re: Help - Create new viewport lisp
« Reply #1 on: February 12, 2022, 03:08:16 AM »
Any ideas ?

Thanks

PM

  • Guest
Re: Help - Create new viewport lisp
« Reply #2 on: February 12, 2022, 10:07:16 AM »
i update the code but something is missing. The new viewport is big in correct dimension but the misc is off (in properties ), the annotation scale is 1:1 and is lock and not center to the previous selection (is empty. )

Can any one help ?

Thanks

Code - Auto/Visual Lisp: [Select]
  1. ; Source:                            http://www.theswamp.org/index.php?topic=42149.msg473439#msg473439
  2. ; Improvements suggested by Lee Mac: http://www.theswamp.org/index.php?topic=42149.msg473793#msg473793
  3. ; Modified version for:              http://www.theswamp.org/index.php?topic=47145
  4. (defun c:NV (/ *error* _RestoreView p1 p2 doc ct vs vc tmp mp sc ll sl res vpdoc vpp vp ans)
  5.   (defun *error* (Msg)
  6.     (princ "Error: ")
  7.     (princ Msg)
  8.     (if ct (_RestoreView))
  9.     (princ)
  10.   )
  11.   (defun _RestoreView ()
  12.     (setvar "ctab" ct)
  13.   )
  14.   (if (/= (getvar "cvport") 1)
  15.     (if
  16.       (and
  17.         (setq p1 (getpoint "\nSelect first point of view: "))
  18.         (setq p2 (getcorner p1 "\nSelect second point of view: "))
  19.       )
  20.       (progn
  21.               ct (getvar "ctab")
  22.               vs (getvar "viewsize")
  23.               vc (getvar "viewctr")
  24.               sc (cond
  25.                    ( (getint
  26.                        (strcat
  27.                          "\nWhat is Viewport Scale 1: <"
  28.                          (itoa (setq sc (cond (sc) (50))))
  29.                          ">: "
  30.                        )
  31.                      )
  32.                    )
  33.                    ( sc )
  34.                  )
  35.         )
  36.         (setq ll
  37.           (vlax-for % (vla-get-layouts doc)
  38.             (setq res
  39.               (cons
  40.                 (list
  41.                   (vla-get-name %)
  42.                   %
  43.                   (vla-get-TabOrder %)
  44.                 )
  45.                 res
  46.               )
  47.             )
  48.           )
  49.         )
  50.         (setq ll
  51.           (cdr
  52.             (vl-sort ll
  53.              '(lambda (a b)
  54.                 (< (last a) (last b))
  55.               )
  56.             )
  57.           )
  58.         )
  59. ;;; ============================================================ Start of mod.
  60.         (if (setq sl (cd:DCL_StdListDialog (mapcar ' car ll) 0 "NewViewport" "Select layout:" 40 15 2 nil T T))
  61.           (progn
  62.             ;; 'Trans stuff' has to be done before changing the active layout:
  63.             (setq mp (trans (mapcar '* (mapcar '+ p1 p2) '(0.5 0.5 0.5)) 1 0)) ; WCS.
  64.             (setq vpDir (trans '(0.0 0.0 1) 2 0 T))
  65.             (setq vpDims (mapcar '* (mapcar 'abs (mapcar '- (trans p1 1 2) (trans p2 1 2))) (list (/ 1000.0 sc) (/ 1000.0 sc) 0.0)))
  66.             (setq vpTwist (getvar 'viewtwist))
  67.             (setvar "ctab" (car (nth sl ll)))
  68.             (vla-put-mspace doc :vlax-false)
  69.             (if (setq vpp (getpoint "\nSelect bottom left point for viewport: "))
  70.               (progn
  71.                 (setq vp
  72.                   (vla-addpviewport
  73.                     (vla-get-paperspace doc)
  74.                     (vlax-3d-point (mapcar '+ vpp (mapcar '* vpDims '(0.5 0.5 0.5))))
  75.                     (car vpDims)
  76.                     (cadr vpDims)
  77.                   )
  78.                 )
  79.                 (vla-put-customscale vp (/ 1000.0 sc))
  80.                 (vla-put-direction vp (vlax-3d-point vpDir))
  81.                 (vla-put-target vp (vlax-3d-point mp))
  82.                 (vla-put-twistangle vp vpTwist)
  83.                 (vla-put-displaylocked vp :vlax-true)
  84. ;;; ============================================================ End of mod.
  85.                 (vla-put-MSpace doc :vlax-true)
  86.                 (vla-put-ActivePViewport doc vp)
  87.                 (vla-ZoomCenter
  88.                   (vlax-get-acad-object)
  89.                   (vlax-3d-point mp)
  90.                   1.0
  91.                 )
  92.                 (vla-put-CustomScale vp (/ 1. sc))
  93.                 (vla-put-MSpace doc :vlax-false)
  94.                 (vla-put-DisplayLocked vp :vlax-true)
  95.                 (initget "Yes No")
  96.                 (setq ans
  97.                   (cond
  98.                     ( (getkword "\nBack to model space [Yes/No] <No>: ") )
  99.                     ( "No" )
  100.                   )
  101.                 )
  102.                 (if (= ans "Yes") (_RestoreView))
  103.               )
  104.               (progn
  105.                 (princ "\n** Invalid Point ** ")
  106.                 (if ct (_RestoreView))
  107.               )
  108.             )
  109.           )
  110.           (princ "\n** Layout not selected ** ")
  111.         )
  112.       )
  113.       (princ "\n** Invalid Point ** ")
  114.     )
  115.     (princ "\nStart Program in Model Space ")
  116.   )
  117.   (princ)
  118. )
  119. ; =========================================================================================== ;
  120. ; Okno dialogowe z lista (list_box) / Dialog control with list (list_box)                     ;
  121. ;  Data      [LIST]    - lista do wyswietlenia / list to display                              ;
  122. ;  Pos       [INT]     - pozycja poczatkowa na liscie / select list position                  ;
  123. ;  Title     [STR/nil] - tytul okna / window title                                            ;
  124. ;  ListTitle [STR/nil] - tytul list_box / list_box title                                      ;
  125. ;  Width     [INT]     - szerokosc / width                                                    ;
  126. ;  Height    [INT]     - wysokosc / height                                                    ;
  127. ;  Btns      [0/1/2]   - [cancel/ok/ok_cancel] przyciski / buttons                            ;
  128. ;  MSelect   [T/nil]   - dopuszczenie multiple_select / allow multiple select                 ;
  129. ;  DPos      [T/nil]   - zapamietanie pozycji okna / save window position                     ;
  130. ;  DblClick  [T/nil]   - podwojny klik (wykluczone Cancel) / double click (not for Cancel)    ;
  131. ; ------------------------------------------------------------------------------------------- ;
  132. ; Zwraca / Return:                                                                            ;
  133. ;  nil  = nic nie wybrano (anulowano) / nothing was selected (canceled)                       ;
  134. ;  INT  = wybrano jedna pozycje / one position selected  | MSelect = nil                      ;
  135. ;  LIST = wybrano kilka pozycji / few positions selected | MSelect = T                        ;
  136. ; ------------------------------------------------------------------------------------------- ;
  137. ; (cd:DCL_StdListDialog '("A" "B" "C") 0 "Title" "ListTitle:" 40 15 2 nil T nil)              ;
  138. ; =========================================================================================== ;
  139. (defun cd:DCL_StdListDialog (Data Pos Title ListTitle Width Height Btns MSelect DPos DblClk
  140.                              / f tmp dc res)
  141.   (if (not DPos) (setq *cd-TempDlgPosition* (list -1 -1)))
  142.   (cond
  143.     ( (not
  144.         (and
  145.           (setq f
  146.             (open
  147.               (setq tmp (vl-FileName-MkTemp nil nil ".dcl"))
  148.               "w"
  149.             )
  150.           )
  151.           (foreach %
  152.             (list
  153.               "StdListDialog:dialog{"
  154.               (strcat "label=\""
  155.                 (if Title (strcat Title "\";") "\"\";")
  156.               )
  157.               ":list_box{key=\"list\";"
  158.               (if ListTitle
  159.                 (strcat "label=\"" ListTitle "\";")""
  160.               )
  161.               "fixed_width=true;fixed_height=true;"
  162.               (strcat "width="
  163.                 (if (not Width) "20" (itoa Width))";"
  164.               )
  165.               (strcat "height="
  166.                 (if (not Height) "20" (itoa Height))";"
  167.               )
  168.               (if (not DblClck)
  169.                 (strcat "multiple_select="
  170.                   (if MSelect "true;" "false;")
  171.                 )
  172.                 "multiple_select=false;"
  173.               )
  174.               "}"
  175.               (cond
  176.                 ( (zerop Btns) "cancel_button;")
  177.                 ( (= 1 Btns) "ok_only;")
  178.                 (T "ok_cancel;")
  179.               )
  180.               "}"
  181.             )
  182.             (write-line % f)
  183.           )
  184.           (not (close f))
  185.           (< 0 (setq dc (load_dialog tmp)))
  186.           (new_dialog "StdListDialog" dc ""
  187.             (cond
  188.               ( *cd-TempDlgPosition* )
  189.               ( (quote (-1 -1)) )
  190.             )
  191.           )
  192.         )
  193.       )
  194.     )
  195.     ( T
  196.       (start_list "list")
  197.       (mapcar (quote add_list) Data)
  198.       (end_list)
  199.       (if (not Pos)
  200.         (setq Pos 0)
  201.         (if (> Pos (length Data)) (setq Pos 0))
  202.       )
  203.       (setq res (set_tile "list" (itoa Pos)))
  204.       (action_tile "list"
  205.         (strcat
  206.           "(setq res $value)(if DblClk (if(or(not MSelect)"
  207.           "(not (zerop Btns)))"
  208.           "(if (= $reason 4)(setq "
  209.           "*cd-TempDlgPosition* (done_dialog 1)))))"
  210.         )
  211.       )
  212.       (action_tile "accept" "(setq *cd-TempDlgPosition* (done_dialog 1))")
  213.       (action_tile "cancel" "(setq res nil) (done_dialog 0)")
  214.       (setq res
  215.         (if (= 1 (start_dialog))
  216.           (read (strcat "(" res ")"))
  217.           nil
  218.         )
  219.       )
  220.     )
  221.   )
  222.   (if (< 0 dc) (unload_dialog dc))
  223.   (if (setq tmp (findfile tmp)) (vl-File-Delete tmp))
  224.   (if (not DPos) (setq *cd-TempDlgPosition* (list -1 -1)))
  225.   (if res (if (= 1 (length res)) (car res) res))
  226. )
  227. (princ "\n Type NV to Invoke ")
  228.  
  229.  

smemo

  • Mosquito
  • Posts: 19
Re: Help - Create new viewport lisp
« Reply #3 on: February 13, 2022, 09:06:15 AM »
maybe you can use the lisp to Create viewport "as-CreaFinLay.zip"
http://www.theswamp.org/index.php?topic=42149.msg474945#msg474945

PM

  • Guest
Re: Help - Create new viewport lisp
« Reply #4 on: February 13, 2022, 12:15:36 PM »
hi smemo . The lisp i use is from the same post. Your code is too coplicated for me . You have  6 lisp code in a zip file . I want something simple . The original code i use in my first post work fone with NewViewport_Approach_2.lsp.dwg .The problem is when i use it in MY TEMPLATE.dwg the viewports are too small because my scale are  (for example 1:50 --> 1000 : 50 in meters). I use meters . I try to  change the code in my thirs post  and the viewports are big in corect size but the drawing is not in the correct scale, the annotation scale is 1:1 and is lock and not center to the previous selection (is empty. ).

Than you help me with this problem ?

Thanks

smemo

  • Mosquito
  • Posts: 19
Re: Help - Create new viewport lisp
« Reply #5 on: February 15, 2022, 01:10:33 AM »
this is a single file including DCL, type CFL to start after loading


PM

  • Guest
Re: Help - Create new viewport lisp
« Reply #6 on: February 15, 2022, 01:39:01 AM »
Hi smemo. I try your code but gives me this error

smemo

  • Mosquito
  • Posts: 19
Re: Help - Create new viewport lisp
« Reply #7 on: February 15, 2022, 07:31:19 AM »
"ai_utils.lsp" is a function present in Express Tools.
Requires the installation of the express tools in autocad
https://knowledge.autodesk.com/support/autocad/learn-explore/caas/sfdcarticles/sfdcarticles/How-to-install-Express-Tools-into-AutoCAD.html

PM

  • Guest
Re: Help - Create new viewport lisp
« Reply #8 on: February 15, 2022, 09:23:24 AM »
I am using Autocad 2020 and the express tools works fine.

smemo

  • Mosquito
  • Posts: 19
Re: Help - Create new viewport lisp
« Reply #9 on: February 15, 2022, 02:02:14 PM »
try to search..
(findfile "ai_utils.lsp")
and eventually load it

PM

  • Guest
Re: Help - Create new viewport lisp
« Reply #10 on: February 15, 2022, 04:58:36 PM »
Sorry smemo this code is not working for me. If you can help me to fix the code i post is ok

Thanks

PM

  • Guest
Re: Help - Create new viewport lisp
« Reply #11 on: February 18, 2022, 02:18:04 PM »
Hi smemo  i find the ai_utils.lsp was in

Code - Auto/Visual Lisp: [Select]
  1. "C:\\Program Files\\Autodesk\\AutoCAD 2020\\Support\\en-us;"
  2.  

Is it posible to create the DCL file in C:\Users\Admin\AppData\Local\Temp and not
 
C:\Users\Admin\AppData\Roaming\Autodesk\AutoCAD 2020\R23.1\enu ?


Thanks


mhupp

  • Bull Frog
  • Posts: 250
Re: Help - Create new viewport lisp
« Reply #12 on: February 18, 2022, 08:08:38 PM »
this will make a temp file in the TEMPPREFIX folder location

Code - Auto/Visual Lisp: [Select]
  1. (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w"))
  2. when done with the dcl
  3.  

PM

  • Guest
Re: Help - Create new viewport lisp
« Reply #13 on: February 19, 2022, 03:03:53 AM »
Hi mhupp .I try to do this change but something in going wrong. Can you tell me exactly what lines of the code to  change? Thanks

PM

  • Guest
Re: Help - Create new viewport lisp
« Reply #14 on: February 23, 2022, 11:57:22 AM »
I try to do the change  here

Code - Auto/Visual Lisp: [Select]
  1. (defun create_dcl (fn / acadfn)
  2.   (if (null(wcmatch (strcase fn) "*`.DCL"))
  3.     (setq fn (strcat fn ".DCL"))
  4.   )
  5.   (if (not (findfile (strcat (getvar "roamablerootprefix") fn)))
  6.     ;; create dcl file
  7.     (progn
  8.       (setq fn (strcat (getvar "roamablerootprefix") fn)
  9.             fn (open fn "w")
  10.       )
  11.  
  12.  

but is not working. Can any one help me to create the dcl file in  C:\Users\Admin\AppData\Local\Temp

Thanks

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Help - Create new viewport lisp
« Reply #15 on: February 23, 2022, 01:19:18 PM »
I try to do the change  here

Code - Auto/Visual Lisp: [Select]
  1. (defun create_dcl (fn / acadfn)
  2.   (if (null(wcmatch (strcase fn) "*`.DCL"))
  3.     (setq fn (strcat fn ".DCL"))
  4.   )
  5.   (if (not (findfile (strcat (getvar "roamablerootprefix") fn)))
  6.     ;; create dcl file
  7.     (progn
  8.       (setq fn (strcat (getvar "roamablerootprefix") fn)
  9.             fn (open fn "w")
  10.       )
  11.  
  12.  

but is not working. Can any one help me to create the dcl file in  C:\Users\Admin\AppData\Local\Temp

Thanks
Why don't you use your profile? You probably don't have access to the admin profile if you're a limited user ....

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

PM

  • Guest
Re: Help - Create new viewport lisp
« Reply #16 on: February 23, 2022, 01:35:14 PM »
Hi ronjonp. I can not understand your answer!!! I want to use C:\Users\Admin\AppData\Local\Temp because the dcl file is a temp file it is easyer for me to delete it.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Help - Create new viewport lisp
« Reply #17 on: February 23, 2022, 01:50:32 PM »
Hi ronjonp. I can not understand your answer!!! ...
Chill out...

I'm not sure why you're having problems with this.
Code - Auto/Visual Lisp: [Select]
  1. (defun create_dcl (fn / acadfn)
  2.   (if (null(wcmatch (strcase fn) "*`.DCL"))
  3.     (setq fn (strcat fn ".DCL"))
  4.   )
  5.   (setq path "C:\\Users\\Admin\\AppData\\Local\\Temp\\")
  6.   (if (not (findfile (strcat path fn)))
  7.     ;; create dcl file
  8.     (progn
  9.       (setq fn (strcat path fn)
  10.             fn (open fn "w")
  11.       )

Was your previous username Topographer ?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

PM

  • Guest
Re: Help - Create new viewport lisp
« Reply #18 on: February 23, 2022, 07:02:41 PM »
Hi ronjonp . I replace the part in the code , run the code without errors but when i write CFL to start the lisp nothing happened .  Any idea?

Thanks

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Help - Create new viewport lisp
« Reply #19 on: February 23, 2022, 07:22:10 PM »
Hi ronjonp . I replace the part in the code , run the code without errors but when i write CFL to start the lisp nothing happened .  Any idea?

Thanks
Sorry I don't know what your problem is. Maybe try using (getenv "temp") as your directory assuming that you login as "ADMIN"

Again, was your previous username Topographer ?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC