TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: MSTG007 on November 20, 2017, 10:49:39 AM

Title: Dynamically Best Fit to a Scaled Viewport
Post by: MSTG007 on November 20, 2017, 10:49:39 AM
If I have a page setup for 36x24 and the Viewport is the 36x24. Is there command that can do its best to assign a viewport scale to the object in model space (Xref or what not)?

I hope that makes some sense. Its one of those... its just a thought... lol.
Title: Re: Dynamically Best Fit to a Scaled Viewport
Post by: Dommy2Hotty on November 20, 2017, 05:18:17 PM
I use these (2) that I cobbled together...not the prettiest, nor does it work everytime...I haven't had time to make them better, but they might lead you in the right direction:

Code: [Select]
;==============================================
;SET VIEWPORT BASED ON OBJECTS (1-1/2" = 1'-0")
;==============================================
(defun C:DomVIEWPORT_SetViewPortProfile ()
  (setq CurLayOut (getvar 'ctab))
  (command "pspace")
  (princ "\n*** SETVIEWPORT: PROFILE BY OBJECTS (1-1/2) ***")
  (setq ViewP (entsel "\nSelect VIEWPORT to modify: "))
  (setq ViewPEnt (entget (car ViewP)))
  (setq ViewPID (cdr (assoc 69 ViewPEnt)))
  (if Block
    ()
    (progn
      (setvar 'tilemode 1)
      (setq Block (ssget))
      (setvar 'ctab CurLayOut)
      );progn
    );if
  (command "mview" "lock" "off" ViewP "")
  (command "mspace")
  (setvar "cvport" ViewPID)
  (command "zoom" "object" Block "")
  (command "zoom" "scale" "1/8xp")
  (setq annoscale "1-1/2\" = 1'-0\"")
  (setvar "cannoscale" annoscale)
  (command "pspace")
  (command "mview" "lock" "ON" ViewP "")
  (setq Block nil)
  (princ)
  )

Code: [Select]
;=======================================================
;SET VIEWPORT BASED ON WINDOW SELECTION (1-1/2" = 1'-0")
;=======================================================
(defun C:DomVIEWPORT_SetViewPortProfileByWindow ()
  (setq CurLayOut (getvar 'ctab))
  (command "pspace")
  (princ "\n*** SETVIEWPORT: PROFILE BY WINDOW (1-1/2) ***")
  (setq ViewP (entsel "\nSelect VIEWPORT to modify: "))
  (setq ViewPEnt (entget (car ViewP)))
  (setq ViewPID (cdr (assoc 69 ViewPEnt)))
  (if Block
    ()
    (progn
      (setvar 'tilemode 1)
        (initget 1)
(setq pt1 (getpoint "\n\t***\tPick lower left corner\t*** \n : "))
(initget 1)
(setq pt2 (getcorner pt1 "\n\t***\tPick upper right corner\t*** \n : "))

      (setvar 'ctab CurLayOut)
      );progn
    );if
  (command "mview" "lock" "off" ViewP "")
  (command "mspace")
  (setvar "cvport" ViewPID)
  (command "zoom" "window" pt1 pt2)
  (command "zoom" "scale" "1/8xp")
  (setq annoscale "1-1/2\" = 1'-0\"")
  (setvar "cannoscale" annoscale)
  (command "pspace")
  (command "mview" "lock" "ON" ViewP "")
  (setq Block nil)
  (princ)
  )
Title: Re: Dynamically Best Fit to a Scaled Viewport
Post by: MSTG007 on November 21, 2017, 07:14:25 AM
Thanks a bunch for sharing. I will play around with this and hopefully get it to work! Thank you again!