Model Lisp Import Puncte
Model Lisp Import Puncte
My problem:
I have a collection of data (X Y Rotation) separated by spaces in a txt
format. Next I'm wanting to import this data into autocad utilizing
Import XYZ. However, instead of the XYZ, I basically want to do
XYRotation. This will allow me to insert a basic block and rotate it
to the proper Rotational value.
Questions:
1. Is it very difficult to make this change?
2. How do I go about making this change?
Code:
;;;--- IMPORTXYZ.lsp - Import coords from a file.
;;;
;;;
;;;--- Copyright 2005 by JefferyPSanders.com
;;; All rights reserved.
;;;
;;;--- Revisions
;;;
;;; 3/2/06 - Solved problem with blank Excel lines.
(defun C:IMPORTXYZ()
(setq exitMessage "\n IMPORTXYZ.lsp Complete. \n ")
;;;-----------------------------------------------------------------------------
----------
;;;--- Function to get the selected work*** name from the dialog
box
(defun saveVars3()
;;;--- Get the index of the selected ***
(setq sheetIndex(atoi(get_tile "sheetlist")))
;;;--- Use the index to find the name of the ***
(setq sheetName(nth sheetIndex sheetList))
)
;;;-----------------------------------------------------------------------------
----------
;;;-----------------------------------------------------------------------------
----------
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;
;;;
;;;--- Function to get the data from an Excel ***
;;;
;;; Parameter - fileName = Excel Spread *** name including path
if necessary
;;;
(defun XL_GET (fileName / myApp sysDrive dataList myWBooks myWBook
sht shtCnt mySheets
sheetList cnt shtName ddiag mySht mySheet
myRange myAddress
myCells 1stRow 1stCol LstRow LstCol
dataList)
;;;--- Get the system drive
(setq sysDrive (getenv "systemdrive"))
;;;--- If the excel object library is not found...load it
(if (null Library)
(progn
;;;--- Find out which version we should use
(setq Library
(cond
((findfile (strcat sysDrive "\\Program Files\\Microsoft
Office\\Office\\Excel8.olb")))
((findfile (strcat sysDrive "\\Program Files\\Microsoft
Office\\Office\\Excel9.olb")))
((findfile (strcat sysDrive "\\Program Files\\Microsoft
Office\\Office\\Excel10.olb")))
((findfile (strcat sysDrive "\\Program Files\\Microsoft
Office\\Office\\Excel.exe")))
((findfile (strcat sysDrive "\\Program Files\\Microsoft
Office\\Office10\\Excel.exe")))
((findfile (strcat sysDrive "\\Program Files\\Microsoft
Office\\Office11\\Excel.exe")))
((findfile (strcat sysDrive "\\Program Files\\Microsoft
Office\\Office11\\XL5EN32.OLB")))
)
)
;;;--- If the library was found...
(if Library
(progn
;;;--- Strip off
(setq LibVer (substr (vl-filename-base Library) 6))
(cond
((= LibVer "8")(princ "\n Opening Excel Version 8..."))
((= LibVer "9")(princ "\n Opening Excel Version 9..."))
((= LibVer "1")(princ "\n Opening Excel Version 10..."))
((= LibVer "") (princ "\n Opening Excel Version
2000+..."))
((= LibVer "3")(princ "\n Opening Excel Version
2003..."))
)
(vlax-import-type-library
:tlb-filename Library
:methods-prefix "JXCL-"
:properties-prefix "JXCL-"
:constants-prefix "JXCL-"
)
(princ " Done.")
)
(alert "Excel Object Library was not found!\n\nSee the XL
HELP on my web site.")
)
)
)
;;;--- If an excel application is not loaded, proceed...
(if (null myApp)
(progn
;;;--- If Excel...
(if(setq myapp(vlax-get-or-create-object "Excel.Application"))
(progn
;;;--- Open the workbook
(vlax-invoke-method (vlax-get-property myapp 'WorkBooks)
'Open fileName)
;;;--- Set it to invisible mode
(vla-put-visible myApp 0)
;;;--- Get the workbooks object
(setq myWBooks(vlax-get myApp "Workbooks"))
;;;--- Open the excel file
(setq myWBook(vla-open myWBooks fileName))
;;;;--- Get the sheets object
(setq mySheets(vlax-get myWBook "Sheets"))
;;;--- Get a list of the *** names
(princ "\n Getting *** Names from Excel...")
(setq shtCnt(vla-get-count mySheets))
(setq sheetList(list))
(setq cnt 1)
(while(<= cnt shtCnt)
(setq sht(JXCL-get-item mySheets cnt))
(setq shtName(vla-get-name sht))
(setq sheetList(append sheetList(list shtName)))
(setq cnt(+ cnt 1))
)
(princ " Done.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;--- Let the user select a *** ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;-----------------------------------------------------------------------------
----------
(defun xyz_help()
(setq helpList(list))
(setq helpList
(list
"ImportXYZ - Help"
" "
" Select a file and press the GETXYZ COORDS button. The
first 50"
" coordinates will show up in the list box for a sanity check
on"
" the results. Next, select the type of action you want to
perform."
" When you are ready, press the OKAY button."
" "
" FILENAME :"
" "
" The name of the file to open. Can be an ascii text file
that is delimited"
" by spaces, commas, tabs, or number of characters. Can
also be an EXCEL"
" file. Press the BROWSE FOR FILENAME button to select from
a directory."
" "
" "
" DECIMAL PLACES TO DISPLAY :"
" "
" This will effect the decimal places shown in the list box
only. This will"
" NOT alter the actual point in AutoCAD."
" "
" "
" GETXYZ COORDS : "
" "
" Press this button to open the file and import the
coordinates. The"
" first 50 results will be shown in the list box for a sanity
check."
" "
" "
" DRAW A NODE :"
" This will draw an autocad node entity [point] on each
coordinate."
" "
" "
" DRAW A CIRCLE :"
" This will draw an autocad circle entity on each
coordinate."
" "
" "
" DRAW LINES :"
" This will draw a line from coordinate to coordinate in
order."
" "
" "
" INSERT A BLOCK :"
" This will insert a block entity on every coordinate with
the option"
" to select the block from a directory."
" "
" "
" EDIT ATTRIBUTE :"
" This will insert a block entity on every coordinate with
the options"
" to select the block from a directory and input the tag
names to edit."
" This will also change the value of the attribute to match
the xyz coords."
" Try it using the included example block IMPORTXYZATT.dwg."
" "
" "
" INSERT EXCEL NOTE :"
" This function will write the data from the first column in
excel"
" on each coordinate with a leader. ( If each row contains
four items,"
" the program assumes the first column of data is a note. )
The program"
" will use the default text style and height."
" "
"
---------------------------------------------------------------------------"
" "
" If you still need help, please email jps@xxxxxxxxxxxxxxxxxxx
with any"
" questions."
" "
" "
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;--- We need to load a dialog box to show the help information
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;--- See if the definition is already loaded
(if (not (new_dialog "XYZ_HELP" dcl_id))
(progn
(alert "The IMPORTXYZ.dcl file could not be found.")
(exit)
)
)
;;;--- Add the layer list to the dialog box drop down list
(start_list "helplist")
(mapcar 'add_list helpList)
(end_list)
;;;--- Set up an action event
(action_tile "cancel" "(done_dialog)")
;;;--- Display the dialog box
(start_dialog)
)
;;;-----------------------------------------------------------------------------
----------
;;;-----------------------------------------------------------------------------
----------
;;;--- Function to save the setting from the secondary dialog box
(defun saveVars2()
(setq charNum nil)
(cond
((= (get_tile "type7") "1")(setq delimType 7))
((= (get_tile "type8") "1")(setq delimType 8))
((= (get_tile "type9") "1")(progn(setq charNum(atoi(get_tile
"charnum")))(setq delimType 9)))
)
;;;--- Return the delimiter type
delimType
)
;;;-----------------------------------------------------------------------------
----------
;;;-----------------------------------------------------------------------------
----------
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;--- We need to load a dialog box with selections for
delimiter types
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;--- See if the definition is already loaded
(if (not (new_dialog "FINDDELIM" dcl_id))
(progn
(alert "The IMPORTXYZ.dcl file could not be found.")
(exit)
)
)
;;;--- Disable the number of characters text box
(mode_tile "charnum" 1)
;;;--- Set up some action events
(action_tile "type7" "(modeCharNum 1)")
(action_tile "type8" "(modeCharNum 1)")
(action_tile "type9" "(modeCharNum 2)")
(action_tile "cancel" "(setq delimType nil)(done_dialog)")
(action_tile "accept" "(saveVars2)(done_dialog)")
;;;--- Display the dialog box
(start_dialog)
)
)
;;;--- Return the delimiter type
delimType
)
;;;-----------------------------------------------------------------------------
----------
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;--- Cycle through the data returned from the EXCEL
file
;;;
;;; Do this carefully. The excel file could contain
a lot of data
;;; so we do not want to have two list containing
the data.
;;;
;;; XList contains the data retrieved from EXCEL.
;;; Data in the form of:
;;; ( (rowNum xString) (rowNum yString) )
;;; or
;;; ( (rowNum xString) (rowNum yString) (rowNum
zString) )
;;;
;;; dataList will contain the data converted to a
point list.
;;; Data in the form of:
;;; (x y z) - z will be substituted in if
necessary as 0.0
;;;
;;; I need to convert the data from XList [ row
xyzString ] into a
;;; point list containing the x y and z coords [ "x
y z" ] for
;;; the dataList.
;;;
;;; So I will take the first row,
;;; whether it contains two items or three and make
one point list
;;; out of it containing an x y and z coord
(possibly fake z coord),
;;; then add it to the datalist. At the same time I
will remove the
;;; row from the XList. This way there will not be
two list of
;;; data that are possibly enormous in size.
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;-----------------------------------------------------------------------------
----------
;;;--- Check to see if we have more data in the list than x y &
z, a note perhaps
(if(> (length (car dataList)) 3)
(setq moreData T)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;--- Use the first 500 items to find the longest integer to
display
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;--- Set the longest integer variable up
(setq longestInt 0)
;;;--- Set up a counter so we don't exceed 500 values [ time
issue ]
(setq cnt 0)
;;;--- While we do not exceed the 500th item...
(while(< cnt 500)
;;;--- And there are items left in the dataList
(if(> (length dataList) cnt)
(progn
;;;--- Get the nth item from the dataList
(setq a(nth cnt dataList))
(if moreData
(progn
;;;--- Get the integer part of the x y and z coords
as a string
(setq x(itoa(fix(nth 1 a))))
(setq y(itoa(fix(nth 2 a))))
(setq z(itoa(fix(nth 3 a))))
)
(progn
;;;--- Get the integer part of the x y and z coords
as a string
(setq x(itoa(fix(nth 0 a))))
(setq y(itoa(fix(nth 1 a))))
(setq z(itoa(fix(nth 2 a))))
)
)
;;;--- Check the "integer" string lengths for a longer
one
(if(> (strlen x) longestInt)(setq longestInt(strlen x)))
(if(> (strlen y) longestInt)(setq longestInt(strlen y)))
(if(> (strlen z) longestInt)(setq longestInt(strlen z)))
)
)
;;;--- Increment the counter to get the next item
(setq cnt(+ cnt 1))
)
;;;-----------------------------------------------------------------------------
----------
;;;-----------------------------------------------------------------------------
----------
;;;-----------------------------------------------------------------------------
----------
(defun getAttTags(en)
;;;--- Set up a list to hold the tag names
(setq attList(list))
;;;--- Get the DXF group codes of the entity
(setq enlist(entget en))
;;;--- Get the name of the block
(setq blkName(cdr(assoc 2 enlist)))
;;;--- Check to see if the block's attribute flag is there
(if(cdr(assoc 66 enlist))
(progn
;;;--- Get the entity name
(setq en(entnext en))
;;;--- Get the entity dxf group codes
(setq enlist(entget en))
;;;--- Get the type of block
(setq blkType (cdr(assoc 0 enlist)))
;;;--- If group 66 then there are attributes nested inside this
block
(setq group66(cdr(assoc 66 enlist)))
;;;--- Loop while the type is an attribute or a nested
attribute exist
(while(or (= blkType "ATTRIB")(= group66 1))
;;;--- Get the block type
(setq blkType (cdr(assoc 0 enlist)))
;;;--- Get the block name
(setq entName (cdr(assoc 2 enlist)))
;;;--- Check to see if this is the first attribute
(if(= blkType "ATTRIB")
(progn
;;;--- Get the attribute tag
(setq attTag(cdr(assoc 2 enlist)))
;;;--- Add the tag to the tag list
(setq attList(append attList (list attTag)))
)
)
;;;--- Get the next sub-entity or nested entity as you will
(setq en(entnext en))
;;;--- Get the dxf group codes of the next sub-entity
(setq enlist(entget en))
;;;--- Get the block type of the next sub-entity
(setq blkType (cdr(assoc 0 enlist)))
;;;--- See if the dxf group code 66 exist. if so, there are
more nested attributes
(setq group66(cdr(assoc 66 enlist)))
)
)
)
;;;--- Return the tag list
attList
)
;;;-----------------------------------------------------------------------------
----------
;;;--- Function to get a block name from file and it's attribute tags
(defun getBlkFromFile()
;;;--- If the user selects a block...
(if(setq blk(getfiled "Select Block" "" "dwg" 16))
(progn
;;;--- See if the block name already exist
(if(not(member (vl-filename-base blk) blkList))
(progn
;;;--- Add the block name to the block list
(setq blkList(append blkList (list blk)))
;;;--- Add the block name to the block popup list in the
dialog box
(start_list "blocks")
(mapcar 'add_list blkList)
(end_list)
;;;--- Set the currently selected block to the item added
(set_tile "blocks" (itoa (- (length blkList) 1)))
)
;;;--- Else the block exist so, select it in the dialog block
popup list
(progn
(setq a(member (vl-filename-base blk) blkList))
(setq blkIndex (- (length blkList) (length a)))
(set_tile "blocks" (itoa blkIndex))
)
)
)
)
)
;;;-----------------------------------------------------------------------------
----------
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;
;;; 888 888 888 8888888 8888 888
;;;
;;; 8888 8888 88888 888 88888 888
;;;
;;; 88888 88888 888 888 888 888888 888
;;;
;;; 888888 888888 888 888 888 888 888888
;;;
;;; 888 88888 888 88888888888 888 888 88888
;;;
;;; 888 888 888 888 888 8888888 888 8888
;;;
;;;
;;;
;;;
;;;
;;; 888 888888888 888888888
;;;
;;; 88888 888 888 888 888
;;;
;;; 888 888 888 888 888 888
;;;
;;; 888 888 888888888 888888888
;;;
;;; 88888888888 888 888
;;;
;;; 888 888 888 888
;;;
;;;
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;