Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Passing Excel cell content to Acad?

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
638 Views, 4 Replies

Passing Excel cell content to Acad?

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.

4 REPLIES 4
Message 2 of 5
tcorey
in reply to: Anonymous

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.



Tim Corey
MicroCAD Training and Consulting, Inc.
Redding, CA
Autodesk Gold Reseller

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
Message 3 of 5
Hallex
in reply to: Anonymous

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))

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 4 of 5
Anonymous
in reply to: Hallex

Thanks, Hallex! This looks like something I can work with. One question - what is the variable sel and where is it defined?

Message 5 of 5
Hallex
in reply to: Anonymous

Sorry it's extrafluous here, it's going from other routine,

I was rewrite quickly , so you can remove it from there,

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost