TheSwamp

Code Red => VB(A) => Topic started by: MustardTiger1989 on March 13, 2018, 12:15:27 PM

Title: Scaling a dynamic block using values in Excel
Post by: MustardTiger1989 on March 13, 2018, 12:15:27 PM
Hello,

I would like to set a block's dimensions to read an excel table's cell value and update the dimensions (i.e. change the size of the rectangle) based on values entered in an Excel table?

For example, given a rectangle that has dimensions X (Width) by Y (Height) and a table that has the X and Y values given in cells A1 and B1 linked from an excel spreadsheet.

I'm new to writing custom codes within AutoCAD, so any help/direction would be great!
Title: Re: Scaling a dynamic block using values in Excel
Post by: BIGAL on March 16, 2018, 03:46:47 AM
You need two programs say getxcel.lsp and lee-macs dynamic properties lisp. Those two have all the tools required.

Also search for shaft.lsp and shaft.dwg over at Cadtutor its a dwg linked to excel its really brilliant change excel cell, dwg updates its like autocad version 9 maybe 20  years ago, it shipped as a sample dwg. Will try to find.
Title: Re: Scaling a dynamic block using values in Excel
Post by: MustardTiger1989 on March 16, 2018, 03:05:17 PM
Hey,

Thanks for the reply. I was unable to locate the shaft.dwg file. Would you happen to have it?
Title: Re: Scaling a dynamic block using values in Excel
Post by: Yosso on April 04, 2018, 11:07:29 AM
Found a Shaft.lsp @ http://autocad.xarch.at/code/cadence/95-11/ghindex.html

Title: Re: Scaling a dynamic block using values in Excel
Post by: BIGAL on April 04, 2018, 10:49:47 PM
Did find it but it has a c# link that is an exe program and its 32bit not 64 so does not run.

You need to do some home work about using lisp the answers are in those two programs.

If I can find time will add to my to do list as an example of dynamic block link to excel.
Title: Re: Scaling a dynamic block using values in Excel
Post by: MustardTiger1989 on April 11, 2018, 10:17:12 AM
Okay, thanks for all your help!
Title: Re: Scaling a dynamic block using values in Excel
Post by: BIGAL on May 02, 2018, 06:21:38 AM
I need a bit more time for fine tuning but this works. It just a test for cells A1 & B1. It shows method rather than code.

Code: [Select]
;using excel to update rectang dynamic block.
; By Alan H May 2018
; simple rectang with default variables d1 & d2
(if (not GETEXCEL)(Load "getexcel"))
(if (not   LM:getdynpropvalue)(load "Dynamic block get-put.lsp"))

(OPENEXCEL "C:\\alan\\Alan.XLSX" "SHEET1" NIL)

(setq blk (vlax-ename->vla-object (car (entsel "Pick block"))))

(setq len  (getcell "a1"))
(LM:setdynpropvalue  blk "d1" len)

(setq  Ht (getcell "b1"))
(LM:setdynpropvalue  blk "d2" Ht)