帮助,导入。txt表格t
大家好!我试图找到一个lisp来导入表。txt文件到autocad,但我不知道从哪里开始这项任务。我有一个想法是:
将表格复制到excel,然后粘贴到autocad中。
问题是我有很多表要导入,如果我这样做,将需要很长时间。
遵循表格模型:
SoI需要填写字段total weight和profile Name
遵循具有所需结果的文件。
我还需要把总重量加上10%
有什么想法可以帮我完成这项任务吗?
对不起我的英语。
实例图纸
桌子txt文件 真 的!这将涉及很多编程,但像大多数使用LISP的事情一样,这是完全可能的。我不确定你的第一个想法在你准备好一个相当广泛的LISP程序之前是否会变得简单和快速。
有几个问题,我假设你的文本文件总是以相同的格式?有什么理由把长度写成科学记数法而不是另一种格式吗?有人可能可以帮你解决这个问题,但需要一些真正的编码才能正确解析文件,然后将文本放置在图形中所需的位置。如果是我,我会坚持从Excel中剪切和粘贴。但那只是我。 嗨,比尔,是的,文件的格式总是一样的,这个文件是另一个程序的输出,我可以选择数值符号。
我制作了一个excel宏来解析数据,现在我试图找到一种方法,在excel中制作表格,然后导入到cad。这容易做吗?
以下是我在vb中的代码:
Sub teste2()
'
' test2 Macro
' Adjust table
'
'
Columns("A:A").EntireColumn.AutoFit
Rows("1:7").Select
Range("A7").Activate
Selection.ClearContents
Rows("1:7").Select
Range("A7").Activate
Selection.Delete Shift:=xlUp
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(8, 1), Array(26, 1), Array(42, 1), Array(58, 1), _
Array(74, 1), Array(76, 1), Array(79, 1), Array(88, 1)), TrailingMinusNumbers:=True
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
Columns("A:A").EntireColumn.AutoFit
Columns("B:B").EntireColumn.AutoFit
Columns("C:C").EntireColumn.AutoFit
Columns("D:D").EntireColumn.AutoFit
Columns("E:H").Select
Selection.Delete Shift:=xlToLeft
End Sub 所以我可以在excel中解析,然后导出到cad 有什么想法可以帮上忙吗??
谢谢 如果您对lisp了解很多,我不确定这是否有帮助,它是否有效。
我现在真的没有时间解释,但这是从另一个Lisp程序的Lisp程序中刮下来的、清理过的/剥离过的/清除过的/裸露的最小值。
如果你需要任何帮助来理解它,也许这里的一些人可以帮助你。
未测试的警告可能会导致系统崩溃
(vl-load-com)
;; use c:excel to run
(defun do-Excel ( / )
(setq valuearray (ExcelArray "Name of Tab" (list "A1" "A2" "A3")))
;;enter stuff here
)
(defun C:excel (/)
(setq excelfile "enter file location, name and extention here")
(Kill-Excel)
(if (= (Load-Excel) t)
(progn
(Open-Excel excelfile)
(Save-Excel)
(Kill-Excel)
(gc)
)
(alert "\n Could not Initiate Symbol Library.\n")
)
(princ)
)
))
(defun Load-Excel ( / )
(setq sysdrv (getenv "systemdrive"))
(cond
((setq tlb (findfile (strcat sysdrv "\\Program Files (x86)\\Microsoft Office\\Office\\Excel8.olb"))) tlb)
((setq tlb (findfile (strcat sysdrv "\\Program Files (x86)\\Microsoft Office\\Office\\Excel9.olb"))) tlb)
((setq tlb (findfile (strcat sysdrv "\\Program Files (x86)\\Microsoft Office\\Office\\Excel10.olb"))) tlb)
((setq tlb (findfile (strcat sysdrv "\\Program Files (x86)\\Microsoft Office\\Office\\Excel.exe"))) tlb)
((setq tlb (findfile (strcat sysdrv "\\Program Files (x86)\\Microsoft Office\\Office10\\Excel.exe"))) tlb)
((setq tlb (findfile (strcat sysdrv "\\Program Files (x86)\\Microsoft Office\\Office12\\Excel.exe"))) tlb)
((setq tlb (findfile (strcat sysdrv "\\Program Files (x86)\\Microsoft Office\\Office14\\Excel.exe"))) tlb)
((setq tlb (findfile (strcat sysdrv "\\Program Files\\Microsoft Office\\Office\\Excel8.olb"))) tlb)
((setq tlb (findfile (strcat sysdrv "\\Program Files\\Microsoft Office\\Office\\Excel9.olb"))) tlb)
((setq tlb (findfile (strcat sysdrv "\\Program Files\\Microsoft Office\\Office\\Excel10.olb"))) tlb)
((setq tlb (findfile (strcat sysdrv "\\Program Files\\Microsoft Office\\Office\\Excel.exe"))) tlb)
((setq tlb (findfile (strcat sysdrv "\\Program Files\\Microsoft Office\\Office10\\Excel.exe"))) tlb)
((setq tlb (findfile (strcat sysdrv "\\Program Files\\Microsoft Office\\Office12\\Excel.exe"))) tlb)
((setq tlb (findfile (strcat sysdrv "\\Program Files\\Microsoft Office\\Office14\\Excel.exe"))) tlb)
)
(cond
((null msxl-xl24HourClock)
(if (setq tlbfile tlb)
(progn
(vlax-import-type-library
:tlb-filename tlbfile
:methods-prefix "msxl-"
:properties-prefix "msxl-"
:constants-prefix "msxl-"
)
(if msxl-xl24HourClock
(setq out T)
)
)
)
)
(T (setq out T))
)
out
)
(defun Open-Excel (excelfile/)
(cond ((setq file (findfile excelfile))
(progn(Alert "\nOpening Excel file...") file))
(t
(progn
(alert "\n Excel File Not found.")
)
)
)
(cond
((setq fn (findfile file))
(cond
((setq session (vlax-get-or-create-object "Excel.Application"))
(setq xlworkbook (vlax-invoke-method (vlax-get-property session 'WorkBooks)
'Open
fn
)
)
(setq xlsheets (vlax-get xlworkbook "Sheets"))
(vla-put-visible session 0);; change to 1 and excel will be visible
)
)
)
(T
(alert (strcat "\nCannot locate source file: " file)
)
)
)
(do-excel)
)
;;kills excel
(defun Kill-Excel (/)
(setq session (vlax-get-object "Excel.Application"))
(while (not (not session))
(cond
((not (vlax-object-released-p session))(vlax-invoke-method session 'QUIT)(vlax-release-object session))
)
(setq session nil)
(gc)
(gc)
)
)
;;saves excel
(defun Save-Excel (/)
(vl-catch-all-apply
'vlax-invoke-method
(list xlworkbook "Save")
)
(vl-catch-all-apply
'vlax-invoke-method
(list xlworkbook "Close")
)
)
;;Use matrix to input mass values
;;(lstinput "Tab1" "A1" (list (list 0,3,5,6,19,200,4994,10)(list 0,4,5,6,1,3,4)(list 0,"","",6,1,3,4)))
;;Output starts at A1
;;0 3 5 6 19 200 4994 10
;;0 4 5 613 4
;;0 613 4
(defun lstinput (sheet startcell inputlst)
(setq xlsheet (vlax-get-property xlsheets 'Item sheet))
(vlax-invoke-method xlsheet 'Activate)
(setq startrow 1)
(foreach itm inputlst
(setq startcol 1)
(foreach sec itm
(if (/= sec "")
(msxl-put-formula
(vlax-variant-value
(msxl-get-item (msxl-get-cells (msxl-get-Range xlsheet startcell))
(vlax-make-variant startrow)
(vlax-make-variant startcol)
)
)
sec
)
)
(setq startcol (1+ startcol))
)
(setq startrow (1+ startrow))
)
)
;;Put Value in cell
;;(scinput tab cell value)
(defun scinput (sheet cell input)
(setq xlsheet (vlax-get-property xlsheets 'Item sheet))
(vlax-invoke-method xlsheet 'Activate)
(setq xlcell (msxl-get-Range xlsheet cell))
(msxl-put-Formula xlcell input)
)
;;Moves Tab
;;(move-excel TabToMove TabToMoveBefore)
(defun Move-Excel (sheet before)
(msxl-move (vlax-get-property xlsheets 'Item sheet) (vlax-get-property xlsheets 'Item before))
)
;;Copies tab
;;(copy-excel Tab1 Tab2 Rename)
(defun Copy-Excel (sheet before Newname)
(msxl-copy (vlax-get-property xlsheets 'Item sheet) (vlax-get-property xlsheets 'Item before))
(setq xlCount (vlax-get-property xlSheets 'Count))
(setq xlSheet
(vlax-get-property xlSheets "Item"
(vlax-get-property
(vlax-get-property session 'ActiveSheet)
'Name
)
)
)
(vlax-put-property xlSheet 'Name Newname)
)
;;Hides Rows
;;(Hide-Row Sheet RowsToHide)
(defun Hide-Rows (sheet rows)
(setq xlSheet
(vlax-get-property xlSheets "Item"
(vlax-get-property
(vlax-get-property session 'ActiveSheet)
'Name
)
)
)
(msxl-put-rowheight(msxl-get-Range xlsheet rows) (VLAX-MAKE-VARIANT 0 5))
)
;;Takes Values from Excel and Stores them into an Lisp Array
;;(ExcelArray Tab1 (list "A1" "A2" "A3"))
(defun ExcelArray (sheet array)
(setq xlsheet (vlax-get-property xlsheets 'Item sheet))
(vlax-invoke-method xlsheet 'Activate)
(setq excel-values nil)
(foreach cell array
(setq xlcell (msxl-get-Range xlsheet cell))
(setq value (msxl-get-Formula xlcell input))
(setq excel-values (append excel-values (list values)))
)
excel-values
)
如果在Excel中创建表格,则可以使用它执行以下两种操作之一,以将其放入AutoCAD图形中:
[列表=1]
[*]使用Windows剪贴板复制并粘贴表格。这将引入一个OLE对象,您可以稍后对其进行编辑。
[*]创建从AutoCAD图形到Excel文件中表格的数据链接。也可以从Excel或AutoCAD进行编辑。
[/列表]
听起来你想要的是跳过Excel步骤,只使用LISP来读取和解析文本文件。然后,通过仔细定位从文本文件解析的文本,可以创建一个好看的表。这不是不可能做到的,但我可以看出,要做到这一点需要一些勤奋的毅力。 谢谢CADWarrior,我会看一看并尝试理解代码。
比尔,我制作了一个excel宏来将数据导入excel,thaks寻求帮助 等等,那么信息已经在文本文件中,您要将其放入excel文件?
如果它是一个txt文件,这是我到目前为止仍然需要完成的一些东西
(defun c:txtTab (/)
(setq file (getfiled "Select a Txt file" "" "txt" )
(setq txt (open file "r"))
(setq linetxt nil)
(setq linetxtnew nil)
(while (/= (setq line(read-line txt)) nil)
(setq linetxt (append linetxt (list line)))
)
(foreach line linetxt
(while (wcmatch line "*>*") (setq line (vl-string-subst "" ">" line)))
(while (wcmatch line "*<*") (setq line (vl-string-subst "" "<" line)))
(while (wcmatch line "**") (setq line (vl-string-subst " " "" line)))
(if (not (or (= line "")(= line " ")(wcmatch line "*Active Units Weight*")(wcmatch line "*Steel Take Off*")(wcmatch line "*and Number*")(wcmatch line "*ACTIVE UNITS WEIGHT KG*")))
(setq linetxtnew (append linetxtnew (list line)))
)
)
(setq parts 0)
(setq weights 0)
(setq partlist nil)
(setq weightlist nil)
(foreach line linetxtnew
(if (wcmatch line "*{ *") (setq number (substr line 4 (- (vl-string-search "}" line) 3))))
(if (wcmatch line "TOTAL LENGTH,")(setq parts 0))
(if (= parts 1)
(progn
;;filter parts
)
)
(if (= weights 1)
(progn
;;filter weights
)
)
(if (wcmatch line "*Profile Names Total") (setq parts 1))
(if (wcmatch line "TOTAL LENGTH,")(setq weights 1))
)
(princ (strcat "Item Number is: " Number))
)
NEXTMARCUS这还不是成品。
所需步骤:
1、查找要从中提取数据的文件位置(检查)
;SETOUTBOX.LSP
; program to draw setout details as a co-ord list
; 29/9/04 by alan H
(setvar "menuecho" 0)
(setvar "SNAPMODE" 0)
(SETQ OLDSNAP (GETVAR "OSMODE"))
(setvar "OSMODE" 0)
(defun xyz ()
(setq ans "")
(setq char_found "")
(while (/= char_found ",")
(setq char_found (substr new_line x 1))
(setq x (+ x 1))
(setq ans (strcat ans char_found))
) ;end while
) ;end defun
(setq setsc (/ (getreal "\nEnter Dwg scale 1: ") 1000.0))
(setq stpt (getpoint "\nPick top left point for details "))
(setq xyzfiles (getfiled "\nENTER CO-ORD File name" "" "" 4))
(setq fopen (open xyzfiles "R"))
(command "zoom" "E")
(command "zoom" "c" stpt (* setsc 100.0))
(setq pt1 stpt)
(setq txtht (* 2.5 setsc)); 2.5mm HIGH LETTERING
(setq num 1)
(setq llen (* 84.0 setsc))
(setq ydiff (* 4.5 setsc)); 4.5mm line spacing
(setq stptx (car stpt))
(setq stpty (cadr stpt))
(setq txtpt (list (+ stptx (* 42.0 setsc)) (+ stpty (* 2.0 setsc))))
(command "text" "BC" txtpt txtht "" "xxxxx")
(setq txtpt (list (+ stptx (* 42.0 setsc)) (+ stpty (* 7.0 setsc))))
(command "text" "BC" txtpt txtht "" "%%uSETOUT DETAIL")
(setq pt2 (polar stpt 0.0 llen))
(command "line" stpt pt2 "") ;draw horizontal line
(setq pt1 (polar stpt 4.7124 (* 5.75 setsc)))
(setq txtpt (polar pt1 0.0 (* 9.0 setsc)))
(command "text" "BC" txtpt (* 3.5 setsc) "" "POINT")
(setq txtpt (polar pt1 0.0 (* 34.0 setsc)))
(command "text" "BC" txtpt (* 3.5 setsc) "" "EASTING")
(setq txtpt (polar pt1 0.0 (* 67.0 setsc)))
(command "text" "BC" txtpt (* 3.5 setsc) "" " NORTHING ")
(setq pt1 (polar stpt 4.7124 (* 8.0 setsc)))
(setq pt2 (polar pt1 0.0 llen))
(command "line" pt1 pt2 "") ;draw horizontal line
(setq pt1 (polar pt1 4.7124 (* 1.0 setsc)))
(setq pt2 (polar pt1 0.0 llen))
(command "line" pt1 pt2 "") ;draw horizontal line below above
(setq pt1 (polar pt1 4.7124 (* 1.0 setsc)))
(setq pt2 (polar pt1 0.0 llen))
(command "line" pt1 pt2 "") ;draw horizontal line below above
(setq pt3 pt1) ; sets pt to last line position
;(setq pt5 (polar pt3 1.5708 (* 1.0 setsc))) ; 1 mm above line
(setq pt5 pt3) ; 0.5 mm above line
(SETQ XX 1)
(while (setq new_line (read-line fopen))
(PRINC XX)
(setq x 1)
(setq y 5)
(xyz)
(setq ptno ans) ;pull ptno out
(xyz)
(setq easting ans)
(xyz)
(setq northing ans)
(setq pt3 (polar pt3 4.7124 ydiff))
(setq pt4 (polar pt3 0.0 llen))
(command "line" pt3 pt4 "")
(setq pt5 (polar pt5 4.7124 ydiff))
(setq pt6 (polar pt5 0.0 (* 8.0 setsc)))
(setq pt7 (polar pt5 0.0 (* 28.0 setsc)))
(setq pt8 (polar pt5 0.0 (* 58.0 setsc)))
(command "text" "BL" pt6 txtht "" ptno)
(command "text" "BL" pt7 txtht "" EASTING)
(command "text" "BL" pt8 txtht "" NORTHING)
(SETQ XX (+ XX 1))
) ; end while
(command "line" stpt pt3 "")
(setq pt3 (polar pt3 0.0 (* 18.0 setsc)))
(setq stpt (polar stpt 0.0 (* 18.0 setsc)))
(command "line" stpt pt3 "")
(setq pt3 (polar pt3 0.0 (* 33.0 setsc)))
(setq stpt (polar stpt 0.0 (* 33.0 setsc)))
(command "line" stpt pt3 "")
(setq pt3 (polar pt3 0.0 (* 33.0 setsc)))
(setq stpt (polar stpt 0.0 (* 33.0 setsc)))
(command "line" stpt pt3 "")
(princ setsc )
(setq pt1nil
pt2nil
pt3nil
pt4nil
pt5nil
pt6nil
pt7nil
pt8nil
stpt nil
ansnil
SETSC NIL
)
(SETVAR "OSMODE" OLDSNAP)
(princ)
2、删除无用字符和行(检查)
(setq LINETTXT nil)(setq linetxtnew nil)(while(/=(setq line(read line txt))nil)(setq LINETTXT(append LINETTXT(list line)))(foreach LINETTXT(while(wcmatch line“*>*”)(setq line(vl string subst”“”>“line)))(while(wcmatch line“*
页:
[1]
2