A little help with an "if" statement

Discussion in 'AutoCAD' started by devon, Oct 26, 2004.

  1. devon

    devon Guest

    Hello,

    I have a script that I run which binds, purges and saves drawings to the issued dirctory. It grabes the "rev" attribute from the titleblock and sticks it in the file name for the issued drawigs too.

    I am having a problem with a "revup" lisp that this loads.
    The problem is that I am trying to delete a "check print" stamp off in the file which is issued and then re-insert it in the "working files" again.
    My if statement is all screwed up and I would love some input.

    Currently the problem is that the "if" statement just inserts the stamp over and over again each time i run the script. the tablesearch is not picking up the fact that the stamp is in the drawing.

    ---- SNIP ----------
    (setq tbent (entget tbname))
    (setq tbent (subst (cons 1 (eval revup))(assoc 1 tbent) tbent))
    (entmod tbent)
    (entmod (entget (ssname tbset tbsetnum)))
    (if (tblsearch "layer" "Check_Print_Stamp")
    (if (= 1 (cdr (assoc 70 (tblsearch "layer" "Check_Print_Stamp"))))
    (progn
    (command "layer" "thaw" "Check_Print_Stamp" "")
    (if (ssget "x" (list '(0 . "INSERT") '(8 . "Check_Print_Stamp") '(2 . "Check_Print_Stamp")))
    (command "erase" (ssget "x" (list '(0 . "INSERT") '(8 . "Check_Print_Stamp") '(2 . "Check_Prin_Stamp"))) "")
    )
    )
    )
    )
    (command ".layer" "n" "Check_Print_Stamp" "c" "7" "Check_Print_Stamp" "")
    (command ".insert" "O:/Infra/CADD/Software/acad/lib/stdsym/Check_Print_Stamp" "0,0" "" "" "0")
    (command ".change" "l" "" "p" "layer" "Check_Print_Stamp" "")
    )
    ------snip---------


    any help is much appreciated.

    Thanks
    Devon
     
    devon, Oct 26, 2004
    #1
  2. devon

    Tom Smith Guest

    There appears to be one typo, where you're trying to erase "Check_Prin_Stamp" without a t.

    You could save a step by eliminating the redundant ssget:

    (if (setq sset (ssget "x" (list '(0 . "INSERT") '(8 . "Check_Print_Stamp") '(2 . "Check_Print_Stamp"))))
    (command "erase" sset "")
    )
     
    Tom Smith, Oct 26, 2004
    #2
  3. devon

    CAB2k Guest

    It could also be written this way:
    Code:
    (setq tbent (entget tbname))
    (setq tbent (subst (cons 1 (eval revup)) (assoc 1 tbent) tbent))
    (entmod tbent)
    (entmod (entget (ssname tbset tbsetnum)))
    ;;=================================================================
    (and (setq lyr (tblsearch "layer" "Check_Print_Stamp"))
    (= 1 (cdr (assoc 70 lyr)))
    (setq ss (ssget "x"
    (list '(0 . "INSERT")
    '(8 . "Check_Print_Stamp")
    '(2 . "Check_Print_Stamp"))))
    (command "layer" "thaw" "Check_Print_Stamp" ""
    "erase" ss  "")
    )
    ;;=================================================================
    (command ".layer" "n" "Check_Print_Stamp" "c" "7" "Check_Print_Stamp" "")
    (command ".insert"  "O:/Infra/CADD/Software/acad/lib/stdsym/Check_Print_Stamp"
    "0,0"  ""  "" "0" )
    (command ".change" "l" "" "p" "layer" "Check_Print_Stamp" "")
     
    CAB2k, Oct 26, 2004
    #3
  4. devon

    Tom Smith Guest

    Sorry, I don't get the purpose of the code. You're checking whether a layer
    exists and is frozen, and if so, you're thawing the layer and deleting a
    block if found. Then, regardless of whether any of the above was done,
    you're making sure a layer exists and inserting a stamp on it. The insertion
    happens in all cases. If you don't want the stamp duplicated, you need to
    check for its existence before inserting it. I don't understand the
    ntent -- under what cirecumstances you want the block deleted and/or
    inserted.
     
    Tom Smith, Oct 27, 2004
    #4
  5. devon

    devon Guest

    Hi Tom,

    Thanks for your reply.

    I will try to explain the process.

    1. I have a set of drawings in the "working" directory. They should ALL have a check_print_stamp inserted and ON.
    In some cases, a user may have switched off the stamp, or deleated it, but not purged it from the dwg.

    2. I run a "archive" routine. This binds xrefs, purges and the script & Lisp grab the "REV" attribute from the titleblock and when it saves the bound drawing to the "issued" directory it places the rev letter/number in the file name.

    3. I am trying to make the lisp do a couple of things with the check_print_stamp. If the stamp is on, delete it before binding takes place. If the stamp is off/forzen, thaw and delete before binding. Then the origonal, insert the stamp back in.

    4. this gives me 2 results.
    A. The "working" drawings will all end up with the stamp switched on.
    B. The drawings that were bound/purged and saved into the "issued" directory will not have the stamp at all.

    Does this help?

    Sorry, I should have explained this in my 1st post.

    Regards,
    Devon
     
    devon, Oct 27, 2004
    #5
  6. devon

    Tom Smith Guest

    As far as the stamp deletion, it appears you could eliminate the entire if
    statement:

    (if (tblsearch "layer" "Check_Print_Stamp")
    etc etc
    )

    And replace it with:

    (command "erase" (ssget "x" '((0 . "INSERT") (2 . "Check_Print_Stamp"))) "")

    This will delete all instances of the stamp, regardless of whether it's on a
    frozen layer. There's no need to check the layer status, unless you think it
    might be locked. Your routine isn't deleting the stamp unless the layer is
    frozen.

    As far as the insertion, I can only guess that this needs to take place at a
    different point in your script.
     
    Tom Smith, Oct 28, 2004
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.