Jump to content

How to combine several SETVAR commands


KarolR

Recommended Posts

If you had to change a whole bunch of them, might you want to save and load a customized .SVF (system variable file)

within the lisp, making certain that you returned it to the normal settings at the end of the lisp,

or in case of a user induced error or escape?

 

Just thinking out loud, as I am illisperate. :huh:

Link to comment
Share on other sites

I guess that's another option :lol:... Never considered doing that, honestly (not knocking it, just saying). :beer:

 

In my limited experience (I'm just an entry level CAD Technician, who didn't know what a Defun was as of Fall 2009), the most efficient method is a combination of setting a solid Profile (to cover those System Variables that are stored to the Registry), a solid Drawing Template (.DWT) to handle those which are stored within the Drawing itself, and LISP (as noted above, usually implemented via AcadDoc.lsp) to handle those which are User-defined and not in contest with your internal, or client standards... Just my $0.02 :thumbsup:

Link to comment
Share on other sites

(mapcar 'setvar '(coords hpassoc) (list 2 1))

 

Yes this method will work, but just a couple of things (and that is no reflection on you, my friend :))....

 

I very much dislike this method, primarily because it separates the system variable, and the desired value into two separate lists, rather than one list pair (i.e., '(variable value) ) as shown in my example above.

 

This is _not_ purely an opinion rooted in code maintenance, as there is also an (albeit small) performance advantage to keeping the variable value list pair together as well... Demonstrated here in this little speed test:

 

Test functions:

(vl-load-com)

(defun _Mapcar (vars vals)
 (mapcar 'setvar vars vals)
)

(defun _Foreach (pairs)
 (foreach x pairs
   (vl-catch-all-apply 'setvar x)
 )
)

Speed test results:

 

_$ (bench '(_Mapcar) (list '(clayer) (list "0")) 1000)

_MAPCAR
Elapsed: 796
Average: 0.7960


_$ (bench '(_Foreach) (list (list '(clayer "0"))) 1000)

_FOREACH
Elapsed: 780
Average: 0.7800

Link to comment
Share on other sites

(vl-load-com)

(foreach x (list '(coords 2)
                '(hpassoc 1)
                ;; <-- More sysvars
          )
 (vl-catch-all-apply 'setvar x)
)

What is the difference between: (list 'a 'b 'c), which gives a list (a b c),

And: (list a b c), which also gives (a b c).

I don't know what for is the quote (') function, and why do i need it here, in the example code above

Link to comment
Share on other sites

What is the difference between: (list 'a 'b 'c), which gives a list (a b c),

And: (list a b c), which also gives (a b c).

I don't know what for is the quote (') function, and why do i need it here, in the example code above

 

If you know all of the values that are going to be supplied within that list, then there's not need to call the List function as I demonstrate in that example. To do so simply minimizes the number of time List is actually being called.

 

My reason for using a call to the List function is so that I can supply known values (the Quoted items), as well as values that require evaluation (meaning something programmatic is being performed within the List call itself).

 

Consider this example:

(vl-load-com)

(foreach x
        (list '(coords 2)
              '(hpassoc 1)
              (list 'osmode
                    (cond
                      ((= "user1" (setq user (getvar 'loginname)) 255)
                       ((= "user2" user) 35)
                       ((= "user3" user) 39)
                       ((= "user4" user) 243)
                       (T (getvar 'osmode))                            ; <-- Not one of my users
                      )
                    )
              )
              ;; <-- More sysvars
        )
 (vl-catch-all-apply 'setvar x)
)

Link to comment
Share on other sites

Another item that I include in my System Variables that would require evaluation when AcadDoc.lsp is being loaded is the AUTOMATICPUB System Variable, so that when the DWGPREFIX includes our sheets directory, this is enabled, and when in our model directory, this is disabled. :thumbsup:

Link to comment
Share on other sites

What is the difference between: (list 'a 'b 'c), which gives a list (a b c),

And: (list a b c), which also gives (a b c).

I don't know what for is the quote (') function, and why do i need it here, in the example code above

 

This old explanation may help:

http://www.cadtutor.net/forum/showthread.php?38732-Selecting-all-unclosed-polylines&p=258390#post258390

Link to comment
Share on other sites

This old explanation may help:

http://www.cadtutor.net/forum/showthread.php?38732-Selecting-all-unclosed-polylines&p=258390#post258390

 

... Another excellent post, Lee. :beer:

Link to comment
Share on other sites

What is (vl-load-com)? should i insert it in the code?

Is the vl a function?

 

Only if it's required by your code, that is if it contains any VLISP commands. Any programs which contain only LISP commands will not need this. Still it won't hurt to have it in there if you're in doubt.

 

Lot's of people set this to install automatically when AutoCAD opens. I prefer low overhead and only load it when needed. And if it's already loaded the system will just ignore it if you call it again so it's pretty safe.

 

Since this post is about setting system variables with code, and I think it was already mentioned, and in that case I will reiterate, it's a good practice to assign the original setting to some variable to hold for you and when your LISP program has completed, reset them back to their original state. If your programs are used by other people you will soon feel their wrath if your code leaves their pickbox at zero, or osmode to something other than what they are accustomed to using. A good error handling routine is also beneficial so that even if the code crashes or someone hits escape during execution, everything you changed gets set back to it's original value. Just my 2¢ worth.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...