Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18

Thread: Setting System Variables best Practice

  1. #11
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    568
    Login to Give a bone
    0

    Default Re: Setting System Variables best Practice

    Just me I would look at the foreach method of setting variables just make the list of (variablename value) look at Black box example, as your using the code do you really need all the comments ? Maybe put all the setvar into a text file then easy to do a look up for details if needed.

  2. #12
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,125
    Login to Give a bone
    0

    Default Re: Setting System Variables best Practice

    Addressing... "do you really need all the comments" which I think is directed at my programming style.

    The code I present here is VERY stripped down.

    To me this is not a lot of comments, compared to a comment on every line for big programs like AutoCAD.

    I have 30 or so libraries of functions with up to a hundred functions in each library.

    Good programming practice (for me) is reusing functions.

    I have routines that create header files and search header information too.

    The comments are so even a beginner can read the code and understand what I am doing.

    P=

    I did think of the textfile idea too and thought to put it in it. Just didn't do it yet.

    The routine below was for changing the system variables and having them change back at the end of a routine.

    It could also be used to just change variables without restoring them.
    AutomateCAD

  3. #13
    AUGI Addict madcadder's Avatar
    Join Date
    2000-11
    Location
    Too far from the beach
    Posts
    1,065
    Login to Give a bone
    0

    Default Re: Setting System Variables best Practice

    I did all those long, drawn out comments from SYSVDLG just so I'd have the info right there.
    I don't have to remember it all. I don't have to look it up. And if I want to change something I can find it just by scrolling the file.
    It's not a complete list of all the variables, but it's got quite a few of the most common ones and ones that you may have to figure out what it is exactly that does controls that.
    It could be a lot less...sure, but from double-clicking the tray icon to the template loaded with my huge ACADDOC loading also is 8-9 seconds on an Intel 12th gen.

  4. #14
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,125
    Login to Give a bone
    0

    Default Re: Setting System Variables best Practice

    OK

    Everyone has their own way of programming.

    I used to write LISP code without comments 30 years ago.

    I have evolved since then.

    Every program I write now is exactly the same style.

    Everyone has their own way of programming.

    P=
    AutomateCAD

  5. #15
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,125
    Login to Give a bone
    0

    Default Re: Setting System Variables best Practice

    I had to cut the code down here.

    I had more than 10000 characters for the post.

    In this version I included the ability to use a csv text file to modify system variables.

    You can use different text files for different routines.

    The csv file looks like:

    ATTDIA,0
    DIMFIT,5
    APERTURE,8

    See uploaded files for full code.

    P=

    Code:
    ;___________________________________________________________________________________________________________|
    ;
    ; Written By: Peter Jamtgaard copyright 2024 All Rights Reserved
    ;___________________________________________________________________________________________________________|
    ;
    ; Abstract: This is a library of functions that store and restore system variable (to previous value)
    ; Example to store:      (SystemVariablePut     "DIMFIT" 3)
    ; Example to restore:    (SystemVariableRestore "DIMFIT")
    ; Example to store:      (SystemVariablesPut    (list (list "ATTDIA" 0)(list "DIMFIT" 3)) nil)
    ; Example to read csv    (SystemVariablesPutFromFile "SystemVariablesPut.txt" T)
    ; Example to restore all (SystemVariablesRestore)
    ;___________________________________________________________________________________________________________|
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Command Line Function Header List
    ;___________________________________________________________________________________________________________|
    
    ...
    
    ;* C:SVT2
    ;* Command Line Function to test SystemVariablesPutFromFile
    
    ;* C:SystemVariableTest2
    ;* Command Line Function to test SystemVariablesPutFromFile
    
    ;___________________________________________________________________________________________________________|
    ;
    ; General Function Header List
    ;___________________________________________________________________________________________________________|
    ;
    ;  Function List		Argument1	Argument2 	Arguement3
    
    ;* (CSVFiletoList strFilename strDelimiter)
    ;* Import a CSV File to a list of Sublists
    
    ;* (CSVStringToList  strText strDelimiter)
    ;* Convert CSV String to List
    
    ;* (ErrorTrap symFunction)
    ;* Function to trap errors in expressions
    
    ... Ommitted
    
    ;* (SystemVariablesPutFromFile strTextFile blnClear)
    ;* Function to change the values of system variables from a csv file.
    
    ;* (SystemVariableTextRead strTextFile strDelimiter )
    ;* Function to read a text file with a specified delimiter
    
    ;* (SystemVariableTextToValue lstSublist)
    ;* Function to transform a system variable string value to value in a sublist
    
    ... Ommitted
    
    ;$ End Header
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Command Line Function to test SystemVariablesPutFromFile
    ;___________________________________________________________________________________________________________|
    
    (defun C:SVT2 ()(C:SystemVariableTest2))
    
    (defun C:SystemVariableTest2 (/ )
     (SystemVariablesPutFromFile "SystemVariablesPut.txt" T); <- T means do not store system variables
    )
    
    ;___________________________________________________________________________________________________________ 
    ;
    ; Import a CSV File to a list of Sublists
    ;___________________________________________________________________________________________________________ 
    
    (defun CSVFiletoList (strFileName strDelimiter / filCSVFile lstOfSublists strFullName strText )
     (if (and (setq strFullName (findfile strFileName))
              (setq filCSVFile (open strFilename "r"))
         )
      (progn
       (while (setq strText (read-line filCSVFile))
        (setq lstOfSublists (cons (CSVStringToList strText strDelimiter) lstOfSublists))
       )
       (close filCSVFile)
       (reverse lstOfSublists)
      )
     )
    )
    
    ;___________________________________________________________________________________________________________ 
    ;
    ; Convert CSV String to List **
    ;___________________________________________________________________________________________________________ 
    
    (defun CSVStringToList  (strText strDelimiter / intPosition lstStrings)
     (while (setq intPosition (vl-string-search strDelimiter strText 0))
      (setq lstStrings  (cons (substr strText 1 intPosition) lstStrings)
            strText     (substr strText (+ intPosition 1 (strlen strDelimiter)))
      )
     )
     (if lstStrings
      (reverse (cons strText lstStrings))
      (list strText)
     )
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to trap errors in expressions
    ;___________________________________________________________________________________________________________|
    
    (defun ErrorTrap (symFunction / objError result)
     (if (not
          (vl-catch-all-error-p
           (setq objError (vl-catch-all-apply
                          '(lambda (X)(set X (eval symFunction)))
                           (list 'result)))))
      (if result result 'T)
     )
    )
    
    ... Ommitted
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to change the values of system variables from a csv file.
    ;___________________________________________________________________________________________________________|
    
    (defun SystemVariablesPutFromFile (strTextFile blnClear / lstOfSystemVariables strFullName  )
     (if (and (setq strFullName (findfile strTextFile))
              (setq lstOfSystemVariables (SystemVariableTextRead strFullName "," ))
         )
      (SystemVariablesPut lstOfSystemVariables blnClear)
     )
    )
    
    ... Ommitted
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to read a text file with a specified delimiter
    ;___________________________________________________________________________________________________________|
    
    (defun SystemVariableTextRead (strTextFile strDelimiter / lstOfSystemVariables strFullName)
     (if (and (setq strFullName          (findfile strTextFile))
              (setq lstOfSystemVariables (CSVFileToList strFullName strDelimiter))
              (setq lstOfSystemVariables (mapcar 'SystemVariableTextToValue lstOfSystemVariables))
              (setq lstOfSystemVariables (vl-remove 'nil lstOfSystemVariables))
              (/= (length lstOfSystemVariables) 0)
         )
      lstOfSystemVariables
     )
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to transform a system variable string value to value in a sublist
    ;___________________________________________________________________________________________________________|
    
    (defun SystemVariableTextToValue (lstSublist / strSystemVariable strValue symType Value1 Value2)
     (if (and (setq strSystemVariable (car  lstSublist))
              (setq Value1            (getvar strSystemVariable))
              (errortrap             '(setvar strSystemVariable Value1));<- Is not read only
              (setq strValue          (cadr lstSublist))
              (setq symType           (type Value1))            
         )
      (progn
       (cond ((= symType 'INT) (setq Value2 (atoi strValue)) )
             ((= symType 'LIST)(setq Value2 (eval (read strValue))) )
             ((= symType 'REAL)(setq Value2 (atof strValue)) )
             ((= symType 'STR) (setq Value2 strValue) )
       )
       (list strSystemVariable Value2)
      )
     )
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Global variable of modelspace object of active document
    ;___________________________________________________________________________________________________________|
    
    (setq objGlobalModelSpace (vla-get-modelspace 
                               (vla-get-activedocument 
                                (vlax-get-acad-object))))
    
    (princ "!")
    (vl-load-com)
    Attached Files Attached Files
    Last edited by peter; 2024-10-13 at 02:10 PM.
    AutomateCAD

  6. #16
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    568
    Login to Give a bone
    0

    Default Re: Setting System Variables best Practice

    Why not use a dwt that has a lot of the variables set ? In my lisp code just set the variables required for the step in the code, most obvious is osnap.

  7. #17
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,125
    Login to Give a bone
    0

    Default Re: Setting System Variables best Practice

    OK,

    But what if multiple people work on the same drawing with different sysvar preferences?

    You could link the csv file to a login name
    AutomateCAD

  8. #18
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,743
    Login to Give a bone
    0

    Default Re: Setting System Variables best Practice

    Quote Originally Posted by madcadder View Post
    <snip>
    ... from double-clicking the tray icon to the template loaded with my huge ACADDOC loading also is 8-9 seconds on an Intel 12th gen.
    Wonder if using Autodesk's SYSVARMONITOR would provide better performance?
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 5860, Xeon W7-2495X, 128GB RAM, Dual PCIe 4.0 M.2 SSD (RAID 0), 20GB NVIDIA RTX 4000 ADA

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Setting system variables inside templates
    By rbilger in forum AutoCAD Customization
    Replies: 1
    Last Post: 2009-07-09, 06:40 PM
  2. Permanently setting system variables (MIRRTEXT, etc.)
    By GJEllis in forum AutoCAD General
    Replies: 6
    Last Post: 2008-03-10, 05:52 PM
  3. Setting up system variables!
    By pferreira in forum AutoCAD Tips & Tricks
    Replies: 0
    Last Post: 2006-06-30, 10:11 PM
  4. Setting up mapdigisetup variables in vba?
    By norrin in forum AutoCAD Map 3D - General
    Replies: 4
    Last Post: 2005-11-02, 03:05 PM
  5. Save reminder - system setting or project setting?
    By patricks in forum Revit Architecture - General
    Replies: 4
    Last Post: 2005-07-08, 01:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •