Author Topic: Updating data link via LISP help needed  (Read 1155 times)

0 Members and 1 Guest are viewing this topic.

diego65

  • Newt
  • Posts: 51
  • Learning LISP is a cool thing
Updating data link via LISP help needed
« on: April 09, 2013, 02:56:39 PM »
Please I need this to work, any help will be very appreciate it.


What I am missing in this code?, please any help will be appreciate it.

What I am trying to accomplish, is to update information from a workbook or spreadsheet that is linked to our drawing's template by selecting the informatin from that workbook using the mouse insted of linking the info manually to a different cell on the spreadsheet.
Right now we create a new drawing from a template that it is linked to a generic cell in our spreasheet template, when new drawing is created, we need to link to a new cell from teh spreashet and we manually linked the info to a different cell on a spreasheet, and that is time cosuming.
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
                )))))))
  (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)
« Last Edit: August 13, 2013, 05:27:23 PM by Joselo247 »