Jump to content

Looking for Lisp's which can be run based on layout (CTAB) name which are Odd OR Even Number


Dnyanesh Kamthe

Recommended Posts

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.

 

 

 

Link to comment
Share on other sites

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

....

 

Link to comment
Share on other sites

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

 

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Dear Tsuky & BIGAL,

Thanks for your interest & help.

below is list i am getting (This is just sample):

image.thumb.png.de659cfb3d08c66ce3f1debf1a2aa6ad.png

 

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.

 

Link to comment
Share on other sites

(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 by exceed
  • Like 2
Link to comment
Share on other sites

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:

image.png.6e57eedec563c795aff4d8ca9631587a.png

 

Could you please look into this. thank you again for your great help and time.

Link to comment
Share on other sites

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)
)

 

  • Like 2
Link to comment
Share on other sites

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:

image.png.6e57eedec563c795aff4d8ca9631587a.png

 

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.

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Thank you Tsuky,

I tried your lisp which giving me:

image.png.bf2d11d3a2acdb08d38b536c74050718.png

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.

 

 

Link to comment
Share on other sites

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

image.png.c86a9ea3df9947d259276f46dcb4efe7.png

Link to comment
Share on other sites

33 minutes ago, Dnyanesh Kamthe said:

Thank you Tsuky,

I tried your lisp which giving me:

image.png.bf2d11d3a2acdb08d38b536c74050718.png

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)
)

 

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

image.png.32b85a72e8a46b07d23d055eced45521.png

Note: XX.lsp for Odd numbered layout

           YY.lsp for Even Numbered layout

Could you please help me on this. 

Thank you.

Link to comment
Share on other sites

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)
)

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...