Hi there I made something like tis a few weeks ago plese use the following code and give me your opinion!
It will input the block called point in your dwg in the points with coordinates x,y with atributes Asx nad ASy taken from xls file.
1. create block Point.dwg usinf wblock function
this block must have atributes Asx and Asy definined in this order.and paste it in your acad/support folder
2. create xls file with 4 columns x,y Asx ASy.
3. Use this to create a dcl file called Zbl2DXLS.DCL in you acad suport folder.
Zbl2DXLS: dialog {
label = "INPUT BLOCKS FROM FILE";
width=5;
: boxed_row {
label=" Chose Input file !";
: edit_box { // defines the INPUT FILE edit box
label = "";
key = "path1";
edit_width = 40;
fixed_width = true;
alignment =left;
}
: button {// defines the INPUT FILE BUTON
alignment=right;
fixed_height=true;
key="BROW";
label= "BROWSE";
fixed_width=true;
}
}
: boxed_radio_row { // defines the radio button areas
label = "What is the Measure Unit of Coordinates in Your File?";
fixed_width = true;
alignment = centered;
children_alignment = centered;
: radio_button { // defines the METERS radio button
label = "METERS";
key = "ME";
fixed_width =true;
}
: radio_button { // defines the CENTIMETERS radio button
label = "CENTIMETERS";
key = "CE";
fixed_width = true;
}
: radio_button { // defines the MILIMRETRS radio button
label = "MILIMETERS";
key = "MI";
fixed_width =true;
}
}
: column{
:boxed_row {
alignment = centered;
children_alignment = left;
fixed_width=true;
label = "Scale Factors to Apply in your DWG";
:column{
: text {
alignment=centered;
is_bold= true;
height=0.8;
label= "Set DWG Scale : 1/?";
}
: edit_box { // defines the dRAWING sCALE edit box
key = "DWSC";
edit_width = 4;
fixed_width = true;
alignment=centered;
}
}
: spacer { width =0.1; }
:column{
: text {
alignment=centered;
is_bold= true;
height=0.8;
label = "Set Block Scale:";
}
: edit_box { // defines the Block Scale edit box
key = "BSC";
edit_width =4;
fixed_width =true;
alignment=centered;
}
}
}
:boxed_row {
alignment = centered;
fixed_width =true;
label = "Position of First Block in your DWG.";
:row{
: edit_box { // defines the ROW edit box
label = "ROW";
key = "ROW1";
edit_width = 4;
alignment = left;
fixed_width =true;
}
: spacer { width =0.1; }
: edit_box { // defines the COLUMN Scale edit box
label = "COLUMN";
key = "COLUMN1";
edit_width =4;
alignment = right;
fixed_width =true;
}
}
}
}
: boxed_row {
label=" Select ZERO Point !";
: edit_box { // defines the ZERO POINTXcoord edit box
label = "X:";
key = "ZEROX";
edit_width = 10;
fixed_width = true;
alignment =left;
}
: edit_box { // defines the ZERO POINTYcoord edit box
label = "Y:";
key = "ZEROY";
edit_width = 10;
fixed_width = true;
alignment =left;
}
: edit_box { // defines the ZERO POINTZcoord edit box
label = "Z:";
key = "ZEROZ";
edit_width = 10;
fixed_width = true;
alignment =left;
}
: button {// defines the ZERO POINT PICK BUTON
alignment=right;
fixed_height=true;
key="PICK";
label= "PICK";
fixed_width=true;
mnemonic = "P";
}
}
: row { // defines the OK/Cancel button row
width=15;
: spacer { width =0.02;}
: button { // defines the OK button
label = "OK";
is_default = true;
key = "accept";
width = 2.5;
}
: spacer { width =0.01; }
: button { // defines the Cancel button
label = "Cancel";
is_cancel = true;
key = "cancel";
width = 2.5;
}
: spacer { width =0.02;}
}
}
4. Use the folowing to create the lisp routine ZMEIblock2dfromXLS.lsp
(princ "\nZMEiblock2DfromXLS - LOADED"

(princ "\nStart with 'ZBL2DXLS'"

(vl-load-com)
(defun vlxx-TypeLib-Excel9 ()
(findfile
(strcat
(getenv "SYSTEMDRIVE"

; Windows NT and 2000, example: "C:"
"\\Program Files\\Microsoft Office\\Office\\Excel9.olb" ; OFFICE 2000 OLB file
) ;_ end of strcat
) ;_ end of findfile
) ;_ end of defun
(defun vlxx-Load-TypeLib-Excel9 (/ tlbfile out)
(cond
((null msxl-xl24HourClock)
(if (setq tlbfile (vlxx-TypeLib-Excel9))
(progn
(princ "\nInitializing Microsoft Excel 2000..."

(vlax-Import-Type-Library
:tlb-filename tlbfile :methods-prefix
"msxl-"

roperties-prefix "msxl-"
:constants-prefix "msxl-"
) ;_ end of vlax-Import-Type-Library
;_ end of vlax-Import-Type-Library
;_ end of vlax-Import-Type-Library
;_ end of vlax-Import-Type-Library
(if msxl-xl24HourClock
(setq out T)
) ;_ end of if
) ;_ end of progn
) ;_ end of if
)
(T (setq out T))
) ;_ end of cond
out
) ;_ end of defun
;;; Note: <xfile> is the fully-qualified filename to be opened,
;;; <dmode> is either "SHOW" or "HIDE" depending upon whether
;;; you want the Excel session to be accessible to the user directly.
(defun vlxx-Open-Excel9-Exist (xfile dmode / appsession)
(princ "\nOpening Excel Spreadsheet file..."

(cond
((setq appsession (vlax-Get-or-Create-Object "Excel.Application.9"

)
(vlax-invoke-Method
(vlax-Get-Property appsession 'WorkBooks)
'Open
xfile
) ;_ end of vlax-invoke-Method
(if (= (strcase dmode) "SHOW"

(vla-Put-Visible appsession 1)
(vla-Put-Visible appsession 0)
) ;_ end of if
)
) ;_ end of cond
appsession
) ;_ end of defun
;;; Get cell object relative to range using <relrow> and <relcol>
(defun vlxx-Excel-Get-Cell (rng relrow relcol)
(vlax-Variant-Value
(msxl-Get-Item
(msxl-Get-Cells rng)
(vlax-Make-Variant relrow)
(vlax-Make-Variant relcol)
) ;_ end of msxl-Get-Item
) ;_ end of vlax-Variant-Value
) ;_ end of defun
;;; Return value of contents in cell (row, col)
(defun vlxx-Excel-Get-CellValue (row col)
(vlax-Variant-Value
(msxl-Get-Value
(vlxx-Excel-Get-Cell
(msxl-Get-ActiveSheet xlapp)
row
col
) ;_ end of vlxx-Excel-Get-Cell
) ;_ end of msxl-Get-Value
) ;_ end of vlax-Variant-Value
) ;_ end of defun
;;; Return a list of cell values for a given row
(defun vlxx-Excel-Get-RowValues
(row startcol numcells / next out)
(setq next startcol)
(repeat numcells
(setq out (if out
(append out (list (vlxx-Excel-Get-CellValue row next)))
(list (vlxx-Excel-Get-CellValue row next))
) ;_ end of if
next (1+ next)
) ; setq
) ; repeat
out
) ;_ end of defun
;;; Return a Number of Non NILL values for a given COLUMN
;;;starting from a given ROW
(defun vlxx-Excel-Get-ColumnValues
(col startrow / next out)
(setq next startrow)
(setq out (vlxx-Excel-Get-CellValue next col))
(princ out)
(while (/= out nil)
(setq out (vlxx-Excel-Get-CellValue next col)
next (1+ next)
block_conter (- (- next 1) startrow)
) ;_ end of setq
) ;_ end of while
(princ "\nBlock Definitions Found - "

block_conter
) ;_ end of defun
;;; Return a list of lists where each sublist is one row of information
;;; in a top-to-bottom order in the spreadsheet range
;;;
;;; (vlxx-Excel-GetRangeValues-ByRows sRow sCol nRows nCols)
(defun vlxx-Excel-GetRangeValues-ByRows
(startrow startcol numrows numcols / nextrow rowlst outlst)
(setq nextrow startrow)
(repeat numrows
(setq rowlst (vlxx-Excel-Get-RowValues nextrow startcol numcols)
outlst (if outlst
(append outlst (list rowlst))
(list rowlst)
) ;_ end of if
nextrow (1+ nextrow)
) ;_ end of setq
) ;_ end of repeat
outlst
) ;_ end of defun
(defun C:ZBL2DXLS ()
(setq dcl_id (load_dialog "Zbl2DXLS.dcl"

) ;Load the dialog box.
(setq what_next 5)
(setq cnt 1)
(setq
dialogLoaded T
dialogShow T
dwg_path (getvar "DWGPREFIX"
INUNITS "METER"
METERYES "1"
CENTIMETERYES "0"
MILIMETERYES "0"
DWSC1 50
BSC1 20
beginROW 1
beginColumn 1
Xoo "0.0000"
Yoo "0.0000"
Zoo "0.0000"
ZEROPOINT (list Xo Yo Zo)
) ;_ end of setq
(while (>= what_next 5) ;Begin display loop.
(if (null (new_dialog "Zbl2DXLS" dcl_id)) ;Initialize dialog
(exit) ;box, exit if nil
) ;_ end of if
(set_tile "path1" dwg_path)
(set_tile "ME" METERYES)
(set_tile "CE" CENTIMETERYES)
(set_tile "MI" MILIMETERYES)
(set_tile "DWSC" (rtos DWSC1))
(set_tile "BSC" (rtos BSC1))
(set_tile "ROW1" (rtos beginRow))
(set_tile "COLUMN1" (rtos beginColumn))
(set_tile "ZEROX" Xoo)
(set_tile "ZEROY" Yoo)
(set_tile "ZEROZ" Zoo)
(action_tile
"ME"
"(setq INUNITS \"METER\"

"
) ;_ end of action tile
(action_tile
"CE"
"(setq INUNITS \"CENTIMETER\"

"
) ;_ end of action tile
(action_tile
"MI"
"(setq INUNITS \"MILIMETER\"

"
) ;_ end of action tile
(action_tile
"BROW"
(strcat
"(progn (set_tile \"path1\" (getfiled \"Get file with data\" (getvar \"DWGPREFIX\"

\"xls"
"\" 4)))"
) ;_ end of strcat
) ;_ end of action_tile
(action_tile
"cancel"
(strcat "(progn (setq UserClick nil) (done_dialog 4))"

) ;_end of action tile
(action_tile
"accept"
(strcat
"(progn (setq DWGSCALE (get_tile \"DWSC\"

)"
"(setq filename (get_tile \"path1\"

)"
"(setq block_scale (get_tile \"BSC\"

)"
"(setq ROW (get_tile \"ROW1\"

)"
"(setq COLUMN (get_tile \"COLUMN1\"

)"
"(setq Xo (get_tile \"ZEROX\"

)"
"(setq Yo (get_tile \"ZEROY\"

)"
"(setq Zo (get_tile \"ZEROZ\"

)"
"(setq ZEROPOINT (list Xo Yo Zo))"
"(setq UserClick T)"
"(done_dialog 3))"
) ;_ end of strcat
) ;_ end of action_tile
(action_tile
"PICK"
(strcat
"(progn (setq dwg_path (get_tile \"path1\"

)"
"(setq METERYES (get_tile \"ME\"

)"
"(setq CENTIMETERYES (get_tile \"CE\"

)"
"(setq MILIMETERYES (get_tile \"MI\"

)"
"(setq DWSC1 (atoi (get_tile \"DWSC\"

))"
"(setq BSC1 (atoi (get_tile \"BSC\"

))"
"(setq beginRow (atoi (get_tile \"ROW1\"

))"
"(setq beginColumn (atoi (get_tile \"COLUMN1\"

))"
"(done_dialog 6))"
) ;_ end of strcat
) ;_ end of action_tile
(setq what_next (start_dialog)) ;Display dialog box
(cond
((= what_next 6)
(progn
(setq ZERO (getpoint "\n Pick a ZERO point: "

)
(setq Xoo (rtos (car ZERO) 2 4))
(setq Yoo (rtos (cadr ZERO) 2 4))
(setq Zoo (rtos (caddr ZERO) 2 4))
) ;_ end of progn
)
((= what_next 3)
(done_dialog)
)
((= what_next 4)
(done_dialog)
)
) ;_ end of cond
) ;_ end of while
(unload_dialog dcl_id)
(if
UserClick ; User clicked Ok
(progn
(setq cmdecho1 (getvar "cmdecho"

)
(setvar "cmdecho" 0)
(setq osmode1 (getvar "osmode"

)
(setvar "osmode" 0)
(setq ATTREQ1 (getvar "ATTREQ"

)
(setvar "ATTREQ" 1)
(princ (strcat "\nInput File Set To:" filename))
(princ "\nZERO point set to:"

(princ ZEROPOINT)
(princ (strcat "\nInput Units set to: " INUNITS))
(if (= INUNITS "METER"

(setq SCALE 1000)
(if (= INUNITS "CENTIMETER"

(setq SCALE 10)
(setq SCALE 1)
) ;_ end of if
) ;_ end of if
(Princ (strcat "\nDrawing Scale factor set to: 1/"
DWGSCALE
) ;_ end of strcat
) ;_ end of Princ
(Princ (strcat "\nBlock Scale factor set to: 1/"
block_scale
) ;_ end of strcat
) ;_ end of Princ
(cond
((vlxx-Load-TypeLib-Excel9)
(cond
((setq xlfile filename)
(setq G$XFILE xlfile)
(cond
((setq xlapp (vlxx-Open-Excel9-Exist xlfile "HIDE"

)
(setq ash (msxl-Get-ActiveSheet xlapp))
(setq range (msxl-Get-ActiveCell xlapp))
;;; Starts non NIL Rows counter "VLXX-EXCEL-GET-COLUMNVALUES"
;;; ACCORDING TO VALUES FOR START ROW AND
;;; START COLUMN TAKEN FROM THE DCL WINDOW
;;; Assigns the Block_Counter value to "Patka" variable
(setq COLUMN2 (atoi COLUMN)
ROW2 (atoi ROW)
) ;_ end of setq
(setq patka (vlxx-Excel-Get-ColumnValues COLUMN2 ROW2))
(princ patka)
;;; Starts "vlxx-Excel-GetRangeValues-ByRows"
;;; ACCORDING TO VALUES OF ROW2 COLUNM2 for number of Rows determined by row Counter
;;; "VLXX-EXCEL-GET-COLUMNVALUES"
;;; Returns Xllist variable - Block definitions from spredsheet
(setq Columns 5)
(setq Rows patka)
(setq
xlist (vlxx-Excel-GetRangeValues-ByRows
ROW2
COLUMN2
Rows
Columns
) ;_ end of vlxx-Excel-GetRangeValues-ByRows
) ;_ end of setq
;;; Print out each sublist of "XLIST" to see what you got...
(princ "\nIserting Blocks: \n"

(foreach mbr xlist
(progn (princ mbr)
(setq Pt_name (if (numberp (nth 0 mbr))
(rtos (nth 0 mbr))
(nth 0 mbr)
) ;_ end of if
Xcoord
(nth 1 mbr)
Ycoord
(nth 2 mbr)
Asx
(if (numberp (nth 3 mbr))
(rtos (nth 3 mbr))
(nth 3 mbr)
) ;_ end of if
Asy
(if (numberp (nth 4 mbr))
(rtos (nth 4 mbr))
(nth 4 mbr)
) ;_ end of if
Pt_coord
(list
(+ (atof Xo)
(/ (* SCALE Xcoord)
(atof DWGSCALE)
) ;_ end of /
) ;_ end of +
(+ (atof Yo)
(/ (* SCALE Ycoord)
(atof DWGSCALE)
) ;_ end of /
) ;_ end of +
) ;_ end of list
) ;_ end of setq
(command "_-insert"
;inserting block
"point" ; block name
Pt_coord
; block input coordinates
block_scale ; block scale factor
"" ; block rotation angle
""
Pt_name ; Atribute Point name
Asx ; atribute Asx
Asy ; atribute Asy
) ;_ end of command
) ;_ end of progn
(terpri)
) ;_ end of foreach
(setq xlist nil)
(vlxx-Excel-Quit xlapp)
)
(T (princ "\nFailed to start application session."

)
) ;_ end of cond
)
) ;_ end of cond
)
(T (alert "Failed to initialize type library for Excel 2000..."

)
) ;_ end of cond
(setvar "cmdecho" cmdecho1)
(setvar "osmode" osmode1)
(setvar "ATTREQ" ATTREQ1)
(princ)
) ;_ end of progn
) ;_ end of if USERCLICK
) ;_ end of defun
;;; Quit Excel and Close
(defun vlxx-Excel-Quit (appsession)
(vlax-Invoke-Method appsession 'QUIT)
(if (vlax-Property-Available-p appsession 'Visible)
(princ "\nExcel Application still active!"

(princ "\nExcel Application has been closed."

) ;_ end of if
) ;_ end of defun
;;; Force any open session of Excel to close
(defun vlxx-Excel-Kill ()
(while (vlax-Get-Object "Excel.Application.9"

(vlxx-Excel-Quit (vlax-Get-Object "Excel.Application.9"

)
) ;_ end of while
) ;_ end of defun
5. NOE the excel9.olb(office2000) in definition VLXX-TypeLib-Excel9 must be changed to Excel8.olb for office 97 or to XL5EN32.olb for office XP. There is a simple way to make it to work automaticy.
HOPE THIS WILL HELP.
ZMEI