Author Topic: Setting System Variables  (Read 4287 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10395
Setting System Variables
« on: November 12, 2003, 08:44:21 PM »
I'm sure this has been covered so if someone could point me to the routine.

A routine run when each drawing opens & resets system variables to the values you expect
or prefer. Why I get drawings with ANGDIR set to 1 or LUPREC set to 0 I'll never know.

User profiles take care of some but is there a way to reset to system defaults or a lisp
to set to you faves?

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Mark

  • Custom Title
  • Seagull
  • Posts: 28708
Setting System Variables
« Reply #1 on: November 12, 2003, 09:28:07 PM »
this is what I use, it's called from my custom menu so it runs when ever I open a dwg.
Code: [Select]

;;; variable setting mechanism
;;; called from 'CustomMenu.mnl'

(defun set-vars (/ var val)

  (setq var '(
              "expert"    ; 4
              "blipmode"  ; 0
              "lunits"    ; 2
              "luprec"    ; 4
              "auprec"    ; 4
              "cmddia"    ; 1
              "cmdecho"   ; 1
              "coords"    ; 2
              "dimsho"    ; 1
              "dragp1"    ; 10
              "dragp2"    ; 25
              "facetres"  ; 2
              "filedia"   ; 1
              "filletrad" ; 0
              "grips"     ; 1
              "gripsize"  ; 5
              "highlight" ; 1
              "isolines"  ; 4
              "maxactvp"  ; 5
              "maxsort"   ; 200
              "mirrtext"  ; 0
              "osmode"    ; 73
              "maxactvp"  ; 50
              "pickadd"   ; 1
              "pickauto"  ; 1
              "pickdrag"  ; 0
              "pickfirst" ; 1
              "savetime"  ; 30
              "splframe"  ; 0
              "textfill"  ; 1
              "textqlty"  ; 50
              "textsize"  ; 0.18
              "ucsfollow" ; 0
              "ucsicon"   ; 0
              "visretain" ; 1
              )
        ); setq

  (setq val '(
              4    ; "expert"    
              0    ; "blipmode"  
              2    ; "lunits"    
              4    ; "luprec"    
              4    ; "auprec"    
              1    ; "cmddia"    
              1    ; "cmdecho"  
              2    ; "coords"    
              1    ; "dimsho"    
              10   ; "dragp1"    
              25   ; "dragp2"    
              2    ; "facetres"  
              1    ; "filedia"  
              0    ; "filletrad"
              1    ; "grips"    
              5    ; "gripsize"  
              1    ; "highlight"
              4    ; "isolines"  
              5    ; "maxactvp"  
              200  ; "maxsort"  
              0    ; "mirrtext"  
              73   ; "osmode"    
              50   ; "maxactvp"  
              1    ; "pickadd"  
              1    ; "pickauto"  
              0    ; "pickdrag"  
              1    ; "pickfirst"
              30   ; "savetime"  
              0    ; "splframe"  
              1    ; "textfill"  
              50   ; "textqlty"  
              0.18 ; "textsize"  
              0    ; "ucsfollow"
              0    ; "ucsicon"  
              1    ; "visretain"
              )
        ); setq

  (if
    (eq (length var)(length val))
    (mapcar 'setvar var val)
    ; else
    (alert "There is a problem with the variables settings")
    )

  (princ)

  )
TheSwamp.org  (serving the CAD community since 2003)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10395
Setting System Variables
« Reply #2 on: November 12, 2003, 09:59:42 PM »
Oh, Thank You Sir.   :D  :D  :D


CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Dave

  • Guest
Setting System Variables
« Reply #3 on: November 20, 2003, 08:30:24 AM »
The way we do this in our software is via INI files and using (dos_getini).  Foreach value we also store the data type to ensure proper conversion (everything coming out of dos_getini is string values).  Just split the value string to separate the value from the data type.

[Sysvars]
LUNITS=2,INT
LUPREC=6,INT
...

Then use (foreach) on the loaded vars=values list to set them.  It runs very fast and works very well.  The only exception is viewres which requires a command pipe call instead of a setvar call.
Code: [Select]

(foreach varname (dos_getini "Sysvars" nil $inifilename)
  (setq valuelist (dos_getini "Sysvars" varname $inifilename)
          valset (dos_strtokens valuelist ",")
          value (car valset)
          datatype (cadr valset)
  )
  (if (= (strcase varname) "VIEWRES")
    (vl-cmdf "_.viewres" "_y" (atoi value))
    (cond
      ( (= datatype "INT") (setvar varname (atoi value)) )
      ( (= datatype "REAL") (setvar varname (atof value)) )
      ( T (setvar varname value) )
    )
  )
)

This is not the exact chunk of code, but it's enough to give the idea.  It lets the user configure the values and add/remove vars at will since it's not hard-coded.  Just 2 cents. :shock:

CAB

  • Global Moderator
  • Seagull
  • Posts: 10395
Setting System Variables
« Reply #4 on: January 07, 2004, 05:03:18 PM »
Well I'm stuck again.. :(
Mark I couldn't resist changing you routine.
The "I got ot do it my way" syndrome I guess.
I changed to dotted pairs to keep the variables next to the values for
readability sake but I am having problems with a couple of variables
I am adding to the list.

"dcprops" wants a YES or NO answer at the command prompt and I cant
get it to work with my lisp.

Also "insbase" '(0 0 0) needs a 3D point and  "snapbase" (list 0 0)
needs a 2D point.

How can I make there work with the following code? (anybody)
 PS haven't finished the var list yet

Code: [Select]

(defun ACADset_vars (/ var)

  (setq var '(
              ("angdir"    . 0 )  ; CCW
              ("angbase"   . 0 )  ;
              ("apbox"     . 0 )  ; Aperture box off 0
              ("aperture"  . 10 ) ; zone of detection
              ("aunits"    . 0 )  ; 0 = degrees 4 = survey
              ("auprec"    . 4 )  ; no. od decimal places
              ("autosnap"  . 7 )  ;
     
              ("blipmode"  . 0 )  ; o = blips off
     
              ("chammode"  . 0 )  ; require 2 distances
              ("cursorsize" . 5 )  ; size of cross
              ("cmddia"    . 1 )
              ("cmdecho"   . 1 )
              ("coords"    . 2 )
     
;              ("dcprops"   . "OFF" )  ;ON= doubleclick on text opens the properties window
              ("dimaso"    . 1 )  ;
              ("dimsho"    . 1 )
              ("dragmode"  . 2 )  ; display outline
              ("dragp1"    . 10 )
              ("dragp2"    . 25 )
     
              ("edgemode"  . 1 )  ; trim to extension
              ("expert"    . 4 )
     
              ("gridmode"  . 0 )  ; grid off
              ("grips"     . 1 )  ;
              ("gripsize"  . 3 )  ; grip box size
     
              ("facetres"  . 2 )
              ("filedia"   . 1 )
              ("filletrad" . 0 )
              ("fillmode"  . 1 )  ;
           
              ("highlight" . 1 )
     
;              ("insbase"   . '(0 0 0))  ;
              ("isolines"  . 4 )
     
              ("limcheck"  . 0 )  ; 0= allow create obj outside limites
              ("lunits"    . 4 )  ; 4=Arch  2=decimal
              ("luprec"    . 5 )  ; decimal places displayed for linear
     
              ("maxactvp"  . 50 ) ; max viewport to be regenerated
              ("maxsort"   . 500) ; max num of layers to sort in layer manager
              ("mbuttonpan" . 1)  ;
              ("measurement" . 0)  ; English
              ("measureinit" . 0)  ; English
              ("mirrtext"  . 0 )  ; 1=mirror text 0=backwards test
     
              ("offsetgaptype" . 0 )  ;
              ("osmode"    . 73 )
     
              ("pickadd"   . 1 )
              ("pickauto"  . 1 )
              ("pickbox"   . 3 )  ; the pick box size
              ("pickdrag"  . 0 )
              ("pickfirst" . 1 )
              ("pickstyle" . 1 )  ;
              ("plinegen"  . 0 )  ;
              ("plinetype" . 2 )  ;
              ("plinewid"  . 0 )  ; pline width
              ("plotrotmode" . 1)  ; align lower left plot area with LL of paper

              ("qtextmode" . 0 )  ; 1=display box ILO text
     
              ("regenmode" . 1 )
     
              ("savetime"  . 30 ) ; minutes between auto save 0=no auto save
;              ("snapbase"  . (list 0 0)) ; hatch base point
              ("splframe"  . 0 )
     
              ("textfill"  . 1 )  ; plot with text filled
              ("textqlty"  . 50 ) ; text resolution of TT font while plotting
              ("textsize"  . 5 )  ; default text size
     
              ("ucsfollow" . 0 )
              ("ucsicon"   . 0 )  ; 0=no display 3=display icon at origin
     
              ("visretain" . 1 )  ; retain layer state
              )
        ); setq


  (mapcar '(lambda (x)
     (setvar(car x) (cdr x))
 )
 var)

  (princ)

  ) ;; EOF
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

daron

  • Guest
Setting System Variables
« Reply #5 on: January 07, 2004, 05:09:38 PM »
dcprops is not a variable. You crash there. I'd recommend not using it or making sure it doesn't load on a file that is not saved, like the startup drawing1.dwg.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10395
Setting System Variables
« Reply #6 on: January 07, 2004, 06:17:15 PM »
Thanks Daron I'll remove that one from the list.

How about the others that require points, any idea how
I can get them to work?

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

SMadsen

  • Guest
Setting System Variables
« Reply #7 on: January 07, 2004, 06:25:22 PM »
Make'em proper lists instead of dotted pairs.

Not useful:
(cdr '("insbase"   . '(0 0 0))) = (QUOTE (0 0 0))

Useful:
(cdr (list "insbase"  0.0 0.0 0.0)) = (0.0 0.0 0.0)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10395
Setting System Variables
« Reply #8 on: January 07, 2004, 06:55:30 PM »
Ok, this working, but is it the proper way to handle the list?

Code: [Select]


(defun ACADset_vars (/ var)

  (setq var (list
              (list "angbase"     0 )  ;
              (list "angdir"      0 )  ; CCW
              (list "apbox"       0 )  ; Aperture box off 0
              (list "aperture"    10 ) ; zone of detection
              (list "aunits"      0 )  ; 0 = degrees 4 = survey
              (list "auprec"      4 )  ; no  od decimal places
              (list "autosnap"    7 )  ;
     
              (list "blipmode"    0 )  ; o = blips off
     
              (list "chammode"    0 )  ; require 2 distances
              (list "cmddia"      1 )
              (list "cmdecho"     1 )
              (list "coords"      1 )
              (list "cursorsize"  5 )  ; size of cross
     
              (list "dimaso"      1 )  ;
              (list "dimsho"      1 )
              (list "dragmode"    2 )  ; display outline
              (list "dragp1"      10 )
              (list "dragp2"      25 )
     
              (list "edgemode"    1 )  ; trim to extension
              (list "expert"      4 )
     
              (list "facetres"    2 )
              (list "filedia"     1 )
              (list "filletrad"   0 )
              (list "fillmode"    1 )  ;
           
              (list "gridmode"    0 )  ; grid off
              (list "grips"       1 )  ;
              (list "gripsize"    3 )  ; grip box size
     
              (list "highlight"   1 )
     
              (list "insbase"  (list 0 0 0))  ;
              (list "isolines"    4 )
     
              (list "limcheck"    0 )  ; 0= allow create obj outside limites
              (list "lunits"      4 )  ; 4=Arch  2=decimal
              (list "luprec"      5 )  ; decimal places displayed for linear
     
              (list "maxactvp"    50 ) ; max viewport to be regenerated
              (list "maxsort"     500) ; max num of layers to sort in layer manager
              (list "mbuttonpan"  1)  ;
              (list "measurement" 0)  ; English
              (list "measureinit" 0)  ; English
              (list "mirrtext"    0 )  ; 1=mirror text 0=backwards test
     
              (list "offsetgaptype" 0 )  ;
              (list "osmode"      175 )
     
              (list "pickadd"     1 )
              (list "pickauto"    1 )
              (list "pickbox"     3 )  ; the pick box size
              (list "pickdrag"    0 )
              (list "pickfirst"   1 )
              (list "pickstyle"   1 )  ;
              (list "plinegen"    0 )  ;
              (list "plinetype"   2 )  ;
              (list "plinewid"    0 )  ; pline width
              (list "plotrotmode" 1)  ; align lower left plot area with LL of paper
              (list "polarmode"   1 )  ;
              (list "projmode"    1 )  ;
              (list "proxygraphics" 1)  ;
              (list "proxynotice"   1)  ;
              (list "proxyshow"     1)  ;

              (list "qtextmode"   0 )  ; 1=display box ILO text
     
              (list "regenmode"   1 )
     
              (list "savetime"    30 ) ; minutes between auto save 0=no auto save
              (list "sdi"          0 )
              (list "snapang"     0 )
              (list "snapbase"  (list 0 0)) ; hatch base point
              (list "snapisopair" 0 )
              (list "snapmode"    0 )
              (list "snapstyl"    0 )
              (list "snaptype"    0 )
              (list "snapunit"  (list 1 1))
              (list "sortents"    96)
              (list "splframe"    0 )
     
              (list "textfill"    1 )  ; plot with text filled
              (list "textqlty"    50 ) ; text resolution of TT font while plotting
              (list "textsize"    5 )  ; default text size
              (list "tooltips"    1 )
              (list "trimmode"    1 )
              (list "tstackalign" 1 )
              (list "tstacksize"  70 )
     
              (list "unitmode"    0 )
              (list "ucsfollow"   0 )
              (list "ucsicon"     0 )  ; 0=no display 3=display icon at origin
     
              (list "worldview"   1 )
     
              (list "visretain"   1 )  ; retain layer state
     
              (list "zoomfactor"  10 )
              )
        ); setq

  (mapcar '(lambda (x)
     (setvar(car x) (cadr x))
 )
 var)

  (princ)

) ;; EOF
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16867
  • Superior Stupidity at its best
Setting System Variables
« Reply #9 on: January 07, 2004, 10:15:03 PM »
Seems ok to me....
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

SMadsen

  • Guest
Setting System Variables
« Reply #10 on: January 08, 2004, 04:24:20 AM »
CAB,
Dotted pairs are cool for this sort of thing. What I meant was that where CDR is supposed to return a list you should use a proper list and where CDR is supposed to return an atom you should continue to use dotted pairs.

That's why entity lists look like they do. Look at the difference between a group code 70 and code 10. CDR behaves differently when used on lists and dotted pairs:

(cdr '("insbase" 0.0 0.0 0.0)) = (0.0 0.0 0.0)
(cdr '("plinetype" . 2)) = 2

Code: [Select]
(defun ACADset_vars (/ var)

  (setq var '(("angbase" . 0)      ;
              ("angdir" . 0)       ; CCW
              ("apbox" . 0)        ; Aperture box off 0
              ("aperture" . 10)    ; zone of detection
              ("aunits" . 0)       ; 0 = degrees 4 = survey
;;....<cut>
              ("insbase"  0 0 0)   ;
              ("isolines" . 4)
;;....<cut>
              ("snapbase" 0 0)     ; hatch base point
              ("snapisopair" . 0)
;;....<cut>
              ("zoomfactor" . 10)
             );_ var
  );_ setq

  (mapcar '(lambda (x)
         (setvar(car x) (cdr x))
        )
        var)

  (princ)

) ;_ EOF

CAB

  • Global Moderator
  • Seagull
  • Posts: 10395
Setting System Variables
« Reply #11 on: January 08, 2004, 09:21:02 AM »
Well you first message went right over my head.

So the solution is to use dotted pairs for those items that get the atom.
And use a list (setq a '(   ("snapbase" 0 0)    )) when a list needs to be returned.
 where (cdr (car a)) returns (0 0) which is a point list
and this will work
  (setq a (car '(("snapbase" 0 0)) )))
  (setvar (car a) (cdr a))


So here is the revise routine as dotted pairs:

Code: [Select]
;;; variable setting mechanism
;;; called from 'AlansAutoLoad.lsp'
;;;
;;;  Note, vars that need point data are not entered as dotted pairs
;;;    Example  ("snapbase" 0 0)
;;;
(defun ACADset_vars (/ var)

  (setq var '(
              ( "angbase"   . 0 )  ;
              ( "angdir"    . 0 )  ; CCW
              ( "apbox"     . 0 )  ; Aperture box off 0
              ( "aperture"  . 10 ) ; zone of detection
              ( "aunits"    . 0 )  ; 0 = degrees 4 = survey
              ( "auprec"    . 4 )  ; no  od decimal places
              ( "autosnap"  . 7 )  ;
     
              ( "blipmode"  . 0 )  ; o = blips off
     
              ( "chammode"  .  0 )  ; require 2 distances
              ( "cmddia"    .  1 )
              ( "cmdecho"   .  1 )
              ( "coords"    .  1 )
              ( "cursorsize" . 5 )  ; size of cross
     
              ( "dimaso"    .  1 )  ;
              ( "dimsho"    .  1 )
              ( "dragmode"  .  2 )  ; display outline
              ( "dragp1"    .  10 )
              ( "dragp2"    .  25 )
     
              ( "edgemode"  .  1 )  ; trim to extension
              ( "expert"    .  4 )
     
              ( "facetres"  .  2 )
              ( "filedia"   .  1 )
              ( "filletrad" .  0 )
              ( "fillmode"  .  1 )  ;
           
              ( "gridmode"  .  0 )  ; grid off
              ( "grips"     .  1 )  ;
              ( "gripsize"  .  3 )  ; grip box size
     
              ( "highlight" .  1 )
     
              ( "insbase"  0 0 0)  ;
              ( "isolines"  .  4 )
     
              ( "limcheck"  .  0 )  ; 0= allow create obj outside limites
              ( "lunits"    .  4 )  ; 4=Arch  2=decimal
              ( "luprec"    .  5 )  ; decimal places displayed for linear
     
              ( "maxactvp"  .  50 ) ; max viewport to be regenerated
              ( "maxsort"   .  500) ; max num of layers to sort in layer manager
              ( "mbuttonpan" . 1)  ;
              ( "measurement" . 0)  ; English
              ( "measureinit" . 0)  ; English
              ( "mirrtext"  .  0 )  ; 1=mirror text 0=backwards test
     
              ( "offsetgaptype" . 0 )  ;
              ( "osmode"    .  175 )
     
              ( "pickadd"   .  1 )
              ( "pickauto"  .  1 )
              ( "pickbox"   .  3 )  ; the pick box size
              ( "pickdrag"  .  0 )
              ( "pickfirst" .  1 )
              ( "pickstyle" .  1 )  ;
              ( "plinegen"  .  0 )  ;
              ( "plinetype" .  2 )  ;
              ( "plinewid"  .  0 )  ; pline width
              ( "plotrotmode" . 1)  ; align lower left plot area with LL of paper
              ( "polarmode"  . 1 )  ;
              ( "projmode"  .  1 )  ;
              ( "proxygraphics" . 1)  ;
              ( "proxynotice" .  1)  ;
              ( "proxyshow"   .  1)  ;

              ( "qtextmode"  . 0 )  ; 1=display box ILO text
     
              ( "regenmode"  . 1 )
     
              ( "savetime"   . 30 ) ; minutes between auto save 0=no auto save
              ( "sdi"        .  0 )
              ( "snapang"    . 0 )
              ( "snapbase"  0 0) ; hatch base point
              ( "snapisopair" . 0 )
              ( "snapmode"   . 0 )
              ( "snapstyl"   . 0 )
              ( "snaptype"   . 0 )
              ( "snapunit"   1 1)  ;
              ( "sortents"   . 96)
              ( "splframe"   . 0 )
     
              ( "textfill"   . 1 )  ; plot with text filled
              ( "textqlty"   . 50 ) ; text resolution of TT font while plotting
              ( "textsize"   . 5 )  ; default text size
              ( "tooltips"   . 1 )
              ( "trimmode"   . 1 )
              ( "tstackalign" . 1 )
              ( "tstacksize"  . 70 )
     
              ( "unitmode"   . 0 )
              ( "ucsfollow"  . 0 )
              ( "ucsicon"    . 0 )  ; 0=no display 3=display icon at origin
     
              ( "worldview"  . 1 )
     
              ( "visretain"  . 1 )  ; retain layer state
     
              ( "zoomfactor" . 10 )
              )
        ); setq

  (mapcar '(lambda (x)
     (setvar(car x) (cdr x))
 )
 var)
  (prompt "\nACADSet_Variables has set system variables to your preset values.")
  (princ)

) ;; EOF
;;  remove the comment from the next line to run as soon as it is loaded
;(ACADset_vars)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

SMadsen

  • Guest
Setting System Variables
« Reply #12 on: January 08, 2004, 09:29:44 AM »
Exactemento!  :)