明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2084|回复: 5

选择尺寸或者文字更改图块的属性

[复制链接]
发表于 2012-6-10 23:27:44 | 显示全部楼层 |阅读模式
求高手解决~~!   现在的效果是:选择的尺寸或者文字只能更改图块属性初始建立的那个属性参照尺寸填入块中时,只取整数。
理想效果是能设定想要更改的目标属性, 标注填入时,取两位小数~~


(defun c:nmn(/ p sn en p1 nam ty e1 e2 st p2 p3 p4 ss );
(command "undo" "g")
(setq os (getvar "osmode") blp (getvar "blipmode"))
(setvar "blipmode" 0)
(setvar "osmode" 0)
(graphscr)
(if (null text0)(setq text0 ""))
(canzhao)
(while (setq p (entsel "请选取需要更改属性的图块~!"))
(setq sn (car p) en (entget sn) p1 (to 10) nam (to 2) ty (to 0))
(if (or (= "规格" ty)(= "INSERT" ty)(= "DIMENSION" ty))
(if (or (= "规格" ty)(= "DIMENSION" ty))
(progn ;; 将文字改为参照的文字内容
(setq e1 (subst (cons 1 st) (assoc 1 en) en))
(entmod e1)
);progn
(progn ;; 将属性改为参照的文字内容
(setq e1 (entget (entnext (cdr (car en)))))
(setq e1 (subst (cons 1 st) (assoc 1 e1) e1))
(entmod e1)(entmod en)
(if (or (eq nam "规格")(eq nam "规格1"))(progn
(setq e2 (entget (entnext (cdr (car e1)))))
(setq e2 (subst (cons 1 st) (assoc 1 e2) e2))
(entmod e2)(entmod en)
))
);progn
)
(progn
(princ "n**所选物体是")
(princ (cdr (assoc 0 en)))
(princ ", 不是文字或图块,请重新选择.**n")
)
)
)
(setvar "osmode" os)
(setvar "blipmode" blp)
(terpri)
(command "undo" "end"))
 楼主| 发表于 2012-6-10 23:36:32 | 显示全部楼层
前面没有上全,,不好意思~~~


(defun to (n)
(cdr (assoc n (entget sn)))
)
(defun canzhao (/ sn p13 p14) ;;提取参照文字或属性内容:
(setq sn (car (entsel (strcat "n点取需用参照的文字、属性或尺寸<" text0 ">:"))))
(if (= sn nil)
(setq st text0)
(if (or (= "TEXT" (to 0))(= "INSERT" (to 0))(= "DIMENSION" (to 0)))
(if (= "INSERT" (to 0))
(setq st (entget (entnext (cdr (car (entget sn)))))
st (cdr (assoc 1 st))
);;提取属性
(progn
(if (= "DIMENSION" (to 0))
(progn ;;提取尺寸
(setq p13 (to 13) p14 (to 14))
(if (eq (to 1) "")
(setq st (* (fix (/ (+ (distance p13 p14) 4) 10)) 10)
st (itoa st)
)
(setq st (to 1))
)
)
(setq st (to 1));;提取文字
)
)
);if
(setq st "")
);if
)
(setq text0 st)
)

(defun c:nmn(/ p sn en p1 nam ty e1 e2 st p2 p3 p4 ss );
(command "undo" "g")
(setq os (getvar "osmode") blp (getvar "blipmode"))
(setvar "blipmode" 0)
(setvar "osmode" 0)
(graphscr)
(if (null text0)(setq text0 ""))
(canzhao)
(while (setq p (entsel "请选取需要更改属性的图块~!"))
(setq sn (car p) en (entget sn) p1 (to 10) nam (to 2) ty (to 0))
(if (or (= "规格" ty)(= "INSERT" ty)(= "DIMENSION" ty))
(if (or (= "规格" ty)(= "DIMENSION" ty))
(progn ;; 将文字改为参照的文字内容
(setq e1 (subst (cons 1 st) (assoc 1 en) en))
(entmod e1)
);progn
(progn ;; 将属性改为参照的文字内容
(setq e1 (entget (entnext (cdr (car en)))))
(setq e1 (subst (cons 1 st) (assoc 1 e1) e1))
(entmod e1)(entmod en)
(if (or (eq nam "规格")(eq nam "规格1"))(progn
(setq e2 (entget (entnext (cdr (car e1)))))
(setq e2 (subst (cons 1 st) (assoc 1 e2) e2))
(entmod e2)(entmod en)
))
);progn
)
(progn
(princ "n**所选物体是")
(princ (cdr (assoc 0 en)))
(princ ", 不是文字或图块,请重新选择.**n")
)
)
)
(setvar "osmode" os)
(setvar "blipmode" blp)
(terpri)
(command "undo" "end"))
发表于 2012-6-11 02:48:53 | 显示全部楼层
微笑露一点
发表于 2012-9-24 23:30:21 | 显示全部楼层
多发好贴,造福人民!!!
发表于 2012-11-13 14:12:41 | 显示全部楼层
如何修改实现不要只取整数
发表于 2012-11-13 21:52:47 | 显示全部楼层
建议发片说明
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-12-22 11:03 , Processed in 0.227873 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表