nzgeocad Posted August 16, 2009 Share Posted August 16, 2009 Gidday, Basically what I am looking to do is run one Autolisp function that will define a global variable and then have another function use that variable. Both functions need to be able to be run from the command line or from a button on the ribbon at any time (the second will be error trapped so, if the first hasn't been run and the variable hasn't been defined, it will return a sensible error). What I am trying is something like this: (defun c:CreateVariable ( / localVariable1 localVariable2) (setq localVariable1 50.0) (setq localVariable2 3.0) (setq globalVariable (* localvariable1 localVariable2) ) ; end defun (defun c:UseVariable () (setq newVariable (/ 1234.0 globalVariable)) (princ (rtos newVariable)) ) ; end defun I know that if you define a function using c: xxxx it wont let you use arguments but I don't know how to get that global variable into the function... I'm sure it's simple, but at the moment it's very frustrating. Any help would be appreciated. Quote Link to comment Share on other sites More sharing options...
jammie Posted August 16, 2009 Share Posted August 16, 2009 Introduce a test that will run the CreateVariable if the globalVariable has not been defined (if (not globalVariable) ;test expression (c:CreateVariable) ;preform the function ) See the test expressions COND, IF, AND OR in the AutoLISP help file for more info (defun c:CreateVariable ( / localVariable1 localVariable2) (setq localVariable1 50.0) (setq localVariable2 3.0) (setq globalVariable (* localvariable1 localVariable2)) ) ; end defun (defun c:UseVariable () ;Either the variable has a value or assign one (or globalVariable (c:CreateVariable)) (setq newVariable (/ 1234.0 globalVariable)) (princ (rtos newVariable)) ) ; end defun Quote Link to comment Share on other sites More sharing options...
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.