vlax-catch-all-apply

Discussion in 'AutoCAD' started by jorgematheus, Aug 9, 2004.

  1. jorgematheus

    jorgematheus Guest

    Hi

    How to correct use of vlax-catch-all

    I have this routine
    (DEFUN c:pRUCOMPLE()
    (VL-LOAD-COM)
    (SETQ NVAL 0 NMAX 1000)
    ; (SETQ p (vl-catch-ALL-APPLY 'VLAX-CREATE-OBJECT '"COMPLE2.COXMPLE2"))
    (SETQ P (VL-CATCH-ALL-APPLY (SETQ OBJ (VLAX-CREATE-OBJECT "COMPLEX.COXMPLE2"))))
    (IF (vl-catch-all-error-p P)
    (PRINC "\nCAN´T CREATE OBJECT")
    )
    (WHILE (< NVAL NMAX)
    (PRINC NVAL)
    (if (/= (VLAX-INVOKE OBJ 'Comple) 1)
    (alert "error")
    )
    (setq nval (+1 nval))
    )
    )
    I´m trying to keep program runing and send an error message if the object can´t be created.

    Thank for the help
    Jorge Matheus
     
    jorgematheus, Aug 9, 2004
    #1
  2. jorgematheus

    PG. Guest

    Hi Jorge,

    The commented line in the code is in the right direction but with a
    correction.
    (SETQ p (vl-catch-ALL-APPLY 'VLAX-CREATE-OBJECT '("COMPLE2.COXMPLE2")))

    Or
    (SETQ p (vl-catch-ALL-APPLY 'VLAX-CREATE-OBJECT (list "COMPLE2.COXMPLE2")))

    Also should work.

    The uncommented (setq p (vl-catch-all-apply (setq obj ...) won't work. It's
    a syntax error.
     
    PG., Aug 9, 2004
    #2
  3. jorgematheus

    jorgematheus Guest

    Thank for your answered PG

    But it doesn't work

    Have you loaded it ??

    It should give you an error because comple2.comple2 is not a registered aplication.

    Thank
     
    jorgematheus, Aug 10, 2004
    #3
  4. jorgematheus

    Jürg Menzi Guest

    Hi Jorgematheus schrieb:

    You've to cover 'vl-catch-all-apply' with 'vl-catch-all-error-p':
    Code:
    (if (vl-catch-all-error-p
    (setq p (vl-catch-all-apply
    'vlax-create-object
    '("COMPLE2.COXMPLE2")
    )
    )
    )
    (princ "\nCan't create object.")
    (DoTheOtherStuff)
    )
    
    Cheers
     
    Jürg Menzi, Aug 10, 2004
    #4
  5. Jorge,

    I use this function as a means to catch errors when using vl* functions:

    ;;f:vlerr simplified error catching routine for vl-catch*
    ;;f:vlerr usage (setq en (f:vlerr 'vla-get-Area (list en) nil))
    ;;f:vlerr tag = true for debugging: princes error message

    (defun f:vlerr (fun lst tag / ret)
    (if (vl-catch-all-error-p (setq ret (vl-catch-all-apply fun lst)))
    (if tag
    (progn
    (princ (strcat "\n" (vl-catch-all-error-message ret) "\n"))
    (princ fun)
    (princ lst)
    nil
    )
    nil
    )
    (if (not ret) (setq ret T) ret)
    )
    (if (= (type ret) 'VL-CATCH-ALL-APPLY-ERROR) (setq ret nil))

    ret)



    However, in your case, the VLAX-CREATE-OBJECT returns nil if it can't create the application - so you could just use
    (cond
    ((not (setq obj (VLAX-CREATE-OBJECT "COMPLE2.COXMPLE2") ))
    (alert "Could not create COMPLE2.COXMPLE2.")
    )
    (T ...)
    )

    You could also use the vb method GetInterfaceObject to return more specific information - load f:vlerr and try this:

    (f:vlerr 'vla-GetInterfaceObject (list (vlax-get-acad-object) "COMPLE2.COXMPLE2") T)


    Peter
     
    petersciganek, Aug 10, 2004
    #5
  6. jorgematheus

    jorgematheus Guest

    Thank all for the help
     
    jorgematheus, Aug 10, 2004
    #6
  7. Wouldn't this work? Looks like if the object was not created, nil is
    returned.

    (if (not (setq obj (vlax-create-object "complex.coxmple2")))
    (princ "\nCould not create object!")
    )

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Aug 10, 2004
    #7
  8. jorgematheus

    jorgematheus Guest

    Yes it does. I have done before.

    It happen to me one in while, i get into a problem and tried the hard way.

    Einstein was really right

    The good: I learned additional thing.

    Thank
     
    jorgematheus, Aug 10, 2004
    #8
  9. I usually go the hard way too.

    Glad it helped.

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Aug 10, 2004
    #9
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.