惜惜2
发表于 2024-10-7 16:15:11
kozmosovia 发表于 2024-10-7 16:01
(if (setq space-pos (vl-string-search " " filename))
文件名带有空格才会执行后面的代码
文件名这些格式都是对的因为需要判断空格去循环以及填入属性值
kozmosovia
发表于 2024-10-7 16:27:44
瞎JB扯,你的代码对你给的DWG,执行个鬼。
提问都给埋坑,还是自己琢磨消磨下自己时间比较好。
ljpnb
发表于 2024-10-7 16:35:21
本帖最后由 ljpnb 于 2024-10-7 17:15 编辑
(defun c:test ()
惜惜2
发表于 2024-10-7 16:36:32
kozmosovia 发表于 2024-10-7 16:27
瞎JB扯,你的代码对你给的DWG,执行个鬼。
提问都给埋坑,还是自己琢磨消磨下自己时间比较好。
你用这个LISP试下我加载是可以的只有最后一步代码实现不了
ljpnb
发表于 2024-10-7 16:39:17
attribname:如果“客户”在“产品编码”之前时就会出错
惜惜2
发表于 2024-10-7 16:42:36
ljpnb 发表于 2024-10-7 16:39
attribname:如果“客户”在“产品编码”之前时就会出错
谢谢,我再研究一下 ,上面的代码提示语法错误
ljpnb
发表于 2024-10-7 17:16:00
(defun c:test ()
(setq e1 nil)
(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)
(progn
(foreach attrib
(VLAX-SAFEARRAY->LIST
(VLAX-VARIANT-VALUE (vla-getattributes blockref))
)
(if (= (vla-get-tagstring attrib) "产品编码")
(setq e1 (vla-get-textstring attrib))
)
)
(setq E2 (substr E1 2 3))
(foreach attrib
(VLAX-SAFEARRAY->LIST
(VLAX-VARIANT-VALUE (vla-getattributes blockref))
)
(setq attribname (vla-get-tagstring attrib))
(cond ((wcmatch attribname "客户图号")
(vla-put-textstring attrib drawing-number)
)
((wcmatch attribname "零件名称")
(vla-put-textstring attrib part-name)
)
((and
(wcmatch attribname "设计日期")
(= (vla-get-textstring attrib) "")
)
(vla-put-textstring
attrib
(menucmd "m=$(edtime,$(getvar,DATE),yyyy-mo-dd)")
)
)
((wcmatch attribname "客户")
(vla-put-textstring attrib E2)
)
)
)
)
)
)
)
)
(princ)
)
惜惜2
发表于 2024-10-7 17:23:31
ljpnb 发表于 2024-10-7 17:16
可以了 这是增加了先判断不为空值吗
ljpnb
发表于 2024-10-7 17:34:21
本帖最后由 ljpnb 于 2024-10-7 17:35 编辑
惜惜2 发表于 2024-10-7 17:23
可以了 这是增加了先判断不为空值吗
是的,先取值
平时很少用到属性块,也学习了一下
惜惜2
发表于 2024-10-10 10:19:09
本帖最后由 惜惜2 于 2024-10-10 14:22 编辑
ljpnb 发表于 2024-10-7 17:34
是的,先取值
平时很少用到属性块,也学习了一下(setq E1 nil)
(setq E3 nil)
(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)
(progn
(foreach attrib
(VLAX-SAFEARRAY->LIST
(VLAX-VARIANT-VALUE (vla-getattributes blockref))
)
(if(or (= (vla-get-tagstring attrib) "产品编码")
(= (vla-get-tagstring attrib) "编号"))
(setq e1 (vla-get-textstring attrib))
)
)
(setq E2 (substr E1 2 3))
(foreach attrib
(VLAX-SAFEARRAY->LIST
(VLAX-VARIANT-VALUE (vla-getattributes blockref))
)
(if(and(= (vla-get-tagstring attrib) "设计日期")(not (equal (vla-get-textstring attrib) "")))
(setq E3 (vl-prin1-to-string (vla-get-textstring attrib)))
)
)
(if E3
(setq e3-length (length E3))
)
(if E3
(if (>= e3-length 8)
(setq E4 (strcat (substr E3 0 4) "-" (substr E3 4 2) "-" (substr E3 6 2)))
(setq E4 nil))
)
(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)
)
((and(= (vla-get-tagstring attrib) "设计日期")
(equal (vla-get-textstring attrib) ""))
(if E4
(vla-put-textstring attrib E4)
(vla-put-textstring attrib (menucmd "m=$(edtime,$(getvar,DATE),yyyy-mo-dd)")))
)
((= (vla-get-tagstring attrib) "客户")
(vla-put-textstring attrib E2)
)
)
)
)
)
)
)
)
(princ)
有时间帮忙看下这个吗,假设属性值不为空时,赋值给E3并转换格式再赋值给E4这里有问题