Results 1 to 10 of 10

Thread: COND Statement to Setq Variable

  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 COND Statement to Setq Variable

    Can anyone tell me if there's a better way to do this (particularly FLD3)? The COND statement looks weird like it is. Itk's supposed to look in the filename and see if there's certain letters in it and label the title block accordingly. i.e., "WD" in the filename gives the drawing description "Wiring Diagram"...

    Thanks

    Code:
    (defun c:UTB (/ ss att fld1 fld2 fld3)
      
    (setq fld1 (eval "%<\\AcVar Login \\f \"%tc1\">%"))
    (setq fld2 (eval "%<\\AcVar CreateDate \\f \"M/d/yyyy\">%"))
    
    (cond ((wcmatch (getvar dwgname) "PD")
           (setq fld3 (strcat "PIPING DIAGRAM")))
          ((wcmatch (getvar dwgname) "HL")
           (setq fld3 (strcat "HEADER LAYOUT")))
          ((wcmatch (getvar dwgname) "CL")
           (setq fld3 (strcat "COMPRESSOR LAYOUT")))
          ((wcmatch (getvar dwgname) "CHL")
           (setq fld3 (strcat "COMPRESSOR HEADER LAYOUT")))
          ((wcmatch (getvar dwgname) "WD")
           (setq fld3 (strcat "WIRING DIAGRAM")))
          ((wcmatch (getvar dwgname) "KS1")
           (setq fld3 (strcat "HOUSE PLAN VIEW")))
          ((wcmatch (getvar dwgname) "KS2")
           (setq fld3 (strcat "HOUSE LIFTING & ELEVATION")))
          ((wcmatch (getvar dwgname) "KS3")
           (setq fld3 (strcat "HOUSE BASE")))
          ((wcmatch (getvar dwgname) "KS4")
           (setq fld3 (strcat "HOUSE WALLS")))
          ((wcmatch (getvar dwgname) "KS5")
           (setq fld3 (strcat "HOUSE ROOF")))
          ((wcmatch (getvar dwgname) "KS6")
           (setq fld3 (strcat "CONDENSER SUPPORT")))
          ((wcmatch (getvar dwgname) "KS7")
           (setq fld3 (strcat "CATWALK")))
          ((wcmatch (getvar dwgname) "KS8")
           (setq fld3 (strcat "HANDRAILS")))
          ((wcmatch (getvar dwgname) "KS9")
           (setq fld3 (strcat "SHEETMETAL LAYOUT")))
          ((wcmatch (getvar dwgname) "KS10")
           (setq fld3 (strcat "CURB")))
          ((wcmatch (getvar dwgname) "KE1")
           (setq fld3 (strcat "ELECTRICAL PLAN VIEW")))
          ((wcmatch (getvar dwgname) "KE2")
           (setq fld3 (strcat "LINE DIAGRAM & PANEL SCHEDULES")))
          ((wcmatch (getvar dwgname) "KE3")
           (setq fld3 (strcat "HOUSE CONTROLS DIAGRAM")))
          ((wcmatch (getvar dwgname) "KE4")
           (setq fld3 (strcat "DEFROST PANEL WIRING DIAGRAM")))
          ((wcmatch (getvar dwgname) "KM1")
           (setq fld3 (strcat "HOUSE PIPING DIAGRAM")))
          ((wcmatch (getvar dwgname) "FAN")
           (setq fld3 (strcat "MACHINE HOUSE FAN WIRING")))
          ((wcmatch (getvar dwgname) "LTC")
           (setq fld3 (strcat "LIGHTING CONTACTOR WIRING")))
          ((wcmatch (getvar dwgname) "WTP")
           (setq fld3 (strcat "WATER TANK PIPING")))
          ((wcmatch (getvar dwgname) "WPW")
           (setq fld3 (strcat "WATER PUMP WIRING")))      
    )
    
      
      (if (setq ss (ssget "X" (list (cons 0 "INSERT")(cons 2 "*BORDER*")
           (cons 66 1)(if (getvar "CTAB")(cons 410 (getvar "CTAB"))
                  (cons 67 (- 1 (getvar "TILEMODE")))))))
       
        (progn
          (foreach ent (mapcar 'cadr (ssnamex ss))
        (setq att (entnext ent))
        (while (not (eq "SEQEND" (cdadr (entget att))))
          (cond
        ((eq "DRAWNBY" (cdr (assoc 2 (entget att))))
             (entmod (subst (cons 1 fld1) (assoc 1 (entget att)) (entget att))))
            ((eq "DRAWNDATE" (cdr (assoc 2 (entget att))))
             (entmod (subst (cons 1 fld2) (assoc 1 (entget att)) (entget att))))
            ((eq "DESCRIPTION" (cdr (assoc 2 (entget att))))
             (entmod (subst (cons 1 fld3) (assoc 1 (entget att)) (entget att))))
          )
          (setq att (entnext att))))
          (command "_regenall"))
        (princ "\n<!> No Blocks Found <!>"))
    Phillip Bradshaw
    Lead Pixel Pusher, Lucid Design Studio
    CAD Detailer, Proctor Productions

    A doctor can bury his mistakes but an architect can only advise his clients to plant vines. - Frank Lloyd Wright

  2. #2
    AUGI Addict
    Join Date
    2015-12
    Posts
    2,095
    Login to Give a bone
    0

    Default Re: COND Statement to Setq Variable

    The (wcmatch...) calls look a little odd without any wildcard characters. You may as well just check for equality in that case. And the (strcat...) calls only have a single string?

    (cond...) will return the last statement of its selected "branch", so in these cases I usually supply the (cond...) as an argument to the (setq...) e.g.

    Code:
    (setq
       foo
          (cond
             ((some test here)
                (strcat str_var "CONSTANT STRING")
             )
             ((some other test here)
                (strcat str_var "ANOTHER CONSTANT STRING")
             )
          )
    )
    If you are going to fly by the seat of your pants, expect friction burns.
    Some say beauty is in the eye of the Beholder... perhaps so, but I've only seen the disintegration beam.
    Everyone else being wrong is not the same thing as being right.

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

    Default Re: COND Statement to Setq Variable

    I kinda followed where you were going, but didn't get too far.

    Added this:

    Code:
    (setq fld1 (eval "%<\\AcVar Login \\f \"%tc1\">%"))
    (setq fld2 (eval "%<\\AcVar CreateDate \\f \"M/d/yyyy\">%"))
    (setq fld3 (cond
             ((wcmatch (getvar dwgname) "PD")
                (strcat "PIPING DIAGRAM"))
             ((wcmatch (getvar dwgname) "HL")
                (strcat "HEADER LAYOUT"))
          	   )
    )
    I'm using the wcmatch to match a couple of letters against the filename (I suppose I could add a * before PD, but I don't know if I need to).

    Also, I don't really know how to just make a string into a variable without using strcat. I can't simply do this can I?

    Code:
             ((wcmatch (getvar dwgname) "*HL")
                ("HEADER LAYOUT"))
    Either way (with or without wildcards), I get this error:

    ; error: bad argument type: (or stringp symbolp): nil

    Any ideas?
    Phillip Bradshaw
    Lead Pixel Pusher, Lucid Design Studio
    CAD Detailer, Proctor Productions

    A doctor can bury his mistakes but an architect can only advise his clients to plant vines. - Frank Lloyd Wright

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

    Default Re: COND Statement to Setq Variable

    Phillip, consider this example using your original code:

    Code:
    (setq fld3
           (cond
    
             ;; In the first test expression, define drawing name variable.
             ((wcmatch (setq dwg (getvar 'dwgname)) "*PD") "PIPING DIAGRAM")
    
             ;; Subsequent test expressions do not need to perform the
             ;; getvar step, as this variable has already been defined.
             ((wcmatch dwg "*HL") "HEADER LAYOUT")
    
             ;; If the test expression evaluates to non-nil, the result
             ;; is returned, which in this syntax is a string
             ;; representing the drawing description.
             ((wcmatch dwg "*CL") "COMPRESSOR LAYOUT")
    
             ;; <-- More conditions here
             )
          )
    
    ;; <-- Be sure to test for 'fld3' prior to continuing your code.
    HTH
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3630, Core i9-9900K 5.0GHz, 128GB RAM, Samsung 970 Pro M.2, 8GB NVIDIA Quadro P4000

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

    Default Re: COND Statement to Setq Variable

    Code:
    ;; <-- Be sure to test for 'fld3' prior to continuing your code.
    I keep reading this. I do not think it means what I think it means. How do you test?
    Phillip Bradshaw
    Lead Pixel Pusher, Lucid Design Studio
    CAD Detailer, Proctor Productions

    A doctor can bury his mistakes but an architect can only advise his clients to plant vines. - Frank Lloyd Wright

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

    Default Re: COND Statement to Setq Variable

    Quote Originally Posted by stusic View Post
    Code:
    ;; <-- Be sure to test for 'fld3' prior to continuing your code.
    I keep reading this. I do not think it means what I think it means. How do you test?
    A simple IF statement will do, examples:
    Code:
    (if 
      (and
        ;; set fld1
        ;; set fld2
        ;; set fld3
        )
      ;; <-- continue
      ;; <-- end
      )
    ... Or:
    Code:
    ;; set fld1
    ;; set fld2
    ;; set fld3
    (if (and fld1 fld2 fld3)
      ;;<-- continue
      ;;<-- end
      )
    HTH
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3630, Core i9-9900K 5.0GHz, 128GB RAM, Samsung 970 Pro M.2, 8GB NVIDIA Quadro P4000

  7. #7
    Certifiable AUGI Addict cadtag's Avatar
    Join Date
    2000-12
    Location
    Cairo - no, not Illinois
    Posts
    4,919
    Login to Give a bone
    0

    Default Re: COND Statement to Setq Variable

    or end the COND function with a default string value, whether empty string " " or a fall back string like "NOT FOUND". If fld3 is not set to a string value, and you try to use it with any function that requires a string value, you'll get the error

    ; error: bad argument type: (or stringp symbolp): nil

    that you are seeing
    Real pirates wear silk suits & ties, and write EULAs
    The only thing more dangerous to the liberty of a free people than big government, is big business.

    Toward a Sustainable Water Future: Visions for 2050 http://ascelibrary.org/doi/book/10.1061/9780784412077

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

    Default Re: COND Statement to Setq Variable

    Okay, I think I've got ya. I'm still getting errors (I think it's from another part of my code), but does this look better?

    Code:
    (setq	fld3				;DESCRIPTION
    	 (cond
    	   ((wcmatch (setq dwg (getvar 'dwgname)) "*PD")
    	    "PIPING DIAGRAM"
    	   )
    	   ((wcmatch dwg "*HL") "HEADER LAYOUT")
    	   ((wcmatch dwg "*CL") "COMPRESSOR LAYOUT")
    	   ((wcmatch dwg "*CHL") "COMPRESSOR HEADER LAYOUT")
    	   ((wcmatch dwg "*WD") "WIRING DIAGRAM")
    	   ((wcmatch dwg "*KS1") "HOUSE PLAN VIEW")
    	   ((wcmatch dwg "*KS2") "HOUSE LIFTING & ELEVATION")
    	   ((wcmatch dwg "*KS3") "HOUSE BASE")
    	   ((wcmatch dwg "*KS4") "HOUSE WALLS")
    	   ((wcmatch dwg "*KS5") "HOUSE ROOF")
    	   ((wcmatch dwg "*KS6") "CONDENSER SUPPORT")
    	   ((wcmatch dwg "*KS7") "CATWALK")
    	   ((wcmatch dwg "*KS8") "HANDRAILS")
    	   ((wcmatch dwg "*KS9") "SHEETMETAL LAYOUT")
    	   ((wcmatch dwg "*KS10") "CURB")
    	   ((wcmatch dwg "*KE1") "ELECTRICAL PLAN VIEW")
    	   ((wcmatch dwg "*KE2") "LINE DIAGRAM & PANEL SCHEDULES")
    	   ((wcmatch dwg "*KE3") "HOUSE CONTROLS DIAGRAM")
    	   ((wcmatch dwg "*KE4") "DEFROST PANEL WIRING DIAGRAM")
    	   ((wcmatch dwg "*KM1") "HOUSE PIPING DIAGRAM")
    	   (t
    	    (princ
    	      "\nNo matching drawing descriptions found. Valid name extentions are: HL, CL, CHL, WD, KS1, KS2, KS3, KS4, KS5, KS6, KS7, KS8, KS9, KS10, KE1, KE2, KE3, KE4, KM1"
    	    )
    	   )
    	 )
      )
    Phillip Bradshaw
    Lead Pixel Pusher, Lucid Design Studio
    CAD Detailer, Proctor Productions

    A doctor can bury his mistakes but an architect can only advise his clients to plant vines. - Frank Lloyd Wright

  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: COND Statement to Setq Variable

    Yes, it works! I had to add and asterisk after the search string as well because I forgot "dwgname" also included the file extension, but it's all good now!

    Thanks guys!
    Phillip Bradshaw
    Lead Pixel Pusher, Lucid Design Studio
    CAD Detailer, Proctor Productions

    A doctor can bury his mistakes but an architect can only advise his clients to plant vines. - Frank Lloyd Wright

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

    Default Re: COND Statement to Setq Variable

    You're welcome, happy to help.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3630, Core i9-9900K 5.0GHz, 128GB RAM, Samsung 970 Pro M.2, 8GB NVIDIA Quadro P4000

Similar Threads

  1. error: bad variable name in SETQ?
    By stusic in forum AutoLISP
    Replies: 6
    Last Post: 2013-05-21, 05:46 PM
  2. Routine skipping over cond. statement. . why?
    By M. Kubitza in forum AutoLISP
    Replies: 11
    Last Post: 2010-01-13, 11:04 PM
  3. Replies: 52
    Last Post: 2007-09-27, 09:09 PM
  4. Using commands in a cond statement
    By eleonard in forum AutoLISP
    Replies: 14
    Last Post: 2007-02-27, 06:07 PM
  5. setq Selection Set to a variable
    By gisdude in forum AutoLISP
    Replies: 2
    Last Post: 2006-05-30, 03:05 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
  •