If & and

Discussion in 'AutoCAD' started by Adesu, Feb 22, 2005.

  1. Adesu

    Adesu Guest

    Here is a script from Luis,
    My question is what is function of "if & and" ?,because in my opinion if
    this code without "if,and,progn",it will work too,I am not yet using or
    seldom to use if & and,thanks for your comment

    Another alternative... might be this:

    (vl-load-com)
    (defun C:SWT (/ first second obj1 obj2 a b)
    (if
    (and
    (setq first (car (entsel "\nSelect text to switch: ")))
    (setq second (car (entsel "\nWith this text: ")))
    ) ; end of and
    (progn
    (setq obj1 (vlax-ename->vla-object first)
    obj2 (vlax-ename->vla-object second)
    a (vlax-get obj2 'insertionpoint)
    b (vlax-get obj1 'insertionpoint))
    (vlax-put obj1 'insertionpoint a)
    (vlax-put obj2 'insertionpoint b)
    ) ; end of
    progn
    ) ; end of if
    (princ)
    ) ; end of
    defun
     
    Adesu, Feb 22, 2005
    #1
  2. Do this test....

    Remove the if/and

    Pick nothing.... what happens?
     
    Luis Esquivel, Feb 22, 2005
    #2
  3. The condition for this routine to work is to have both items valid... inside of (and ...) we can read the object type.... so if something else is selected... the routine will stop there.

    hth
     
    Luis Esquivel, Feb 22, 2005
    #3
  4. Adesu

    Adesu Guest

    Command: swt

    Select text to switch:
    With this text: ; error: bad argument type: lentityp nil >>>here displayed
    on screen !

    Command:
     
    Adesu, Feb 22, 2005
    #4
  5. Adesu

    Alaspher Guest

    Hi, Ade!
    Code:
    (defun c:swt (/ first second obj1 obj2 a b)
    (if (and (setq first (car (entsel "\nSelect text to switch: ")))
    (setq second (car (entsel "\nWith this text: ")))
    ) ;_ only if couple of entities selected (user input control)
    (progn (setq obj1 (vlax-ename->vla-object first) ;_ this code will start
    obj2 (vlax-ename->vla-object second)
    a    (vlax-get obj2 'insertionpoint)
    b    (vlax-get obj1 'insertionpoint)
    )
    (vlax-put obj1 'insertionpoint a)
    (vlax-put obj2 'insertionpoint b)
    )
    )
    (princ)
    )
    But this routine (not a script) isn't good functionally.
    If user pick not a TEXT or a TEXT is fit will be error.

    For more safety example see code below:
    Code:
    (defun c:swt1 (/ first second a b)
    (if (and (setq first (safety-obj-select "TEXT" "\nSelect text to switch <Exit>: "))
    (setq second (safety-obj-select "TEXT" "\nWith this text <Exit>: "))
    )
    (progn (setq first	(vlax-ename->vla-object first)
    second	(vlax-ename->vla-object second)
    a	(vla-get-insertionpoint second)
    b	(vla-get-insertionpoint first)
    )
    (vla-move second a b)
    (vla-move first b a)
    )
    )
    (princ)
    )
    
    (defun safety-obj-select (etype prmpt / ent)
    (setvar "ERRNO" 0)
    (setq etype (strcase etype))
    (while
    (and (/= etype
    (if (and (setq ent (vl-catch-all-apply (function entsel) (list prmpt)))
    (not (vl-catch-all-error-p ent))
    )
    (cdr (assoc 0 (entget (setq ent (car ent)))))
    )
    )
    (/= 52 (getvar "ERRNO"))
    (not (vl-catch-all-error-p ent))
    )
    (print (getvar "ERRNO"))
    (setvar "ERRNO" 0)
    )
    (if (vl-catch-all-error-p ent)
    (progn (princ (vl-catch-all-error-message ent)) nil)
    ent
    )
    )
    Best regards!
     
    Alaspher, Feb 22, 2005
    #5
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.