See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Working with COND statement - "error: malformed list on input"

  1. #1
    Design Visualization Moderator stusic's Avatar
    Join Date
    2004-10
    Location
    Denver, Colorado
    Posts
    1,515
    Login to Give a bone
    0

    Default Working with COND statement - "error: malformed list on input"

    Hey All!

    I'm trying to isolate the last few letters of the drawing filename, but can't quite get it right. This is really the first time I've worked with COND statements, so my problem probably lies within there. Can't someone help me find my error? Thanks a heap!

    Code:
    (defun c:UTB ( / ent ss att fld1 fld2 fld3 dwg n s an bn ad util-is64 a fld4)
    
      (setq fld1 (strcat ("%<\AcVar Login \f \"%tc1\">%")) ;DRAWNBY
      (setq fld2 (getvar "DWGNAME")) ;DRAWING_NO
      (setq fld3 (substr (getvar "dwgname") 1 7)) ;ITEM_NO;
    
      ;set drawing description
      (setq a
         (strlen fld2)
      );setq
         (cond
           ((= a 10) (setq fld4 (substr (a 9 10))))
           ((= a 11) (setq fld4 (substr (a 9 11))))
           ((= a 12) (setq fld4 (substr (a 11 12))))
           ((= a 13) (setq fld4 (substr (a 11 13))))
            (T (prompt "\nDrawing Number Format Unrecognized"))
           );end cond
    Basically, if the DWGNAME variable is 10 digits, set "fld4" to a string of the 9th and 10th digits, etc...

    Then I'll need to evaluate those digits and put together a string for the dfrawing description, but that's another task altogether...

    Thanks for any direction you guys can provide, I really appreciate it!

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Working with COND statement - "error: malformed list on input"

    Code:
    ;; <snip>
    
    (setq fld1 (strcat "%<\AcVar Login \f \"%tc1\">%"))
    (setq fld2 (getvar 'dwgname))
    (setq fld3 (substr fld2 1 7))
    
    ;; Drawing description
    (if (and (<= 10 (setq a (strlen fld2))) (>= 13 a))
      (setq fld4 (substr fld2 9))
      (prompt "\nDrawing Number Format Unrecognized")
      )
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  3. #3
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: Working with COND statement - "error: malformed list on input"

    For the first post. you can also use ASSOC

    What you need to remember about COND that it will stop looking at the later conditions as soon as it finds one that is satisfied
    you could write it this way
    Code:
    (if (setq fld4     
    	     (cond
    	       ((= a 10) (substr fld2 9))
    	       ((= a 11) (substr fld2 9))
    	       ((= a 12) (substr fld2 11))
    	       ((= a 13) (substr fld2 11 )))) fld4
            	(print "Drawing Number Format Unrecognized")
           )
    or
    Code:
    (if (setq fld4     
    	     (cond
    	       ((< 9 a 12) (substr fld2 9))
    	       ((< 11 a 14) (substr fld2 11))
    	       )) fld4 (print "Drawing Number Format Unrecognized")
           )
    Notice there's only one call to setq?

    or even,....
    Code:
    (if
                (setq data (assoc a '((10 9) (11 9) (12 11) (11 11))))
                     (setq fld4 (substr fld2 (cadr data)))
                     (print "Drawing Number Format Unrecognized"))
    Specially usefull if you're only needing to assign a value to one variable


    HTH

  4. #4
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Working with COND statement - "error: malformed list on input"

    COND is not needed for the task being performed.

    If you look closely, stusic's COND statement only uses the string length as part of each test expression in order to change the 'length' parameter for the SUBSTR call... in other words the 'start' parameter of the SUBSTR call is the same for each condition.

    ... My $0.02
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  5. #5
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: Working with COND statement - "error: malformed list on input"

    I thought the 2nd int argument for substr vaires depending on the length.

    If length is 10 start at 9, if 12 then 10 and so on
    Code:
    (if   (setq data (assoc a '((10 9) (11 9)
     (12 11) (13 11)
    (14 12)(15 12))))
                     (setq fld4 (substr fld2 (cadr data)))
                     (print "Drawing Number Format Unrecognized"))
    but I guess you are right. I should've read the OP's next post to see whole picture.
    Last edited by pbejse; 2012-07-08 at 01:07 PM.

  6. #6
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Working with COND statement - "error: malformed list on input"

    Quote Originally Posted by stusic View Post
    Code:
    (defun c:UTB ( / ent ss att fld1 fld2 fld3 dwg n s an bn ad util-is64 a fld4)
    
      (setq fld1 (strcat ("%<\AcVar Login \f \"%tc1\">%")) ;DRAWNBY
      (setq fld2 (getvar "DWGNAME")) ;DRAWING_NO
      (setq fld3 (substr (getvar "dwgname") 1 7)) ;ITEM_NO;
    
      ;set drawing description
      (setq a
         (strlen fld2)
      );setq
         (cond
           ((= a 10) (setq fld4 (substr (a 9 10))))
           ((= a 11) (setq fld4 (substr (a 9 11))))
           ((= a 12) (setq fld4 (substr (a 11 12))))
           ((= a 13) (setq fld4 (substr (a 11 13))))
            (T (prompt "\nDrawing Number Format Unrecognized"))
           );end cond
    Apparently I needed to look more closely at the OP myself ... As the first two conditions (string length = 10 or 11) start at 9, and the next two conditions (string length = 12 or 13) start at 11. I clearly overlooked this when I made my original post.

    Perhaps then, we can simplify the COND statement:

    Code:
    ;; <snip>
    
    (setq fld1 (strcat "%<\AcVar Login \f \"%tc1\">%"))
    (setq fld2 (getvar 'dwgname))
    (setq fld3 (substr fld2 1 7))
    
    ;; Drawing description
    (cond
      ((and (<= 10 (setq a (strlen fld2))) (>= 11 a))
       (setq fld4 (substr fld2 9 a)))
      ((and (<= 12 a) (>= 13 a))
       (setq fld4 (substr fld2 11 a)))
      ((prompt "\nDrawing Number Format Unrecognized")))
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  7. #7
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    1

    Default Re: Working with COND statement - "error: malformed list on input"

    Quote Originally Posted by RenderMan View Post
    Apparently I needed to look more closely at the OP myself ... As the first two conditions (string length = 10 or 11) start at 9, and the next two conditions (string length = 12 or 13) start at 11. I clearly overlooked this when I made my original post.

    Well there you go. thought my Dy5l♂xσa is acting up again.

  8. #8
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Working with COND statement - "error: malformed list on input"

    Quote Originally Posted by pbejse View Post
    Well there you go. thought my Dy5l♂xσa is acting up again.
    Nope; you're good, it's just mine.

    Sorry for (my) confusion guys.

  9. #9
    Design Visualization Moderator stusic's Avatar
    Join Date
    2004-10
    Location
    Denver, Colorado
    Posts
    1,515
    Login to Give a bone
    0

    Default Re: Working with COND statement - "error: malformed list on input"

    I love how there's so many ways to accomplish a task - I just wish I knew the best ones These snippets are much smoother than the cumbersome, brute-force kind of coding I've got.

    You guys are the best.

  10. #10
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Working with COND statement - "error: malformed list on input"

    Quote Originally Posted by stusic View Post
    I love how there's so many ways to accomplish a task - I just wish I knew the best ones These snippets are much smoother than the cumbersome, brute-force kind of coding I've got.

    You guys are the best.
    That is kind of you to say, stusic... Sorry to have taken the 'scenic route', but I'm happy to have helped.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

Page 1 of 2 12 LastLast

Similar Threads

  1. error: malformed string on input
    By Bear31831 in forum AutoCAD General
    Replies: 13
    Last Post: 2013-08-27, 06:50 PM
  2. Replies: 16
    Last Post: 2011-03-01, 03:25 PM
  3. Replies: 5
    Last Post: 2009-04-17, 10:10 AM
  4. Replies: 8
    Last Post: 2007-04-04, 12:39 PM
  5. Please explain how LISP function "cond" works
    By ccowgill in forum AutoLISP
    Replies: 11
    Last Post: 2006-11-18, 08:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •