In a script file I want to check to see if a portion of the current files name contains "-FLS-". If it does not then do command A, if it does then do not do command A. Below is what I've started with but not sure where to go from here. I suspect I need a string statement but I don't understand how to use them. Clearly I am a beginner here.
(defun c:get-dwgname ( )
(if (= (getvar 'dwgtitled) 1)
(vl-filename-base (getvar 'dwgname))
)
)
Try
(defun c:get-dwgname ( ) (if (and (= (getvar 'dwgtitled) 1) (wcmatch (vl-filename-base (getvar 'dwgname)) "*-FLS-*") );; and ;; do command A ) )
Henrique
forgive my ignorance but what do you mean by ";;and" and ";;do command A"? You lost me there. The rest makes sense.
@shawn.p.phillips wrote:
...what do you mean by ";;and" and ";;do command A"? ...
The ;;xxx
are just comments to try to make easier the code understanding, in this case, signaling the end of the 'and' function, and the place where you can add your command A...
Henrique
Ok, I've gone way off the deep end here. I am trying to run this script and getting an error:
;;;CHANGE HATCH TO COLOR 254
(defun c:hatsel (/ sset)
(ssget "X" (list (cons 0 "HATCH")))
(setq sset (ssget "P"))
(sssetfirst sset sset)
(princ)
)
;;;Settings for Fire Life Safety
;;;
(defun c:FLSSET ( )
(Princ "Hi Shawn")
)
;;;Check Filename to proceed
;;;
(defun C:iddwg ( )
(cond ((= (vl-string-search "-FLS-" (getvar 'dwgname))
(command "FLSSET))
(t (command "HATSEL"))
)
(princ)
)
Error is shown below:
Command: (defun C:iddwg ( )
(_> (cond ((= (vl-string-search "-FLS-" (getvar 'dwgname))
((((_> (command "FLSSET))
((((("_> (t (command "HATSEL"))
((((("_> )
((((("_> (princ)
((((("_> )
((((("_> TILEMODE 0
((((("_> ZOOM ALL
((((("_> FILEDIA 1
((((("_> Undo E
Change your 'iddwg' function to
(defun C:iddwg () (cond ((vl-string-search "-FLS-" (getvar 'dwgname)) (c:FLSSET) ) (t (c:HATSEL)) ) (princ) ) :: or (defun C:iddwg () (if (vl-string-search "-FLS-" (getvar 'dwgname)) (c:FLSSET) (c:HATSEL) ) (princ) )
Henrique
That worked for the most part but the HATSEL routine isn't initiating when the filename doesn't have the "-FLS-" in it. No errors, just not running the routine.
It should
try
(defun c:hatsel (/ sset) (if (setq sset (ssget "X" (list (cons 0 "HATCH")))) (sssetfirst nil sset) ) (princ) )
Henrique
It worked before. I forgot to add the command line telling it what to do with the hatch once selected. Working smoothly now. Thanks so much for your help.
ok, so one more caveat, how do I add another command when the filename does NOT contain FLS? So in addition to HATSEL I want to run BASICSET as well. Actually run BASICSET then HATSEL in that order.
@shawn.p.phillips wrote:
ok, so one more caveat, how do I add another command when the filename does NOT contain FLS? So in addition to HATSEL I want to run BASICSET as well. Actually run BASICSET then HATSEL in that order.
If 'BASICSET' function is defined as a command (with 'c:' in name), perhaps something like this
(defun c:iddwg () (if (vl-string-search "-FLS-" (getvar 'dwgname)) (c:FLSSET) (progn (c:BASICSET) (c:HATSEL) ) ) (princ) )
Henrique
ok, so one more caveat, how do I add another command when the filename does NOT contain FLS? So in addition to HATSEL I want to run BASICSET as well. Actually run BASICSET then HATSEL in that order.
Try something like this:
(defun c:iddwg nil (if (wcmatch (getvar 'dwgname) "*-FLS-*") (c:FLSSET) (progn (c:BASICSET) (c:HATSEL) ) ) (princ) )
The progn function will simply evaluate each of the supplied arguments, returning the value returned by the last evaluated argument; the progn expression can then be supplied as a single argument to the if function to enable multiple expressions to be evaluated as part of the 'then' or 'else' arguments.
Lee
Looks like I was too slow! - You're too quick Henrique
Shawn,
You've been given some great advice. I do have a question for you though.
Your code makes calls to three other autolisp functions. Are those functions ALWAYS called from within a lisp routine? Or do you want them to be able to be called from the command line?
If you have no need for having them called from the command line, then I'd remove the c-colon from their definitions and calls.
So instead of having the following definition and subsequent function call:
(defun c:basicset().....................
(c:basicset)
I'd have the following:
(defun basicset().........................
(basicset)
Don Ireland
Engineering Design Technician