你把下面这段代码保存为lsp文件,然后把这个lsp文件放在启动组里就行了.
每次打开文件时,它都会自动运行 ...
感谢,如果是在布局空间就不生效了,能否通用啊 惜惜2 发表于 2024-9-9 10:27
感谢,如果是在布局空间就不生效了,能否通用啊
把(410 . "Model")去掉 kozmosovia 发表于 2024-9-9 10:33
把(410 . "Model")去掉
谢谢:handshake 本帖最后由 惜惜2 于 2024-9-19 16:36 编辑
lijiao 发表于 2024-9-9 10:00
你把下面这段代码保存为lsp文件,然后把这个lsp文件放在启动组里就行了.
每次打开文件时,它都会自动运行 ...
<blockquote>(setq filename (vl-filename-base (getvar "dwgname")))
大佬帮忙最后的看下哪里错了,在你的基础上面增加的,用于提取关键字,提取到了后提取第2-4的字符并写入客户 (setq filename (vl-filename-base (getvar "dwgname")))
(if (setq space-pos (vl-string-search " " filename))
(progn
(setq drawing-number (substr filename 1 space-pos))
(setq part-name (substr filename (+ space-pos 2)))
(setq ss (ssget "x" '((0 . "INSERT"))))
(repeat (setq n (sslength ss))
(setq blockref (SSNAME SS (setq n (1- n))))
(setq blockref (vlax-ename->vla-object blockref))
(if (= (vla-get-HasAttributes blockref) :vlax-true)
(foreach attrib
(VLAX-SAFEARRAY->LIST
(VLAX-VARIANT-VALUE (vla-getattributes blockref))
)
(cond ((= (vla-get-tagstring attrib) "客户图号")
(vla-put-textstring attrib drawing-number)
)
((= (vla-get-tagstring attrib) "零件名称")
(vla-put-textstring attrib part-name)
)
((= (vla-get-tagstring attrib) "设计日期")
(vla-put-textstring attrib (rtos (getvar "CDATE") 2 0))
)
(IF
(= (vla-get-tagstring attrib) "编号")
(setq product-code (vla-get-textstring attrib))
)
(IF
(= (vla-get-tagstring attrib) "客户")
(let ((extracted-code (substr product-code 2 3)))
(vla-put-textstring attrib extracted-code)
)
)
)
)
)
)
)
)
)
(princ)
页:
1
[2]