TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: laison on November 08, 2010, 10:21:29 PM

Title: Setting the OSMODE Setting
Post by: laison on November 08, 2010, 10:21:29 PM
When writing code and you get to where you are going to set you OSMODE setting can you set more than 1 setting in the same line?

Code: [Select]
(setvar "osmode" 1, 2, 4, 32)
[CODE]
[/code]
Title: Re: Setting the OSMODE Setting
Post by: alanjt on November 08, 2010, 10:42:05 PM
You add them.
eg.
Code: [Select]
(setvar 'osmode (+ 1 2 4 32)) or
Code: [Select]
(setvar 'osmode 39)
Title: Re: Setting the OSMODE Setting
Post by: MP on November 08, 2010, 10:54:17 PM
Given it's a bit coded integer I'd be more inclined to "or" the values together:

(setvar "osmode" (logior + 1 2 4 32))

I tried to rewrite this 3 times so I wouldn't sound like a dick without success; sorry, just sayin'.

shrug_icon_goes_here
Title: Re: Setting the OSMODE Setting
Post by: alanjt on November 08, 2010, 11:18:46 PM
No dick, just educating.
Thanks Michael.

I assume you meant: (logior 1 2 4 32)
Title: Re: Setting the OSMODE Setting
Post by: MP on November 08, 2010, 11:26:11 PM
yeah sh!t :lol: thanks for being gracious

I'll leave the error so the thread makes sense
Title: Re: Setting the OSMODE Setting
Post by: David Bethel on November 09, 2010, 06:18:35 AM
logior makes more sense to me if you your trying to ensure that the new modes were added to the existing osmode setting.

Code: [Select]

(setq os (getvar "OSMODE"))

(setvar "OSMODE" (logior os 1 2 4 32))


It adds the bit regardless of the current setting. 

I think I would stick with the plus just for readability. -David

Title: Re: Setting the OSMODE Setting
Post by: Daniel J. Ellis on November 09, 2010, 08:07:50 AM
So what  does logior do?

dJE
Title: Re: Setting the OSMODE Setting
Post by: JohnK on November 09, 2010, 08:28:06 AM
...
I'll leave the error so the thread makes sense

heh, too bad some people dont share that basic courtesy.
Title: Re: Setting the OSMODE Setting
Post by: David Bethel on November 09, 2010, 08:45:27 AM
Lets say you want to close a polyline : set the 1 bit in the group 70 flag

Code: [Select]
(setq flag (cdr (assoc 70 ed)))

Either of these statements work:

Code: [Select]
(if (/= (logand flag 1) 1)
    (setq flag (+ flag 1)))

(logior flag 1)

Logior's advantage is that accepts multiple tests in a single call.

-David