erratic Posted February 25, 2010 Posted February 25, 2010 simply put - I am trying to get some lisp together that will save the current AUTOSNAP value and then add "8" to that value (to turn on polar tracking) and then reset the AUTOSNAP value to its previous state. this is probably an easy task - just one that I am not keen on doing properly... I usually look around for code and try to mash it together with what I have/ want and go the trial run route... essentially I am having no luck. I have basic/ intermediate (maybe not) LISP abilities and this has me stumped... any suggestions??? Quote
Lee Mac Posted February 25, 2010 Posted February 25, 2010 How about: (setvar "AUTOSNAP" (boole 6 (getvar "AUTOSNAP") ) Quote
alanjt Posted February 25, 2010 Posted February 25, 2010 (setvar 'autosnap (+ 6 (getvar 'autosnap))) Quote
alanjt Posted February 25, 2010 Posted February 25, 2010 How about: (setvar "AUTOSNAP" (boole 6 (getvar "AUTOSNAP") ) Oh yeah, that would help. I'm dumb. Quote
Lee Mac Posted February 25, 2010 Posted February 25, 2010 Oh yeah, that would help. I'm dumb. You said it Quote
alanjt Posted February 25, 2010 Posted February 25, 2010 You said it I remind the guys at work of that every day. Sadly, they keep bothering me. Quote
erratic Posted February 25, 2010 Author Posted February 25, 2010 Thanks guys! That worked great! I just had to put a save variable ahead of the setvar adjustment and a restore after my block insertion in order to reset the previous setting, but what you gave me works just fine - and much simpler than the thoughts I was previously having in trying to make that work... once again - many thanks!!! Quote
Lee Mac Posted February 25, 2010 Posted February 25, 2010 With my example you shouldn't need to store the variable - by the nature of the boole test - it acts as a toggle. I would make it into a sub-function and call it once before, and once after Quote
Lee Mac Posted February 25, 2010 Posted February 25, 2010 To think about how the boole function will process: The AUTOSNAP is bit-coded (taking values 0-32) - and lets say, for this example, it has a value of 63 (the initial value). In Binary, 63 is: | 32 | 16 | 8 | 4 | 2 | 1 | ------------------------------------- | 1 | 1 | 1 | 1 | 1 | 1 | = 63 We are using the boole function with the operator bits 2+4 = 6, providing us with an XOR behaviour, i.e. either bit one is True OR bit two is True, but both cannot be true. Hence when we apply (boole 6 63 we get: | 32 | 16 | 8 | 4 | 2 | 1 | ------------------------------------- | 1 | 1 | 1 | 1 | 1 | 1 | = 63 | 0 | 0 | 1 | 0 | 0 | 0 | = 8 ------------------------------------- | 1 | 1 | 0 | 1 | 1 | 1 | = 55 As both contain the bit code 8, and so this does not return True (1). If we now apply the same operation again, to our returned value of 55: | 32 | 16 | 8 | 4 | 2 | 1 | ------------------------------------- | 1 | 1 | 0 | 1 | 1 | 1 | = 55 | 0 | 0 | 1 | 0 | 0 | 0 | = 8 ------------------------------------- | 1 | 1 | 1 | 1 | 1 | 1 | = 63 We get back to our value of 63, as now all bits return True (1), for the XOR operation. Hope this helps with the understanding of the boole function, as not too many people use it that often I find. Lee Quote
erratic Posted February 26, 2010 Author Posted February 26, 2010 ...Hope this helps with the understanding of the boole function, as not too many people use it that often I find.Lee Yeah - I can't say that I was familiar with that function, but you explained it quite well... being that I was unfamiliar I just did the variable save/ restore technique and just used your line of code to make the adjustment... basically I wanted to have the polar tracking toggle when the command paused at the rotation stage of a block insertion - all in all it worked. Here is what I did: [indent](DEFUN C:DRP () (SETQ ATD (GETVAR "ATTDIA")) (SETQ CLY (GETVAR "CLAYER")) (SETQ OSM (GETVAR "OSMODE")) (SETQ OTM (GETVAR "ORTHOMODE")) (SETQ OGDMS (GETVAR "DIMSCALE")) [b](C:SL)[/b] (SETVAR "ATTDIA" 1) (SETVAR "ATTREQ" 1) (SETVAR "OSMODE" 545) (SETVAR "ORTHOMODE" 1) [b](TILEZERO) (PTRACK)[/b] (SETQ DMS (GETVAR "DIMSCALE")) (COMMAND "INSERT" "08DROP" PAUSE DMS "" PAUSE) (SETVAR "AUTOSNAP" AS1) (SETVAR "ATTDIA" ATD) (SETVAR "CLAYER" CLY) (SETVAR "OSMODE" OSM) (SETVAR "ORTHOMODE" OTM) (SETVAR "DIMSCALE" OGDMS) (PRINC) );END DEFUN [b](C:SL)[/b] is just my command for making the selected entities layer current (I use it a lot for ensuring certain blocks are inserted on the correct layer with out having to go into any dialogue boxes) I know that this can be done better, but I do not have the LISP skills for that code as of yet [/indent] [indent][indent][i]it would work much better if the initial pick used for the[/i][i] insertion point just picked up the data from the entity selected[/i][i] and THEN adjusted the current layer - as it is now I have to pick[/i][i] the entity for setting the current layer for insertion and then[/i][i] again for the actual insertion point. As you can see I like to[/i][i] build layer adjustments into my commands to add to[/i][i] productivity. If you have any thoughts on this comment of mine[/i][i] please feel free.[/i] [/indent] [/indent] [indent][u]functions:[/u][b] (TILEZERO)[/b] makes sure that the dimscale is adjusted in case the user is inserting the block in paperspace - details:[indent](DEFUN TILEZERO () (IF (= (GETVAR "TILEMODE") 0) (SETVAR "DIMSCALE" 1))) [/indent] [b](PTRACK)[/b] is of course the bit of code I used from you... details: [indent](DEFUN PTRACK () (SETQ AS1 (GETVAR "AUTOSNAP")) (SETVAR "AUTOSNAP" (BOOLE 6 (GETVAR "AUTOSNAP") )) [/indent] [/indent] functions: I like to set these type of inner working tools up as non-c: commands and just repeat the corresponding (xxxx) where needed. I find that it works great - it keeps me from re-typing the same code all over the place. Thanks again for your help! Quote
Lee Mac Posted February 26, 2010 Posted February 26, 2010 You could perhaps use something like this, I haven't tested it, just tidied up your setvar/getvar statements and added an error handler: (DEFUN C:DRP (/ *error* VarLst OldVars) (defun *error* (msg) (and OldVars (mapcar (function setvar) VarLst OldVars)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ)) (setq VarLst '("ATTDIA" "ATTREQ" "CLAYER" "OSMODE" "ORTHOMODE" "DIMSCALE") OldVars (mapcar (function getvar) VarLst)) (C:SL) (mapcar (function setvar) '("ATTDIA" "ATTREQ" "OSMODE" "ORTHOMODE") '(1 1 545 1)) (TILEZERO) (PTRACK) (COMMAND "_.-INSERT" "08DROP" PAUSE (getvar "DIMSCALE") "" PAUSE) (PTRACK) (mapcar (function setvar) VarLst OldVars) (PRINC)) (DEFUN TILEZERO nil (IF (= (GETVAR "TILEMODE") 0) (SETVAR "DIMSCALE" 1))) (DEFUN PTRACK nil (SETVAR "AUTOSNAP" (BOOLE 6 (GETVAR "AUTOSNAP") )) Quote
Recommended Posts
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.