Author Topic: error bad argument type vla-object #<%catch-all-apply-error%>  (Read 3027 times)

0 Members and 1 Guest are viewing this topic.

diego65

  • Newt
  • Posts: 51
  • Learning LISP is a cool thing
error bad argument type vla-object #<%catch-all-apply-error%>
« on: February 01, 2013, 01:06:22 PM »
What I am missing in this code, please any help will be appreciate it.

What I am trying to accomplish, is to update info from a workbook or spreadsheet that is linked to our drawing template by selecting the informatin from that workbook using the mouse insted of linking the info manually.
E.g. drawing number, Date, Project Number etc, these atributtes changes as drawings are created, then the user must go to the Datalink within Autocad and poinitng to the right cell within the workbook.

does this makes sense?

File Location:       C:\Work Project\Data Table Link\
File Name:      Basemap Link.xlsx
Sheet (Tab) Name:   Revison (in where the information is to be linked onto the active drawing)



;; local defun
(defun RefSelection (/ *error* addr c2 c2 Excelapp Sel Sht r1 r2 Rng Vl Wbk)
  (vl-load-com)
  (defun *error*  (msg)
    (if
      (vl-position
   msg
   '("console break"
     "Function cancelled"
     "quit / exit abort"
     )
   )
       (princ "Error!")
       (princ msg)
       )
            (vl-catch-all-apply
   'vlax-invoke-method
   (list Wbk "Close")
      )

   (vl-catch-all-apply
     'vlax-invoke-method
     (list ExcelApp "Quit")
   )

  (mapcar
    (function (lambda (x)(vl-catch-all-apply(function (lambda()
      (if (not (vlax-object-released-p x))
        (progn
        (vlax-release-object x)
        (setq x nil))
      )
         )
    )
            )
      )
         )
    (list Sel Sht Wbk ExcelApp)
  ) 
  (gc)
  (gc)
    (princ)
    )
 

(setq ExcelApp (vl-catch-all-apply
          (function (lambda ()(vlax-get-or-create-object "Excel.Application")))))

(if (vl-catch-all-error-p
      (setq Wbk
        (vl-catch-all-apply
          (function (lambda ()
            (vlax-get-property ExcelApp "ActiveWorkBook"))))))
  (progn
    (alert "Excel WorkBook Must Be Open Before!")
    (exit)
    (*error* nil)
    (princ)
    )
  )
(setq Sht
       (vl-catch-all-apply
    (function (lambda ()
           (vlax-get-property ExcelApp "ActiveSheet")))))

(vlax-put-property ExcelApp 'visible :vlax-true)

(vlax-put-property ExcelApp 'ScreenUpdating :vlax-true)

(vlax-put-property ExcelApp 'DisplayAlerts :vlax-false)

(if (not (vl-catch-all-error-p
      (setq Rng
        (vl-catch-all-apply
          (function (lambda ()
            (vlax-variant-value
              (vlax-invoke-method
                (vlax-get-property Wbk 'Application)
                'Inputbox
                "Select a Range: "
                "Range Selection Example"
                nil
                nil
                nil
                nil
                nil
                8))))))))
  (progn
    (vlax-put-property ExcelApp 'DisplayAlerts :vlax-true)

    (setq r1 (vlax-get-property Rng 'row))
    (setq c1 (vlax-get-property Rng 'column))
    (setq r2 (vlax-get-property (vlax-get-property Rng 'rows) 'count))
    (setq c2 (vlax-get-property (vlax-get-property Rng 'columns) 'count))

    (setq addr (strcat (chr (+ 64 c1))
             (itoa r1)
             ":"
             (chr (+ (ascii (chr (+ 64 c1))) (1- c2)))
             (itoa (+ r1 (1- r2)))))

    (setq Rng (vlax-get-property sht 'Range addr))

    (vlax-invoke Rng 'Select)
    )
  )

(if Rng
  (progn
    (setq vl (mapcar (function (lambda (x)
             (mapcar 'vlax-variant-value x)))
           (vlax-safearray->list
             (vlax-variant-value
          (vlax-get-property Rng 'value2)))))
    (princ "\n")
      (alert (vl-princ-to-string vl))
      )
    (progn
      (alert "Select Excel Range Before!")
      (exit)
      (*error* nil)
      (princ)
      )

    )

(*error* nil)
)

;;Usage:
(defun C:Xss ()

(RefSelection)
(princ)
)
(princ "\nType Xss in the command line")
(princ)

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: error bad argument type vla-object #<%catch-all-apply-error%>
« Reply #1 on: February 02, 2013, 08:48:18 AM »
Could you please add [ CODE ] tags to your code? The # button would do it for you.

Other than that have you tried debugging your code in VLIDE? You can set a break-point anywhere (using F9) then run your code and the IDE will stop at the breakpoint. You can then add Debug/Add Watch... or Watch Last Evaluation. Then you can use F8 to step through the code one item at a time to see where the error occurs and what the last value for your variable(s) was. Makes it much easier to find such errors.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

diego65

  • Newt
  • Posts: 51
  • Learning LISP is a cool thing
Re: error bad argument type vla-object #<%catch-all-apply-error%>
« Reply #2 on: February 04, 2013, 09:53:21 AM »
Hi Inerb,

Where do I run the debugger to test the error?
How to I add the Watch to see what I am missing?
And what to you mean by CODE?
Thank you for your reply, I really appreciate it...

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: error bad argument type vla-object #<%catch-all-apply-error%>
« Reply #3 on: February 04, 2013, 10:45:17 AM »
Where do I run the debugger to test the error? How to I add the Watch to see what I am missing?

Debugging Code with the Visual LISP IDE

And what to you mean by CODE?

Formatting code in your posts