Dnyanesh Kamthe Posted July 24, 2023 Posted July 24, 2023 Dear Expertise, I hope i can get some solution here. Thing is, in my one drawing I have 100 layouts which having names like odd & even numbers. Now i have some work in odd number named layouts which is same for all odd number named layouts (i.e., for 50 layouts): For this one I have already drafted basic lisp, we can call Odd Freeze.lsp. same for even number named layouts also, we can call Even Freeze.lsp. These 2-lisp having different purpose means not same. Now I want to run these both lisp in one lisp based on layout names which are odd & even numbers, means for all Odd number named layouts run Odd Freeze.lsp & for all Even number named layouts run Even Freeze.lsp. Thanks in Advance, Dnyanesh. Quote
Tsuky Posted July 24, 2023 Posted July 24, 2023 Try with (rem). If you can obteint interger from your layouts (if (zerop (rem (atoi (getvar "CTAB")) 2)) (print "even") (print "odd")) Quote Command: (rem 0 2) 0 Command: (rem 1 2) 1 Command: (rem 2 2) 0 Command: (rem 3 2) 1 Command: (rem 4 2) 0 .... Quote
Dnyanesh Kamthe Posted July 24, 2023 Author Posted July 24, 2023 Thank you Tsuky for prompt response. Actually, I am not much familiar with lisp, just beginner. Let me elaborate actually what I am looking for, If could help me in this much appreciated. I want lisp which can do= -Search odd number in layout name then run XX.lsp -Search Even number in layout name then run YY.lsp Thanks in advance Quote
Tsuky Posted July 24, 2023 Posted July 24, 2023 What does command line expression (layoutlist) return in your drawing? Quote
BIGAL Posted July 24, 2023 Posted July 24, 2023 Like Tsuky need to know what your layout names are like. For me we used D01, D02 etc so easy to check is last character a 1 3 5 7 or 9 for odd. Quote
Dnyanesh Kamthe Posted July 25, 2023 Author Posted July 25, 2023 Dear Tsuky & BIGAL, Thanks for your interest & help. below is list i am getting (This is just sample): I want to use lisp in future also with different series starting with number like 0001 OR 2001 OR 5001 OR 10001. Only Similarity we can consider is ODD & EVEN number. Thanks in advance. Quote
exceed Posted July 25, 2023 Posted July 25, 2023 (edited) (defun c:FOO ( / ll cl ) ; command is FOO (setq ll (layoutlist)) ; save layoutlist to ll list. (repeat (length ll) ; repeat as many time as number of members in the list ll. (setq cl (car ll)) ; get the first member of the list ll. (setvar 'ctab cl) ; set the current layout with cl. (if (= (len (atoi cl)) (len (itoa (atoi cl)))) ; check if the layout string is numeric. (progn ; if numeric (cond ; cond for determining odd even ((= (rem (atoi cl) 2) 0) ; if even (xx) ; run xx, if xx.lsp's command is xx and already loaded ) ; end of even ((= (rem (atoi cl) 2) 1) ; if odd (yy) ; run yy, if yy.lsp's command is yy and already loaded ) ; end of odd ) ; end of cond ) ; end of if numeric progn (progn ; if layout name is not numeric ) ; end of if not numeric progn ) ; end of if (setq ll (cdr ll)) ; Remove the first member of the list to move on to the next layout. ) ; end of repeat (princ) ; for mute parrot ) ; end of defun ================= Steven gave a nice comment. Adding this would also be a way. (vl-load-com) (defun len ( txt / ) (strlen (vl-princ-to-string txt)) ) Edited July 26, 2023 by exceed 2 Quote
Dnyanesh Kamthe Posted July 25, 2023 Author Posted July 25, 2023 Thank you exceed for this lisp specially for details you given for each line. This very good to understand whats each line is doing. I tried your lisp but getting error as below: Could you please look into this. thank you again for your great help and time. Quote
Tsuky Posted July 25, 2023 Posted July 25, 2023 Try this ! (defun c:FOO ( / ) (mapcar '(lambda (x) (cond ((and (not (zerop (atoi x))) (eq (atof x) (atoi x))) (if (zerop (rem (atoi x) 2)) (princ (strcat "\n\"" x "\" is even (run your \"xx.lsp\")")) (princ (strcat "\n\"" x "\" is odd (run your \"yy.lsp\")")) ) ) (T (princ (strcat "\nThe layout \"" x "\" have not name with interger or is null"))) ) ) (layoutlist) ) (textscr) (prin1) ) 2 Quote
Steven P Posted July 25, 2023 Posted July 25, 2023 1 hour ago, Dnyanesh Kamthe said: Thank you exceed for this lisp specially for details you given for each line. This very good to understand whats each line is doing. I tried your lisp but getting error as below: Could you please look into this. thank you again for your great help and time. Try Exceeds with this small change (not fully checked but it should work): From: (if (= (len (atoi cl)) (len (itoa (atoi cl)))) ; check if the layout string is numeric. To: (if (= CL (itoa (atoi CL))) ; check if the layout string is numeric. 1 1 Quote
Dnyanesh Kamthe Posted July 25, 2023 Author Posted July 25, 2023 Thank you Tsuky, I tried your lisp which giving me: my xx.lsp & yy.lsp wont run in your lisp. Your lisp just telling which lisp needs to run in which layout. Actuallly i am looking one lisp which can run my these 2 lisp based on layout names which are odd/ even numbers. Quote
Dnyanesh Kamthe Posted July 25, 2023 Author Posted July 25, 2023 28 minutes ago, Steven P said: Try Exceeds with this small change (not fully checked but it should work): From: (if (= (len (atoi cl)) (len (itoa (atoi cl)))) ; check if the layout string is numeric. To: (if (= CL (itoa (atoi CL))) ; check if the layout string is numeric. Thank you Steven P. I tried with your modifications. Still getting error, But this time different one Quote
Tsuky Posted July 25, 2023 Posted July 25, 2023 33 minutes ago, Dnyanesh Kamthe said: Thank you Tsuky, I tried your lisp which giving me: my xx.lsp & yy.lsp wont run in your lisp. Your lisp just telling which lisp needs to run in which layout. Actuallly i am looking one lisp which can run my these 2 lisp based on layout names which are odd/ even numbers. This was an example, I thought it was simple for you to interpret this one and modify it accordingly. Without knowing your lisps, then maybe like this? (defun c:FOO ( / ) (if (not (c:xx)) (load "xx.lsp")) (if (not (c:yy)) (load "yy.lsp")) (mapcar '(lambda (x) (cond ((and (not (zerop (atoi x))) (eq (atof x) (atoi x))) (if (zerop (rem (atoi x) 2)) (c:xx) (c:yy) ) ) (T (princ (strcat "\nThe layout \"" x "\" have not name with interger or is null"))) ) ) (layoutlist) ) (textscr) (prin1) ) 2 1 Quote
Steven P Posted July 25, 2023 Posted July 25, 2023 So for both the XX and YY need to be replaced by your lisp names for odd and even layouts, look in the codes and xx or yy should be easy to spot where to replace Quote
Dnyanesh Kamthe Posted July 28, 2023 Author Posted July 28, 2023 On 7/25/2023 at 4:36 PM, Tsuky said: This was an example, I thought it was simple for you to interpret this one and modify it accordingly. Without knowing your lisps, then maybe like this? (defun c:FOO ( / ) (if (not (c:xx)) (load "xx.lsp")) (if (not (c:yy)) (load "yy.lsp")) (mapcar '(lambda (x) (cond ((and (not (zerop (atoi x))) (eq (atof x) (atoi x))) (if (zerop (rem (atoi x) 2)) (c:xx) (c:yy) ) ) (T (princ (strcat "\nThe layout \"" x "\" have not name with interger or is null"))) ) ) (layoutlist) ) (textscr) (prin1) ) Hello Tsuky, I tried again your revised lisp & used your given names (i.e. XX.lsp & YY.lsp) in my lisps & loaded/ added in startup suites also. After running your FOO lisp its working on only first layout (Odd number named) and after that stopping with error attached herewith. Its not moving to next layout. Note: XX.lsp for Odd numbered layout YY.lsp for Even Numbered layout Could you please help me on this. Thank you. Quote
Tsuky Posted July 28, 2023 Posted July 28, 2023 With this modification? (defun c:FOO ( / ) (if (not (c:xx)) (load "xx.lsp")) (if (not (c:yy)) (load "yy.lsp")) (mapcar '(lambda (x) (setvar "CTAB" x) (cond ((and (not (zerop (atoi x))) (eq (atof x) (atoi x))) (if (zerop (rem (atoi x) 2)) (c:xx) (c:yy) ) ) (T (princ (strcat "\nThe layout \"" x "\" have not name with interger or is null"))) ) ) (layoutlist) ) (prin1) ) Quote
Tharwat Posted July 28, 2023 Posted July 28, 2023 For me, I do prefer to check if the program existed / was found in the search path or via a complete path in prior of loading it otherwise exit safely. Quote
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.