Author Topic: Updating data link via LISP help needed  (Read 2018 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: August 13, 2013, 05:28:38 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)



Code - Auto/Visual Lisp: [Select]
  1. ;; local defun
  2. (defun RefSelection (/ *error* addr c2 c2 Excelapp Sel Sht r1 r2 Rng Vl Wbk)
  3.   (defun *error*  (msg)
  4.     (if
  5.       (vl-position
  6.    msg
  7.    '("console break"
  8.      "Function cancelled"
  9.      "quit / exit abort"
  10.      )
  11.    )
  12.        (princ "Error!")
  13.        (princ msg)
  14.        )
  15.             (vl-catch-all-apply
  16.    (list Wbk "Close")
  17.       )
  18.  
  19.    (vl-catch-all-apply
  20.      (list ExcelApp "Quit")
  21.    )
  22.  
  23.   (mapcar
  24.     (function (lambda (x)(vl-catch-all-apply(function (lambda()
  25.       (if (not (vlax-object-released-p x))
  26.         (progn
  27.         (vlax-release-object x)
  28.         (setq x nil))
  29.       )
  30.          )
  31.     )
  32.             )
  33.       )
  34.          )
  35.     (list Sel Sht Wbk ExcelApp)
  36.   )  
  37.   (gc)
  38.   (gc)
  39.     (princ)
  40.     )
  41.  
  42.  
  43. (setq ExcelApp (vl-catch-all-apply
  44.           (function (lambda ()(vlax-get-or-create-object "Excel.Application")))))
  45.  
  46.       (setq Wbk
  47.         (vl-catch-all-apply
  48.           (function (lambda ()
  49.             (vlax-get-property ExcelApp "ActiveWorkBook"))))))
  50.   (progn
  51.     (alert "Excel WorkBook Must Be Open Before!")
  52.     (exit)
  53.     (*error* nil)
  54.     (princ)
  55.     )
  56.   )
  57. (setq Sht
  58.        (vl-catch-all-apply
  59.     (function (lambda ()
  60.            (vlax-get-property ExcelApp "ActiveSheet")))))
  61.  
  62. (vlax-put-property ExcelApp 'visible :vlax-true)
  63.  
  64. (vlax-put-property ExcelApp 'ScreenUpdating :vlax-true)
  65.  
  66. (vlax-put-property ExcelApp 'DisplayAlerts :vlax-false)
  67.  
  68.       (setq Rng
  69.         (vl-catch-all-apply
  70.           (function (lambda ()
  71.             (vlax-variant-value
  72.               (vlax-invoke-method
  73.                 (vlax-get-property Wbk 'Application)
  74.                 'Inputbox
  75.                 "Select a Range: "
  76.                 "Range Selection Example"
  77.                 nil
  78.                 nil
  79.                 nil
  80.                 nil
  81.                 nil
  82.                 )))))))
  83.   (progn
  84.     (vlax-put-property ExcelApp 'DisplayAlerts :vlax-true)
  85.  
  86.     (setq r1 (vlax-get-property Rng 'row))
  87.     (setq c1 (vlax-get-property Rng 'column))
  88.     (setq r2 (vlax-get-property (vlax-get-property Rng 'rows) 'count))
  89.     (setq c2 (vlax-get-property (vlax-get-property Rng 'columns) 'count))
  90.  
  91.     (setq addr (strcat (chr (+ 64 c1))
  92.              (itoa r1)
  93.              ":"
  94.              (chr (+ (ascii (chr (+ 64 c1))) (1- c2)))
  95.              (itoa (+ r1 (1- r2)))))
  96.  
  97.     (setq Rng (vlax-get-property sht 'Range addr))
  98.  
  99.     (vlax-invoke Rng 'Select)
  100.     )
  101.   )
  102.  
  103. (if Rng
  104.   (progn
  105.     (setq vl (mapcar (function (lambda (x)
  106.              (mapcar 'vlax-variant-value x)))
  107.            (vlax-safearray->list
  108.              (vlax-variant-value
  109.           (vlax-get-property Rng 'value2)))))
  110.     (princ "\n")
  111.       (alert (vl-princ-to-string vl))
  112.       )
  113.     (progn
  114.       (alert "Select Excel Range Before!")
  115.       (exit)
  116.       (*error* nil)
  117.       (princ)
  118.       )
  119.  
  120.     )
  121.  
  122. (*error* nil)
  123. )
  124.  
  125. ;;Usage:
  126. (defun C:Xss ()
  127.  
  128. (RefSelection)
  129. )
  130. (princ "\nType Xss in the command line")

<Edit: code tags added>
« Last Edit: August 13, 2013, 07:34:20 PM by CAB »

fixo

  • Guest
Re: Updating data link via LISP help needed
« Reply #1 on: August 14, 2013, 02:08:49 AM »
This code do nothing with cao link,
see the codes i was found on web

diego65

  • Newt
  • Posts: 51
  • Learning LISP is a cool thing
Re: Updating data link via LISP help needed
« Reply #2 on: August 15, 2013, 01:58:30 PM »
Thank you for your input Fix0,
Is there any instruction on how to run this program?

yuor help will be much appreciated it...
Joselo...