本帖最后由 lijiao 于 2024-9-9 10:02 编辑
你把下面这段代码保存为lsp文件,然后把这个lsp文件放在启动组里就行了.
每次打开文件时,它都会自动运行一次
- (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")
- (410 . "Model")
- )
- )
- )
- (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)
- )
- )
- )
- )
- )
- )
- )
- (princ)
|