Community
How can I pass the contents of a cell value (text string) to Acad? I want the user to click on a cell, then have lisp use the string as the name of a block to insert.
If the string is in Excel, I think you need to use VB.NET (or C#) instead of VisualLISP.
If the string is in a table in AutoCAD you can get to it with VisualLISP.
Try this code but make sure your Excel book is open
and set on desired tab before
;; local defun (defun RefSelection (/ *error* Excelapp Sel Sht 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 single cell with mouse to be bolded." "Range Selection" nil nil nil nil nil 8)))))))) (progn (vlax-put-property ExcelApp 'DisplayAlerts :vlax-true) (vlax-invoke Rng 'Select) ) ) (if Rng (setq vl (vlax-variant-value (vlax-get-property Rng 'value))) (setq vl nil)) (*error* nil) vl ) (defun C:Xss (/ ahha) (setq ahha (RefSelection)) (alert (strcat "Your block name is: " ahha)) ;; --- rest your code to insert block here --- : (princ) ) (princ "\nType Xss in the command line") (princ) (or (vl-load-com)(princ))
Thanks, Hallex! This looks like something I can work with. One question - what is the variable sel and where is it defined?
Sorry it's extrafluous here, it's going from other routine,
I was rewrite quickly , so you can remove it from there,
~'J'~