Author Topic: Check my code?  (Read 2800 times)

0 Members and 1 Guest are viewing this topic.

StykFacE

  • Guest
Check my code?
« on: February 28, 2013, 01:00:14 PM »
I put this in our AcadDoc.lsp file, and was wondering if I managed to do this correctly. My first attempt at a conditional statement. Read up in the developer help and AfraLisp today to create this simple code.
Code: [Select]
(if
  (= 1 (getvar 'selectionannodisplay))
   (setvar "selectionannodisplay" 0)
)
(princ)

We are migrating to all Annotative Objects for dims, mleaders, text, etc and I wanted this variable always to be at zero. Any thoughts would be much appreciated!! Thanks in advance.

- Tannar

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Check my code?
« Reply #1 on: February 28, 2013, 01:02:16 PM »
Technically it's an "IF" statement.  Or... "if/then" to be more precise.   :wink:
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

andrew_nao

  • Guest
Re: Check my code?
« Reply #2 on: February 28, 2013, 01:23:51 PM »
I put this in our AcadDoc.lsp file, and was wondering if I managed to do this correctly. My first attempt at a conditional statement. Read up in the developer help and AfraLisp today to create this simple code.
Code: [Select]
(if
  (= 1 (getvar 'selectionannodisplay))
   (setvar "selectionannodisplay" 0)
)
(princ)


We are migrating to all Annotative Objects for dims, mleaders, text, etc and I wanted this variable always to be at zero. Any thoughts would be much appreciated!! Thanks in advance.

- Tannar

look ok to me although i would put it like

Code: [Select]
(if (=  (getvar 'selectionannodisplay) 1)
   (setvar "selectionannodisplay" 0)
)

its really preference, 6 of one and a half dozen of another

BlackBox

  • King Gator
  • Posts: 3770
Re: Check my code?
« Reply #3 on: February 28, 2013, 01:46:58 PM »
First, there's nothing wrong with your code as written in the OP.

In cases where you want to 'force' a particular system variable value, there's really no need to check, per-se. I've seen it both ways.



Separately, since you're starting to find things you want to do in LISP, you might find this related snippet useful at some point:

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (foreach x '((selectionannodisplay 0)
  3.              ;;<-- other sysvars
  4.             )
  5.   (vl-catch-all-apply 'setvar x)
  6. )
  7.  
"How we think determines what we do, and what we do determines what we get."

StykFacE

  • Guest
Re: Check my code?
« Reply #4 on: February 28, 2013, 02:54:46 PM »
Technically it's an "IF" statement.  Or... "if/then" to be more precise.   :wink:
Lol, before I even called it a conditional I checked the AfraLisp site.... I'm so non-LISP-literate it's not even funny. Thanks tho, much appreciated Matt.

In cases where you want to 'force' a particular system variable value, there's really no need to check, per-se. I've seen it both ways.
The reason I was "checking" the variable is so that if it's already set, it doesn't change the file and always get the annoying Save dialog box when you just open/close and no changes were made. Kinda like doing some batch file open/close stuff from time to time - didn't want anything to interfere. Hopefully I'm making sense, and my approach was correct in this? Oh and thanks for the code, read up on it a bit and I can definitely see this as useful. :)

On a side note, I have some personal commentary. Even tho this is about as simple as you can get I'm proud of it. First, for actually digging up the info and not giving up by coming here screaming "Help me!". I did have about 10 minutes of trial and error, and I found that in the VLIDE I was highlighting just the selection of code and using the "Load Selection" tool to break down functions one at a time to see if there was errors or if it returned a value. RenderMan, I actually had to reference your last little snippet you gave me regarding the custom AcadDoc.lsp file load. The apostrophe before the variable was my biggest set back for a bit, lol.

Anyways, thanks again gents. Hopefully I can build off this. :kewl:

BlackBox

  • King Gator
  • Posts: 3770
Re: Check my code?
« Reply #5 on: February 28, 2013, 03:08:39 PM »
The reason I was "checking" the variable is so that if it's already set, it doesn't change the file and always get the annoying Save dialog box when you just open/close and no changes were made. Kinda like doing some batch file open/close stuff from time to time - didn't want anything to interfere. Hopefully I'm making sense, and my approach was correct in this?

First thing, is that the SelectionAnnodisplay System Variable is stored to the Registry, not the Drawing, so you can make the change and still close the Drawing without the notification.

Second, you may find the acad-push-dbmod, and acad-pop-dbmod functions to be of use.  :wink:

Oh and thanks for the code, read up on it a bit and I can definitely see this as useful. :)

... Even tho this is about as simple as you can get I'm proud of it.

You're welcome, and as you should be. :beer:
"How we think determines what we do, and what we do determines what we get."

StykFacE

  • Guest
Re: Check my code?
« Reply #6 on: February 28, 2013, 03:13:33 PM »
Second, you may find the acad-push-dbmod, and acad-pop-dbmod functions to be of use.  :wink:
Ah, so I can temporarily disable the save trigger then re-enable it? If I read all that right, cool stuff!!

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: Check my code?
« Reply #7 on: February 28, 2013, 05:17:14 PM »
Technically it's an "IF" statement.  Or... "if/then" to be more precise.   :wink:

Technically an "IF" statement is a conditional statement  :wink:

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Check my code?
« Reply #8 on: February 28, 2013, 09:51:39 PM »
Technically it's an "IF" statement.  Or... "if/then" to be more precise.   :wink:

Technically an "IF" statement is a conditional statement  :wink:
Code: [Select]
If funnyResponse = True then
   epicWin
else
   epicFail
End If
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Check my code?
« Reply #9 on: February 28, 2013, 10:03:11 PM »
In case this thread might have been missed:
http://www.theswamp.org/index.php?topic=44026.0
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.

StykFacE

  • Guest
Re: Check my code?
« Reply #10 on: March 01, 2013, 09:09:52 AM »
In case this thread might have been missed:
http://www.theswamp.org/index.php?topic=44026.0
Very good info, thanks CAB. That information is well explained by you and Lee.