乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 19|回复: 19

[编程交流] 帮助,导入。txt表格t

[复制链接]

4

主题

27

帖子

23

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-6 06:54:53 | 显示全部楼层 |阅读模式
大家好!
我试图找到一个lisp来导入表。txt文件到autocad,但我不知道从哪里开始这项任务。我有一个想法是:
将表格复制到excel,然后粘贴到autocad中。
问题是我有很多表要导入,如果我这样做,将需要很长时间。
 
遵循表格模型:
 
 
 
 
SoI需要填写字段total weight和profile Name
遵循具有所需结果的文件。
我还需要把总重量加上10%
有什么想法可以帮我完成这项任务吗?
 
 
对不起我的英语。
实例图纸
桌子txt文件
回复

使用道具 举报

180

主题

639

帖子

463

银币

中流砥柱

Rank: 25

铜币
897
发表于 2022-7-6 06:58:33 | 显示全部楼层
真 的!这将涉及很多编程,但像大多数使用LISP的事情一样,这是完全可能的。我不确定你的第一个想法在你准备好一个相当广泛的LISP程序之前是否会变得简单和快速。
 
有几个问题,我假设你的文本文件总是以相同的格式?有什么理由把长度写成科学记数法而不是另一种格式吗?有人可能可以帮你解决这个问题,但需要一些真正的编码才能正确解析文件,然后将文本放置在图形中所需的位置。如果是我,我会坚持从Excel中剪切和粘贴。但那只是我。
回复

使用道具 举报

4

主题

27

帖子

23

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-6 07:01:57 | 显示全部楼层
嗨,比尔,是的,文件的格式总是一样的,这个文件是另一个程序的输出,我可以选择数值符号。
 
我制作了一个excel宏来解析数据,现在我试图找到一种方法,在excel中制作表格,然后导入到cad。这容易做吗?
以下是我在vb中的代码:
 
  1. Sub teste2()
  2. '
  3. ' test2 Macro
  4. ' Adjust table
  5. '
  6. '
  7.    Columns("A:A").EntireColumn.AutoFit
  8.    Rows("1:7").Select
  9.    Range("A7").Activate
  10.    Selection.ClearContents
  11.    Rows("1:7").Select
  12.    Range("A7").Activate
  13.    Selection.Delete Shift:=xlUp
  14.    Columns("A:A").Select
  15.    Selection.TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
  16.        FieldInfo:=Array(Array(0, 1), Array(8, 1), Array(26, 1), Array(42, 1), Array(58, 1), _
  17.        Array(74, 1), Array(76, 1), Array(79, 1), Array(88, 1)), TrailingMinusNumbers:=True
  18.    Columns("A:A").Select
  19.    Selection.Delete Shift:=xlToLeft
  20.    Columns("A:A").EntireColumn.AutoFit
  21.    Columns("B:B").EntireColumn.AutoFit
  22.    Columns("C:C").EntireColumn.AutoFit
  23.    Columns("D:D").EntireColumn.AutoFit
  24.    Columns("E:H").Select
  25.    Selection.Delete Shift:=xlToLeft
  26. End Sub
回复

使用道具 举报

4

主题

27

帖子

23

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-6 07:07:12 | 显示全部楼层
所以我可以在excel中解析,然后导出到cad
回复

使用道具 举报

4

主题

27

帖子

23

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-6 07:09:06 | 显示全部楼层
有什么想法可以帮上忙吗??
 
 
谢谢
回复

使用道具 举报

13

主题

48

帖子

35

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-6 07:12:18 | 显示全部楼层
如果您对lisp了解很多,我不确定这是否有帮助,它是否有效。
 
我现在真的没有时间解释,但这是从另一个Lisp程序的Lisp程序中刮下来的、清理过的/剥离过的/清除过的/裸露的最小值。
 
如果你需要任何帮助来理解它,也许这里的一些人可以帮助你。
 
未测试的警告可能会导致系统崩溃
  1. (vl-load-com)
  2. ;; use c:excel to run
  3. (defun do-Excel ( / )
  4. (setq valuearray (ExcelArray "Name of Tab" (list "A1" "A2" "A3")))
  5. ;;enter stuff here
  6. )
  7. (defun C:excel (/)
  8. (setq excelfile "enter file location, name and extention here")
  9. (Kill-Excel)
  10. (if (= (Load-Excel) t)
  11.    (progn
  12.      (Open-Excel excelfile)
  13.      (Save-Excel)
  14.      (Kill-Excel)
  15.      (gc)
  16.      )
  17.    (alert "\n Could not Initiate Symbol Library.\n")
  18.    )
  19. (princ)
  20. )
  21.    ))
  22. (defun Load-Excel ( / )
  23. (setq sysdrv (getenv "systemdrive"))
  24. (cond
  25.    ((setq tlb (findfile (strcat sysdrv "\\Program Files (x86)\\Microsoft Office\\Office\\Excel8.olb"))) tlb)
  26.    ((setq tlb (findfile (strcat sysdrv "\\Program Files (x86)\\Microsoft Office\\Office\\Excel9.olb"))) tlb)
  27.    ((setq tlb (findfile (strcat sysdrv "\\Program Files (x86)\\Microsoft Office\\Office\\Excel10.olb"))) tlb)
  28.    ((setq tlb (findfile (strcat sysdrv "\\Program Files (x86)\\Microsoft Office\\Office\\Excel.exe"))) tlb)
  29.    ((setq tlb (findfile (strcat sysdrv "\\Program Files (x86)\\Microsoft Office\\Office10\\Excel.exe"))) tlb)
  30.    ((setq tlb (findfile (strcat sysdrv "\\Program Files (x86)\\Microsoft Office\\Office12\\Excel.exe"))) tlb)
  31.    ((setq tlb (findfile (strcat sysdrv "\\Program Files (x86)\\Microsoft Office\\Office14\\Excel.exe"))) tlb)
  32.    ((setq tlb (findfile (strcat sysdrv "\\Program Files\\Microsoft Office\\Office\\Excel8.olb"))) tlb)
  33.    ((setq tlb (findfile (strcat sysdrv "\\Program Files\\Microsoft Office\\Office\\Excel9.olb"))) tlb)
  34.    ((setq tlb (findfile (strcat sysdrv "\\Program Files\\Microsoft Office\\Office\\Excel10.olb"))) tlb)
  35.    ((setq tlb (findfile (strcat sysdrv "\\Program Files\\Microsoft Office\\Office\\Excel.exe"))) tlb)
  36.    ((setq tlb (findfile (strcat sysdrv "\\Program Files\\Microsoft Office\\Office10\\Excel.exe"))) tlb)
  37.    ((setq tlb (findfile (strcat sysdrv "\\Program Files\\Microsoft Office\\Office12\\Excel.exe"))) tlb)
  38.    ((setq tlb (findfile (strcat sysdrv "\\Program Files\\Microsoft Office\\Office14\\Excel.exe"))) tlb)
  39.    )
  40. (cond
  41.    ((null msxl-xl24HourClock)
  42.     (if (setq tlbfile tlb)
  43.       (progn
  44. (vlax-import-type-library
  45.    :tlb-filename        tlbfile
  46.    :methods-prefix    "msxl-"
  47.    :properties-prefix "msxl-"
  48.    :constants-prefix        "msxl-"
  49.    )
  50. (if msxl-xl24HourClock
  51.    (setq out T)
  52.    )
  53. )
  54.       )
  55.     )
  56.    (T (setq out T))
  57.    )
  58. out
  59. )
  60. (defun Open-Excel (excelfile/)
  61. (cond ((setq file (findfile excelfile))
  62. (progn(Alert "\nOpening Excel file...") file))
  63. (t
  64. (progn
  65.    (alert "\n Excel File Not found.")
  66.      )
  67.    )
  68.   )
  69.    (cond
  70.      ((setq fn (findfile file))
  71.       (cond
  72. ((setq session (vlax-get-or-create-object "Excel.Application"))
  73.   (setq xlworkbook (vlax-invoke-method (vlax-get-property session 'WorkBooks)
  74.                      'Open
  75.                      fn
  76.                      )
  77.         )
  78.   (setq xlsheets (vlax-get xlworkbook "Sheets"))
  79.   (vla-put-visible session 0);; change to 1 and excel will be visible
  80.   )
  81. )
  82.       )
  83.      (T
  84.       (alert (strcat "\nCannot locate source file: " file)
  85.       )
  86.       )
  87.      )
  88. (do-excel)
  89. )
  90. ;;kills excel
  91. (defun Kill-Excel (/)
  92.    (setq session (vlax-get-object "Excel.Application"))
  93.    (while (not (not session))
  94.      (cond
  95. ((not (vlax-object-released-p session))(vlax-invoke-method session 'QUIT)(vlax-release-object session))
  96. )
  97.      (setq session nil)
  98.      (gc)
  99.      (gc)
  100.      )
  101.    )
  102. ;;saves excel
  103. (defun Save-Excel (/)
  104. (vl-catch-all-apply
  105.    'vlax-invoke-method
  106.    (list xlworkbook "Save")
  107.    )
  108. (vl-catch-all-apply
  109.    'vlax-invoke-method
  110.    (list xlworkbook "Close")
  111.    )
  112. )
  113. ;;Use matrix to input mass values
  114. ;;(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)))
  115. ;;Output starts at A1
  116. ;;0 3 5 6 19 200 4994 10
  117. ;;0 4 5 6  1  3   4     
  118. ;;0     6  1  3   4     
  119. (defun lstinput (sheet startcell inputlst)
  120. (setq xlsheet (vlax-get-property xlsheets 'Item sheet))
  121. (vlax-invoke-method xlsheet 'Activate)
  122. (setq startrow 1)
  123. (foreach itm inputlst
  124.    (setq startcol 1)
  125.    (foreach sec itm
  126.      (if (/= sec "")
  127. (msxl-put-formula
  128.   (vlax-variant-value
  129.     (msxl-get-item (msxl-get-cells (msxl-get-Range xlsheet startcell))
  130.       (vlax-make-variant startrow)
  131.       (vlax-make-variant startcol)
  132.       )
  133.     )
  134.   sec
  135.   )
  136. )
  137.      (setq startcol (1+ startcol))
  138.      )
  139.    (setq startrow (1+ startrow))
  140.    )
  141. )
  142. ;;Put Value in cell
  143. ;;(scinput tab cell value)
  144. (defun scinput (sheet cell input)
  145. (setq xlsheet (vlax-get-property xlsheets 'Item sheet))
  146. (vlax-invoke-method xlsheet 'Activate)
  147. (setq xlcell (msxl-get-Range xlsheet cell))
  148. (msxl-put-Formula xlcell input)
  149. )
  150. ;;Moves Tab
  151. ;;(move-excel TabToMove TabToMoveBefore)
  152. (defun Move-Excel (sheet before)
  153. (msxl-move (vlax-get-property xlsheets 'Item sheet) (vlax-get-property xlsheets 'Item before))
  154. )
  155. ;;Copies tab
  156. ;;(copy-excel Tab1 Tab2 Rename)
  157. (defun Copy-Excel (sheet before Newname)
  158. (msxl-copy (vlax-get-property xlsheets 'Item sheet) (vlax-get-property xlsheets 'Item before))
  159. (setq xlCount (vlax-get-property xlSheets 'Count))
  160. (setq xlSheet
  161. (vlax-get-property xlSheets "Item"
  162.    (vlax-get-property
  163.      (vlax-get-property session 'ActiveSheet)
  164.      'Name
  165.      )
  166.    )
  167. )
  168. (vlax-put-property xlSheet 'Name Newname)
  169. )
  170. ;;Hides Rows
  171. ;;(Hide-Row Sheet RowsToHide)
  172. (defun Hide-Rows (sheet rows)
  173. (setq xlSheet
  174. (vlax-get-property xlSheets "Item"
  175.    (vlax-get-property
  176.      (vlax-get-property session 'ActiveSheet)
  177.      'Name
  178.      )
  179.    )
  180. )
  181. (msxl-put-rowheight(msxl-get-Range xlsheet rows) (VLAX-MAKE-VARIANT 0 5))
  182. )
  183. ;;Takes Values from Excel and Stores them into an Lisp Array
  184. ;;(ExcelArray Tab1 (list "A1" "A2" "A3"))
  185. (defun ExcelArray (sheet array)
  186. (setq xlsheet (vlax-get-property xlsheets 'Item sheet))
  187. (vlax-invoke-method xlsheet 'Activate)
  188. (setq excel-values nil)
  189. (foreach cell array
  190.    (setq xlcell (msxl-get-Range xlsheet cell))
  191.    (setq value (msxl-get-Formula xlcell input))
  192.    (setq excel-values (append excel-values (list values)))
  193.    )
  194. excel-values
  195. )
回复

使用道具 举报

180

主题

639

帖子

463

银币

中流砥柱

Rank: 25

铜币
897
发表于 2022-7-6 07:14:08 | 显示全部楼层
 
如果在Excel中创建表格,则可以使用它执行以下两种操作之一,以将其放入AutoCAD图形中:
 
[列表=1]
  • 使用Windows剪贴板复制并粘贴表格。这将引入一个OLE对象,您可以稍后对其进行编辑。
  • 创建从AutoCAD图形到Excel文件中表格的数据链接。也可以从Excel或AutoCAD进行编辑。
    [/列表]
    听起来你想要的是跳过Excel步骤,只使用LISP来读取和解析文本文件。然后,通过仔细定位从文本文件解析的文本,可以创建一个好看的表。这不是不可能做到的,但我可以看出,要做到这一点需要一些勤奋的毅力。
  • 回复

    使用道具 举报

    4

    主题

    27

    帖子

    23

    银币

    初来乍到

    Rank: 1

    铜币
    20
    发表于 2022-7-6 07:19:59 | 显示全部楼层
    谢谢CADWarrior,我会看一看并尝试理解代码。
    比尔,我制作了一个excel宏来将数据导入excel,thaks寻求帮助
    回复

    使用道具 举报

    13

    主题

    48

    帖子

    35

    银币

    初露锋芒

    Rank: 3Rank: 3Rank: 3

    铜币
    65
    发表于 2022-7-6 07:22:42 | 显示全部楼层
    等等,那么信息已经在文本文件中,您要将其放入excel文件?
     
    如果它是一个txt文件,这是我到目前为止仍然需要完成的一些东西
     
    1. (defun c:txtTab (/)
    2. (setq file (getfiled "Select a Txt file" "" "txt" )
    3. (setq txt (open file "r"))
    4. (setq linetxt nil)
    5. (setq linetxtnew nil)
    6. (while (/= (setq line(read-line txt)) nil)
    7.    (setq linetxt (append linetxt (list line)))
    8.    )
    9. (foreach line linetxt
    10.    (while (wcmatch line "*>*") (setq line (vl-string-subst "" ">" line)))
    11.    (while (wcmatch line "*<*") (setq line (vl-string-subst "" "<" line)))
    12.    (while (wcmatch line "*  *") (setq line (vl-string-subst " " "  " line)))
    13.    (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*")))
    14.      (setq linetxtnew (append linetxtnew (list line)))
    15.      )
    16.    )
    17. (setq parts 0)
    18. (setq weights 0)
    19. (setq partlist nil)
    20. (setq weightlist nil)
    21. (foreach line linetxtnew
    22.    (if (wcmatch line "*{ *") (setq number (substr line 4 (- (vl-string-search "}" line) 3))))
    23.    (if (wcmatch line "TOTAL LENGTH,")(setq parts 0))
    24.    (if (= parts 1)
    25.      (progn
    26. ;;filter parts
    27. )
    28.      )
    29.    (if (= weights 1)
    30.      (progn
    31. ;;filter weights
    32. )
    33.      )
    34.    (if (wcmatch line "*Profile Names Total") (setq parts 1))
    35.    (if (wcmatch line "TOTAL LENGTH,")(setq weights 1))
    36.    )
    37. (princ (strcat "Item Number is: " Number))
    38. )
    回复

    使用道具 举报

    4

    主题

    27

    帖子

    23

    银币

    初来乍到

    Rank: 1

    铜币
    20
    发表于 2022-7-6 07:25:15 | 显示全部楼层
     
    NEXTMARCUS这还不是成品。
    所需步骤:
    1、查找要从中提取数据的文件位置(检查)
    1.                     ;SETOUTBOX.LSP
    2.                    ; program to draw setout details as a co-ord list
    3.                    ; 29/9/04 by alan H
    4. (setvar "menuecho" 0)
    5. (setvar "SNAPMODE" 0)
    6. (SETQ OLDSNAP (GETVAR "OSMODE"))
    7. (setvar "OSMODE" 0)
    8. (defun xyz ()
    9. (setq ans "")
    10. (setq char_found "")
    11. (while (/= char_found ",")
    12.    (setq char_found (substr new_line x 1))
    13.    (setq x (+ x 1))
    14.    (setq ans (strcat ans char_found))
    15. )                    ;end while
    16. )                    ;end defun
    17. (setq setsc (/ (getreal "\nEnter Dwg scale 1: ") 1000.0))
    18. (setq stpt (getpoint "\nPick top left point for details "))
    19. (setq xyzfiles (getfiled "\nENTER CO-ORD File name  " "" "" 4))
    20. (setq fopen (open xyzfiles "R"))
    21. (command "zoom" "E")
    22. (command "zoom" "c" stpt (* setsc 100.0))
    23. (setq pt1 stpt)
    24. (setq txtht (* 2.5 setsc))  ; 2.5mm HIGH LETTERING
    25. (setq num 1)
    26. (setq llen (* 84.0 setsc))
    27. (setq ydiff (* 4.5 setsc))  ; 4.5mm line spacing
    28. (setq stptx (car stpt))
    29. (setq stpty (cadr stpt))
    30. (setq txtpt (list (+ stptx (* 42.0 setsc)) (+ stpty (* 2.0 setsc))))
    31. (command "text" "BC" txtpt txtht "" "xxxxx")
    32. (setq txtpt (list (+ stptx (* 42.0 setsc)) (+ stpty (* 7.0 setsc))))
    33. (command "text" "BC" txtpt txtht "" "%%uSETOUT DETAIL")
    34. (setq pt2 (polar stpt 0.0 llen))
    35. (command "line" stpt pt2 "")        ;draw horizontal line
    36. (setq pt1 (polar stpt 4.7124 (* 5.75 setsc)))
    37. (setq txtpt (polar pt1 0.0 (* 9.0 setsc)))
    38. (command "text" "BC" txtpt (* 3.5 setsc) "" "POINT")
    39. (setq txtpt (polar pt1 0.0 (* 34.0 setsc)))
    40. (command "text" "BC" txtpt (* 3.5 setsc) "" "EASTING")
    41. (setq txtpt (polar pt1 0.0 (* 67.0 setsc)))
    42. (command "text" "BC" txtpt (* 3.5 setsc) "" " NORTHING ")
    43. (setq pt1 (polar stpt 4.7124 (* 8.0 setsc)))
    44. (setq pt2 (polar pt1 0.0 llen))
    45. (command "line" pt1 pt2 "")        ;draw horizontal line
    46. (setq pt1 (polar pt1 4.7124 (* 1.0 setsc)))
    47. (setq pt2 (polar pt1 0.0 llen))
    48. (command "line" pt1 pt2 "")        ;draw horizontal line below above
    49. (setq pt1 (polar pt1 4.7124 (* 1.0 setsc)))
    50. (setq pt2 (polar pt1 0.0 llen))
    51. (command "line" pt1 pt2 "")        ;draw horizontal line below above
    52. (setq pt3 pt1)                ; sets pt to last line position
    53. ;(setq pt5 (polar pt3 1.5708 (* 1.0 setsc)))      ; 1 mm above line
    54. (setq pt5 pt3)                ; 0.5 mm above line
    55. (SETQ XX 1)
    56. (while (setq new_line (read-line fopen))
    57. (PRINC XX)
    58. (setq x 1)
    59. (setq y 5)
    60. (xyz)
    61. (setq ptno ans)            ;pull ptno out
    62. (xyz)
    63. (setq easting ans)
    64. (xyz)
    65. (setq northing ans)
    66. (setq pt3 (polar pt3 4.7124 ydiff))
    67. (setq pt4 (polar pt3 0.0 llen))
    68. (command "line" pt3 pt4 "")
    69. (setq pt5 (polar pt5 4.7124 ydiff))
    70. (setq pt6 (polar pt5 0.0 (* 8.0 setsc)))
    71. (setq pt7 (polar pt5 0.0 (* 28.0 setsc)))
    72. (setq pt8 (polar pt5 0.0 (* 58.0 setsc)))
    73. (command "text" "BL" pt6 txtht "" ptno)
    74. (command "text" "BL" pt7 txtht "" EASTING)
    75. (command "text" "BL" pt8 txtht "" NORTHING)
    76. (SETQ XX (+ XX 1))
    77. )                    ; end while
    78. (command "line" stpt pt3 "")
    79. (setq pt3 (polar pt3 0.0 (* 18.0 setsc)))
    80. (setq stpt (polar stpt 0.0 (* 18.0 setsc)))
    81. (command "line" stpt pt3 "")
    82. (setq pt3 (polar pt3 0.0 (* 33.0 setsc)))
    83. (setq stpt (polar stpt 0.0 (* 33.0 setsc)))
    84. (command "line" stpt pt3 "")
    85. (setq pt3 (polar pt3 0.0 (* 33.0 setsc)))
    86. (setq stpt (polar stpt 0.0 (* 33.0 setsc)))
    87. (command "line" stpt pt3 "")
    88. (princ setsc )
    89. (setq pt1  nil
    90.      pt2  nil
    91.      pt3  nil
    92.      pt4  nil
    93.      pt5  nil
    94.      pt6  nil
    95.      pt7  nil
    96.      pt8  nil
    97.      stpt nil
    98.      ans  nil
    99.      SETSC NIL
    100. )
    101. (SETVAR "OSMODE" OLDSNAP)
    102. (princ)

     
    2、删除无用字符和行(检查)
    [code](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“*
    回复

    使用道具 举报

    发表回复

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    • 微信公众平台

    • 扫描访问手机版

    • 点击图片下载手机App

    QQ|关于我们|小黑屋|乐筑天下 繁体中文

    GMT+8, 2025-3-10 11:14 , Processed in 0.385339 second(s), 72 queries .

    © 2020-2025 乐筑天下

    联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表