乐筑天下

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

[编程交流] ؟؟-我需要导出尺寸t

[复制链接]

2

主题

8

帖子

6

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-5 15:28:59 | 显示全部楼层 |阅读模式
您好,我想帮助做lisp,它将维度以我选择对象的相同顺序导出到excel表。。
希望大家都好,祝大家好运
回复

使用道具 举报

rlx

21

主题

1505

帖子

1551

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
81
发表于 2022-7-5 15:32:58 | 显示全部楼层
欢迎访问本网站mahramou。
 
 
我还没有为它编写代码,但我认为这个链接有你想要的:
 
 
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/help-me-a-autolisp-export-dimensions-to-excel/td-p/4662311
 
 
gr.Rlx
回复

使用道具 举报

2

主题

8

帖子

6

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-5 15:36:33 | 显示全部楼层
但我不能用它
它对我不起作用
回复

使用道具 举报

rlx

21

主题

1505

帖子

1551

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
81
发表于 2022-7-5 15:41:48 | 显示全部楼层
 
 
我还没有真正研究过代码,也没有经常使用维度,所以如果其他人有什么东西在货架上。。。否则,贴一个样本,也许我可以看一看(也就是说,如果妻子还没有发现为我计划的其他肮脏任务,新地板、绘画、新卧室、新厨房……它会停止吗,恐怖……)
 
 
gr.Rlx
回复

使用道具 举报

2

主题

8

帖子

6

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-5 15:45:17 | 显示全部楼层
rlx我需要这样

                               
登录/注册后可看大图

 
谢谢你抽出时间
回复

使用道具 举报

2

主题

8

帖子

6

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-5 15:48:04 | 显示全部楼层
我希望能帮我做到这一点

                               
登录/注册后可看大图

thnnx到所有
回复

使用道具 举报

2

主题

8

帖子

6

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-5 15:51:37 | 显示全部楼层
希望有人能帮我这样做
 

                               
登录/注册后可看大图

 
162921rfffqhk7agbekgbf.jpg
回复

使用道具 举报

rlx

21

主题

1505

帖子

1551

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
81
发表于 2022-7-5 15:56:01 | 显示全部楼层
我做了很少的测试(几分钟内必须离开),但试试这个:
 
 
  1. ; Dimensions to CSV - written for CadTutor by RLX on 5 th of july 2017
  2. (defun c:RlxDimensionsToCSV
  3.       ( / p1 p2 txt-selection dim-selection fuzz hit-list row row-list e dim dim-y dim-tst csv-name)
  4. (vl-load-com)
  5. (cond
  6.    ((null (setq p1 (getpoint "\nSelect first corner for markers & dimensions : ")))
  7.     (princ "\nSelection process cancelled"))
  8.    ((null (setq p2 (getcorner p1 "\nOther corner : ")))
  9.     (princ "\nInvalid selection or selection process cancelled"))
  10.    ((null (setq txt-selection (ssget "c" p1 p2 '((0 . "TEXT")))))
  11.     (princ "\nNo text markers were found - ending function"))
  12.    ((null (setq dim-selection (ssget "c" p1 p2 '((0 . "DIMENSION")))))
  13.     (princ "\nNo dimensions were found - ending function"))
  14.    ((null (setq fuzz (getdist "\nEnter or specify tolerance between text marker and dimension insertionpoint : ")))
  15.     (princ "\nYou have to give a distance in order for this routine to sort all dimensions to rows"))
  16.    (t
  17.     ; first sort txt-selection which will function as row name
  18.     (setq txt-selection (sssort txt-selection) dim-selection (sssort dim-selection) row-list '())
  19.     ; Now built list for each (text) marker, for example (("marker1" 176.25) ("marker2" 158.75) ...)
  20.     ; each sublist is text string from marker and its y coordinate
  21.     (setq hit-list (mapcar '(lambda (x / e) (list (cdr (assoc 1 (setq e (entget x)))) (caddr (assoc 10 e)))) txt-selection))
  22.     ;now to put each dimension in the right row
  23.     (foreach dim dim-selection
  24.       (setq dim-y (caddr (assoc 13 (setq dim (entget dim)))) dim-txt (cdr (assoc 1 dim)))
  25.       (if (= dim-txt "")(setq dim-txt (rtos (cdr (assoc 42 dim)) 2 2)))
  26.       (mapcar '(lambda (x)
  27.    (if (equal dim-y (cadr x) fuzz)
  28.      (if (setq row (assoc (car x) row-list))
  29.        (setq row-list (subst (reverse (cons dim-txt (reverse row))) row row-list))
  30.        (setq row-list (cons (append x (list dim-txt)) row-list)))))
  31.        hit-list
  32.       )
  33.     )
  34.    )
  35. )
  36. (if (vl-consp row-list) (write_to_csv (reverse row-list))(princ "\nNothing to write"))
  37. (if (and csv-name (and (findfile csv-name)))(RlxDimensionsToCSV_OpenCSV))
  38. (princ)
  39. )
  40. ;el = elist , xl = x , yl = y , ml = matrix , sl = sorted elist
  41. (defun sssort ( ss / e el i xl yl ml sl)
  42. (if (and ss (> (sslength ss) 1)(setq i 0))
  43.    (progn
  44.      ;ss -> elist ( ((ip)e1) ((ip)e2) .. )
  45.      (while (setq e (ssname ss i))
  46. (setq el (append el (list (list (getip e) e))) i (1+ i)))
  47.      (setq xl (vl-sort (rdup (mapcar 'caar el)) '<)
  48.     yl (vl-sort (rdup (mapcar 'cadar el)) '>))  
  49.      (foreach y yl (foreach x xl (setq ml (append ml (list (list x y))))))
  50.      (setq sl (vl-remove 'nil (mapcar '(lambda (x) (if (assoc x el)(cadr (assoc x el)))) ml))))))
  51. (defun rdup ( i / o );remove duplicates
  52. (vl-remove-if '(lambda (x) (cond ((vl-position x o) t) ((setq o (cons x o)) nil))) i))
  53. (defun getip (e);get insertionpoint
  54. (list (cadr (assoc 10 (entget e)))(caddr (assoc 10 (entget e)))))
  55. ;LOG (("marker3" 126.25 "38.75" "92.5" "97.5") ("marker2" 158.75 "32.5" "13.75" "101.25") ("marker1" 176.25 "31.25" "130" "40mm"))
  56. ;[0] ("marker3" 126.25 "38.75" "92.5" "97.5")
  57. ;[1] ("marker2" 158.75 "32.5" "13.75" "101.25")
  58. ;[2] ("marker1" 176.25 "31.25" "130" "40mm")
  59. (defun write_to_csv ( %lst / pref dname csv-fp row )
  60. (setq pref (getvar "dwgprefix") dname (vl-filename-base (getvar "dwgname")) csv-name (strcat pref dname ".csv"))
  61. (if (setq csv-fp (open csv-name "w"))
  62.    (progn
  63.      (foreach row %lst
  64. (write-line (strcat (car row) "," (cadddr row)) csv-fp)
  65. (mapcar '(lambda (x)(write-line (strcat "," x) csv-fp)) (cdddr row)))
  66.      (close csv-fp)(gc)
  67.    )
  68. )
  69. )
  70. (defun RlxDimensionsToCSV_OpenCSV ()
  71. (princ "\nPress space to open csv report , any other key to exit")
  72. (if (equal (grread) '(2 32)) (or (shell_open (findfile csv-name))(command "notepad" (findfile csv-name)))))
  73. (defun shell_open ( target / shell result )
  74. (if (and (setq target (findfile target))
  75.    (setq shell (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application")))
  76.    (progn
  77.      (setq result (vl-catch-all-apply 'vlax-invoke (list shell 'open target)))
  78.      (vlax-release-object shell)(not (vl-catch-all-error-p result)))))
  79. (c:RlxDimensionsToCSV)

只需一次性选择文字和尺寸标注,并为行名称的插入点(路径1、路径3等)和尺寸标注的y坐标(节点)之间的距离(y)提供公差。它们大致应该在同一高度。
 
 
是的,我知道排序代码不是很好,但现在必须这样做。
 
 
我得走了。
 
 
gr.Rlx
回复

使用道具 举报

2

主题

8

帖子

6

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-5 15:59:23 | 显示全部楼层
thnnx rlx,,但lisp更复杂,我无法使用它。。重复尺寸(我可能不知道如何调整公差)
回复

使用道具 举报

rlx

21

主题

1505

帖子

1551

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
81
发表于 2022-7-5 16:02:58 | 显示全部楼层
 
好的,可能是不同的方法,没有自动但手动选择
 
  1. ; Dimensions to CSV - written for CadTutor by RLX on 7 th of july 2017
  2. ; Purpose is to create csv file with format :
  3. ; --------------------
  4. ; |    A   |    B    |
  5. ; --------------------
  6. ; |  Dim1  |   100   |
  7. ; --------------------
  8. ; |        |   110   |
  9. ; --------------------
  10. ; |  Dim2  |  97.5   |
  11. ; --------------------
  12. ; |        |  23.9   |
  13. ; --------------------
  14. ;
  15. ; Program will loop until the user presses space, enter, R-mouse or escape [sERmoE]
  16. ; step 1 : select (text) description for placement in column A
  17. ; step 2 : program will directly switch to dimension selection mode and will do so util [sERmoE]
  18. ; step 3 : after step 2 program will go back to step 1 (text selection mode) again until [sERmoE]
  19. ; step 4 : data will be processed and saved to same name as dwg but with extension csv
  20. ; step 5 : if user presses space the created csv file will be opened with associated program (if any)
  21. ; since program uses grread to directly read keyboard and mouse input I've programmed also a few keys for zooming
  22. ; + and - , z(oom) and e(xtents) , keys are case insensitive.
  23. ; Program directly reads cursor position and when no entity is found under selected point it switches to window
  24. ; mode (crossing actually).
  25. ; Since opp on CadTutor expressed the wish to be able to select each dimension individually, when program switches
  26. ; to window mode , still only one entity will get selected , just so you know you know...
  27. ; If dimension has text override , this will be the value saved to csv file
  28. (defun c:RlxDimensionToCSV ( / dim-title dim dim-sel csv-list csv-name)
  29. (vl-load-com)
  30. (princ "\nSelect dimension title (text) : ")
  31. (setq dim-title (RlxSel1 "TEXT"))
  32. (while dim-title
  33.    (setq dim-title (cdr (assoc 1 (entget dim-title))))
  34.    (if (assoc dim-title csv-list)
  35.      (alert "Dimension title allready in list")
  36.      (progn
  37. (setq dim-sel '())
  38. (princ "\nSelect dimensions : ")
  39. (while (setq dim (RlxSel1 "DIMENSION"))
  40.   (if (not (member dim dim-sel))
  41.     (setq dim-sel (reverse (cons dim (reverse dim-sel))))))
  42. (if (and dim-title dim-sel)
  43.   (setq csv-list (reverse (cons (list dim-title dim-sel) (reverse csv-list)))))
  44.      ); end progn
  45.    ); end if
  46.    (princ "\nSelect next dimension title or enter to write selection to csv file : ")
  47.    (setq dim-title (RlxSel1 "TEXT"))
  48. ); end while
  49. ; refresh drawing
  50. (vla-regen (vla-get-ActiveDocument (vlax-get-acad-object)) acActiveViewport)
  51. ;selection process is complete , now process & save data
  52. (if (not (vl-consp csv-list))
  53.    (alert "No data to process - ending program")
  54.    (progn
  55.      (setq csv-list (_convert csv-list))
  56.      (if (vl-consp csv-list) (write_to_csv csv-list)(alert "Nothing to write"))
  57.      (if (and csv-name (and (findfile csv-name)))(RlxDimensionsToCSV_OpenCSV))
  58.    )
  59. )
  60. (princ)
  61. )
  62. (defun write_to_csv ( %lst / pref dname csv-fp row )
  63. (setq pref (getvar "dwgprefix") dname (vl-filename-base (getvar "dwgname")) csv-name (strcat pref dname ".csv"))
  64. (if (setq csv-fp (open csv-name "w"))
  65.    (progn
  66.      (foreach row %lst
  67. (write-line (strcat (car row) "," (cadr row)) csv-fp)
  68. (mapcar '(lambda (x)(write-line (strcat "," x) csv-fp)) (cddr row)))
  69.      (close csv-fp)(gc)
  70.    )
  71. )
  72. )
  73. (defun RlxDimensionsToCSV_OpenCSV ()
  74. (princ "\nPress space to open csv report , any other key to exit")
  75. (if (equal (grread) '(2 32)) (or (shell_open (findfile csv-name))(command "notepad" (findfile csv-name)))))
  76. (defun shell_open ( target / shell result )
  77. (if (and (setq target (findfile target))
  78.    (setq shell (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application")))
  79.    (progn
  80.      (setq result (vl-catch-all-apply 'vlax-invoke (list shell 'open target)))
  81.      (vlax-release-object shell)(not (vl-catch-all-error-p result)))))
  82. (defun get_type ( %o )
  83. (cond
  84.    ((= (type %o) 'ENAME)(cdr (assoc 0 (entget %o))))
  85.    ((= (type %o) 'VLA-object)(cdr (assoc 0 (entget (vlax-vla-object->ename  %o)))))
  86.    (t nil)
  87. )
  88. )
  89. (defun RlxSel1 ( $e-type / done-selecting inp i p2 result e ent)
  90. (princ (strcat "\nEsc, enter, Rmouse to cancel, zoom with E(extend), Z(oom) or + / -\nSelect " $e-type))
  91. (setq done-selecting nil)
  92. (while (not done-selecting)
  93.    (setq inp (vl-catch-all-apply 'grread (list nil 4 2)))
  94.    (if (vl-catch-all-error-p inp)
  95.      (setq done-selecting t result nil)
  96.      (cond
  97. ; if point selected
  98. ((= (car inp) 3)
  99. ; if point has object under it
  100. (if (setq ent (nentselp (cadr inp))) (setq e (car ent) typ (get_type e)))
  101. (cond
  102.    ; if we have object and object is the right type we have a winner
  103.    ((and e typ (eq $e-type typ))
  104.     (redraw e 3)(setq done-selecting t result e))
  105.    ; maybe its the parent
  106.    ; this happens when type is dimension and you select dimensions text
  107.    ((and (caddr ent) (setq ent (last (last ent)))(eq $e-type (get_type ent)))
  108.     (redraw ent 3)(setq done-selecting t result ent))
  109.    ; sorry object is not the right stuf
  110.    ((and e typ (not (eq $e-type typ)))
  111.     (princ (strcat "\nYou selected the wrong type (" $e-type ")")))
  112.    ; else try crossing selection
  113.    (t
  114.     (if (and (setq i 0 p2 (getcorner (cadr inp) "\tOther corner : "))
  115.       (setq ss (ssget "c" (cadr inp) p2)))
  116.       (while (setq e (ssname ss i))
  117. (if (= (cdr (assoc 0 (entget e))) $e-type)
  118.    (progn (redraw e 3) (setq result e done-selecting t)))
  119. (setq i (1+ i))))
  120.    );end t
  121.   ); end cond
  122.        ); end (= (car inp) 3)
  123. ; user pressed E of e
  124. ((member inp '((2 69)(2 101))) (command "zoom" "e"))
  125. ; user clicked R-mouse button, pressed enter or space (done selecting)
  126. ((or (equal (car inp) 25)(member inp '((2 13)(2 32))))
  127. (setq done-selecting t result nil))
  128. ; user pressed +
  129. ((equal inp '(2 43)) (command "zoom" "2x"))
  130. ; user pressed -
  131. ((equal inp '(2 45)) (command "zoom" ".5x"))
  132. ; user pressed z or Z
  133. ((member inp '((2 122)(2 90))) (command "'zoom" ""))
  134.      )
  135.    )
  136. )
  137. result
  138. )
  139. (defun _convert ( %lst / item name dim-ent dim-strings lst )
  140. (foreach item %lst
  141.    (setq name (car item) dim-strings '())
  142.    (foreach dim-ent (cadr item) (setq dim-strings (cons (get_dim_string dim-ent) dim-strings)))
  143.    (setq lst (cons (cons name (reverse dim-strings)) lst))
  144. )
  145. (reverse lst)
  146. )
  147. (defun get_dim_string ( %dim / dim dim-txt)
  148. (setq dim (entget %dim) dim-txt (cdr (assoc 1 dim)))
  149. (if (= dim-txt "")(setq dim-txt (rtos (cdr (assoc 42 dim)) 2 2)) dim-txt))
  150. (c:RlxDimensionToCSV)
Rlx级
 
 
7月10日更新代码,检查双维度和维度标题。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-14 00:28 , Processed in 0.649120 second(s), 74 queries .

© 2020-2025 乐筑天下

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