PDA

View Full Version : Routine to set any point as a datum to a bunch of coordinates


noadea
2006-12-11, 02:09 PM
I want to create a bunch of rectangulars with number themselves. But the number and center points of each rectangular are given in the excel file which are column B for the rectangular number, column C for x-coordinate and column D for y-coordinate of the center point for those rectangulars.
The datum of these coordinates can be any point which means I can pick any point and set as a datum ie (0,0).
How to solve this problem? Any help would be much appreciated.
Please do write comment on your code and explain coz I'm new to lisp.

fixo
2006-12-11, 05:07 PM
Hi again :)

Send me your Excel file
A few time ago I have to solved almost the similar task

~'J'~

fixo
2006-12-11, 06:17 PM
Hi, Rohaya.Shaffini
For the first step you can use this routine
to get the data from highlighted (selected) diapazone
of the certain Excel spreadsheet
Open Excel file then select the diapazone you need
and minimize Excel window but do not close,
it's must be still to open
Then run this lisp
Sorry I can't explain to you more, you know why :)


(defun EXV ( / ExcData ExcelApp UsdRange Wbk)
;; load ActiveX extension library
(vl-load-com)
;; get Excel object
(setq ExcelApp (vlax-get-object "Excel.Application"))
;; get Excel active book
(setq Wbk (vlax-get-property ExcelApp "ActiveWorkbook"))
;; get selected diapazone of Excel sheet
(setq UsdRange (vlax-get-property ExcelApp "Selection")
;; get value of selected diapazone
ExcData (vlax-safearray->list
(vlax-variant-value
(vlax-get-property UsdRange "Value"))));or Value2
;; convert array to list of values
(setq ExcData (mapcar (function (lambda (x)
(mapcar 'vlax-variant-value x))) ExcData))
;; close Excel
(vl-catch-all-apply
'vlax-invoke-method
(list Wbk "Close")
)

(vl-catch-all-apply
'vlax-invoke-method
(list ExcelApp "Quit")
)
;; release objects
(mapcar
(function (lambda (x)
(if (not (vlax-object-released-p x))

(vlax-release-object x)
)
)
)
(list UsdRange Wbk ExcelApp)
)
;; clean up
(setq UsdRange nil
Wbk nil
ExcelApp nil
)
;; clean memory
(gc)
(gc)
ExcData
)

(defun C:test()
(setq data (exv))
(foreach indx data
(print indx))
)
;(C:test)


After I have a got your Excel file, I'll to write a whole stuff

~'J'~