Ampere 发表于 2022-7-5 15:53:34

从AutoCAD导出尺寸

嘿,我是这个论坛的新手=)希望得到一些指导。
 
有没有办法将尺寸从autoCAD导出到txt文件
我需要的程序,以获得红色的维度,并在txt文件中列出他们。
 
请友善一点,请记住,我对LISP完全陌生,除此之外几乎没有编程技能,但思想开放,愿意学习=)

Aftertouch 发表于 2022-7-5 16:02:31

你好,安培,
 
这会让你开始。。。
 

(defun C:GetDimLengths ( / AllDimensions CheckDimension n dimlist dimcontent filename fil )        ; Define the command name, localize the variables.
(setq AllDimensions (ssget "_X" (list (cons 0 "Dimension"))))                                        ; Sets AllDimensions as a selection set of all Dimensions the the drawing.
(setq n 0)                                                                                        ; Set loop counter 0.
(setq dimlist '())                                                                                ; Set dimensionslist cleared.
(repeat (sslength AllDimensions)                                                        ; Repeat for all in selectionset AllDimensions
        (setq CheckDimension (entget (ssname AllDimensions n)))                                ; Gets the entity
        (setq dimcontent (cdr (assoc 42 CheckDimension)))                                ; Reads the measured distance
        (setq dimlist (cons dimcontent dimlist))                                        ; Adds this distance to a totallist
        (setq n (+ 1 n))                                                                ; Up the counter for next dimension
)                                                                                        ; End repeat
(if (setq filename (getfiled "\nFile Location..." "DimensionExport" "txt" 11))                ; Make a new textfile with default name
        (progn                                                                                ; When created do this.
                (setq fil (open filename "w"))                                                ; Open the new file
                (foreach x dimlist                                                        ; For all dimensions in the totallist
                        (princ (strcat (rtos x 2) "\n") fil)                                ; Print them in them in the textfile
                )                                                                        ; Close 'foreach'
                (close fil)                                                                ; Close filewriter
                (startapp "notepad" filename)                                                ; Open created file with notepad
                (graphscr)                                                                ; Return to screen
        )                                                                                ; Close 'do this'
)                                                                                        ; End if
(princ)                                                                                                ; Silent exit
)                                                                                                ; End function

 
-“红色”是如何控制的?ByLayer还是set in the properties?
-需要对列表进行排序吗?

Tharwat 发表于 2022-7-5 16:11:59

抚摸之后,好好努力。
 
仅供参考,没有必要分配空列表“dimlist”,因为cons函数会处理这样的事情。

Ampere 发表于 2022-7-5 16:18:28

谢谢你的快速回复,很好的评论。
到目前为止,红色文本仅在属性中更改,但如果更容易从图层中提取值,我可以修改CAD文件=)
我明天会试试。

Aftertouch 发表于 2022-7-5 16:30:31

更改:

(setq AllDimensions (ssget "_X" (list (cons 0 "Dimension"))))                                        ; Sets AllDimensions as a selection set of all Dimensions the the drawing.

 
为此,选择所有标注,其中属性设置为红色。

(setq AllDimensions (ssget "_X" (list (cons 0 "Dimension")(cons 62 1))))                                        ; Sets AllDimensions as a selection set of all Dimensions the the drawing.

 
 
或者,当层名称已知时,选择所有维度

(setq AllDimensions (ssget "_X" (list (cons 0 "Dimension")(cons 8 "YOURLAYERNAMEHERE"))))                                        ; Sets AllDimensions as a selection set of all Dimensions the the drawing.

BIGAL 发表于 2022-7-5 16:37:01

如果要拾取尺寸并获取其第二层方法
 

(setq obj (vlax-ename->vla-object (car (entsel "\nPick Dimension"))))
(setq lay (vla-get-layer obj))
(setq AllDimensions (ssget "_X" (list (cons 0 "Dimension")(cons 8 lay))))

 

(setq obj (entget (car (entsel "\nPick Dimension "))))
(setq lay (cdr (assoc 8 obj)))
(setq AllDimensions (ssget "_X" (list (cons 0 "Dimension")(cons 8 lay))))

minhphuong_humg 发表于 2022-7-5 16:40:00

 
帮助我,案例按窗口选择多个维度。
非常感谢。

Aftertouch 发表于 2022-7-5 16:51:27

将X更改为L

minhphuong_humg 发表于 2022-7-5 16:59:53

亲爱的Aftertouch。
 
(defun C:GetDimLengths ( / AllDimensions CheckDimension n dimlist dimcontent filename fil )        ; Define the command name, localize the variables.
;(setq AllDimensions (ssget "_X" (list (cons 0 "Dimension"))))                                        ; Sets AllDimensions as a selection set of all Dimensions the the drawing.
(setq obj (vlax-ename->vla-object (car (entsel "\nPick Dimension"))))
(setq lay (vla-get-layer obj))
(setq AllDimensions (ssget "_L" (list (cons 0 "Dimension")(cons 8 lay))))
(setq n 0)                                                                                        ; Set loop counter 0.
(setq dimlist '())                                                                                ; Set dimensionslist cleared.
(repeat (sslength AllDimensions)                                                        ; Repeat for all in selectionset AllDimensions
        (setq CheckDimension (entget (ssname AllDimensions n)))                                ; Gets the entity
        (setq dimcontent (cdr (assoc 42 CheckDimension)))                                ; Reads the measured distance
        (setq dimlist (cons dimcontent dimlist))                                        ; Adds this distance to a totallist
        (setq n (+ 1 n))                                                                ; Up the counter for next dimension
)                                                                                        ; End repeat
(if (setq filename (getfiled "\nFile Location..." "DimensionExport" "txt" 11))                ; Make a new textfile with default name
        (progn                                                                                ; When created do this.
                (setq fil (open filename "w"))                                                ; Open the new file
                (foreach x dimlist                                                        ; For all dimensions in the totallist
                        (princ (strcat (rtos x 2) "\n") fil)                                ; Print them in them in the textfile
                )                                                                        ; Close 'foreach'
                (close fil)                                                                ; Close filewriter
                (startapp "notepad" filename)                                                ; Open created file with notepad
                (graphscr)                                                                ; Return to screen
        )                                                                                ; Close 'do this'
)                                                                                        ; End if
(princ)                                                                                                ; Silent exit
)                                                                                                ; End function
 
我将_X更改为_L,但不工作选择(不拾取)维度。
谢谢
页: [1]
查看完整版本: 从AutoCAD导出尺寸