Author Topic: If then statements  (Read 4851 times)

0 Members and 1 Guest are viewing this topic.

JohnK

  • Administrator
  • Seagull
  • Posts: 10660
Re: If then statements
« Reply #15 on: November 02, 2017, 06:22:18 PM »
Ah, yes. I remember having to constantly check for stuff like that now (strings for entry into other functions and what not).  I also remember hating hanging boole's like that too. I remember getting to one company where the previous programmer wrote gobs of unnecessary code--besides the absolute weird things like splash screens and what not--and I spent weeks trimming the fat from his code and tracking down the runaway "TTTTTTTTNILTNILLNILL" prompts from the 5 minute startups. It was an average morning if I trimmed a few hundred lines of code from one of his procedures--and a splash screen of a dragon-.

It's up to you guys but I can only speak from what little experience I remember about keeping variable creation hygienic--tracking down stray variables is not fun--and hanging/unnecessary boolean functions.

The only reason I set a variable is to check that (getenv "LastTemplate") actually returns something ( don't know why it ever would not but... ) otherwise STRCASE will $h!+ the bed :).


I guess you could write it like this too not setting any variables.
Code - Auto/Visual Lisp: [Select]
  1. (and (= 'str (type (getenv "LastTemplate")))
  2.      (wcmatch (strcase (getenv "LastTemplate")) "C:\\USERS*")
  3.      (c:setup_menus)
  4. )

Ok guys. This is where I am at.
...

None of that makes any sense to me. I hope it works but if not, good luck.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

ronjonp

  • Needs a day job
  • Posts: 7531
Re: If then statements
« Reply #16 on: November 02, 2017, 07:05:11 PM »
Ok guys. This is where I am at.

Code: [Select]
(defun c:Setup_menus ()
(setvar "Expert" 0)
(ALERT "Setting Up Menus.")
(princ)
); defun

;;does not work;;(cond ((wcmatch (strcase (getenv "LastTemplate")) "C:\\USERS\\*")(C:Setup_menus)) )

;;works;;;;;(if (and (setq tmp (getenv "LastTemplate")) (wcmatch (strcase tmp) "\\\\NetworkName*"))(C:Setup_menus))

;;works;;;;;(cond ((wcmatch (strcase (getenv "LastTemplate")) "\\\\NetworkName*")(C:Setup_menus)) )

;;does not work;;(and (= 'str (type (getenv "LastTemplate")))(wcmatch (strcase (getenv "LastTemplate")) "C:\\USERS*")(c:Setup_menus)(Setup_menus) )


I have a Icon Shortcut with the following switch:
Code: [Select]
/b "C:\Test\Startup.scr"
Code: [Select]
(if (and (setq tmp (getenv "LastTemplate")) (wcmatch (strcase tmp) "C:\\USERS\\*"))(ALERT "Setting Up Menus."))"
If I run this from the desktop shortcut I can not get it to work. But if I drag it into CAD Model it works.

Code: [Select]
(if (and (setq tmp (getenv "LastTemplate")) (wcmatch (strcase tmp) "C:\\\\USERS\\\\*"))(ALERT "Setting Up Menus."))"
If I run this from the desktop shortcut, it works, but if I drag it in; it does not.

Weird stuff. lol
The logic of all the snippits above is the same? Are you checking what (getenv "LastTemplate") returns?
Code - Auto/Visual Lisp: [Select]
  1. (cond ((wcmatch (strcase (getenv "LastTemplate")) "C:\\*") (print "works")))
  2. (if (and (setq tmp (getenv "LastTemplate")) (wcmatch (strcase tmp) "C:\\*"))
  3.   (print "works")
  4. )
  5. (and (= 'str (type (getenv "LastTemplate")))
  6.      (wcmatch (strcase (getenv "LastTemplate")) "C:\\*")
  7.      (print "works")
  8. )
« Last Edit: November 03, 2017, 09:01:09 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2606
  • I can't remeber what I already asked! I need help!
Re: If then statements
« Reply #17 on: November 03, 2017, 07:43:09 AM »
I appreciate all the help you guys! I was looking at the LastSaved template variable and when the CAD first configures. There really isn't a lastsaved template set yet. I had to change it to template path to get it to work. Now I have tested it in a couple of machines and it works! So thank you again!

Code: [Select]
(cond ((wcmatch (strcase (getenv "TemplatePath")) "C:\\USERS\\*")(C:Setup_menus)) )
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7531
Re: If then statements
« Reply #18 on: November 03, 2017, 08:42:57 AM »
That's the right variable  :oops:  Glad you got it sorted.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2606
  • I can't remeber what I already asked! I need help!
Re: If then statements
« Reply #19 on: November 03, 2017, 08:44:38 AM »
Hey. Thank you for guiding me in the right direction! You know how I get sometimes lol :idiot2:
Civil3D 2020