乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 49|回复: 19

[编程交流] Modify Picked Attrbute Height(

[复制链接]

21

主题

155

帖子

135

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
105
发表于 2022-7-5 18:20:19 | 显示全部楼层 |阅读模式
I'm trying to create a lisp that modifies the height of a picked individual attribute in all blocks of the same name.
A prolonged Google search didn't come up with much.
There's BATTMAN of course, but in a multi-attributed block it's not always easy to discern which attribute is which, especialy if they've been given a ambiguous name. There's also Lee Macs excellent Redefine_Block_Text but it's redefines all items within a block.
My need is for a lisp which picks an attribute, returns the old height & prompts for a new height, then attsyncs all.
 
The code I have created works until the block is 'attsynced'. It modifies the height of the attribute, but it returns to the previous size on attsync. I would guess that it's modifying the height of the value of the attribute rather than the tag.
My code so far:
  1. (defun c:Atthght ( / a ent ent entdxf newh oldh ) (vl-load-com) (while (setq ent (car(nentsel "\nSelect Attribute :")))   (if (wcmatch (cdr (assoc 0 (setq entdxf (entget ent)))) "ATTRIB")     (progn    (setq oldh (rtos (cdr(assoc 40 (entget ent)))))    (setq newh (getstring (strcat "\nSpecify New Height: ")))        (if          (entmod (subst (cons 40 (atof newh)) (assoc 40 entdxf) entdxf))               (entupd ent)                   )(while (setq a (tblnext "BLOCK" (null a)))                                ;;           (if (= (cdr (Assoc 70 a)) 2)                                        ;; attsync                       (vl-cmdf "_.AttSync" "Name" (cdr (assoc 2 a)))                ;; bit                       )                                                        ;;                 )                                                                ;;     );; progn             (princ "\nSelected object is not an Attribute.")   ) ) (princ))
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 18:25:57 | 显示全部楼层
Since you are using ATTSYNC, you can change the height of the attribute definition within the block definition and such changes will be automatically reflected across all references of the block (your current code is changing the height of the attribute reference within a single block reference).
回复

使用道具 举报

21

主题

155

帖子

135

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
105
发表于 2022-7-5 18:27:53 | 显示全部楼层
Hello again Lee
 
I realised that it could be done using REFEDIT or BEDIT, I was trying to find a shortcut.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 18:30:45 | 显示全部楼层
I'm not suggesting using REFEDIT or BEDIT.
回复

使用道具 举报

21

主题

155

帖子

135

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
105
发表于 2022-7-5 18:34:41 | 显示全部楼层
Well, what are you suggesting?
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 18:38:20 | 显示全部楼层
 
As per my above post, that you:
 
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 18:42:11 | 显示全部楼层
To give some more direction: retrieve the BLOCK_RECORD entity using the tblobjname function, and step through the block component entities using the entnext function; when you encounter the target ATTDEF entity, modify the height in the same way as you have with the ATTRIB entity in your code. Then invoke the ATTSYNC command to apply the change across all references of the block.
 
To provide more information about the structure of a block definition, see my post here from 2012.
回复

使用道具 举报

21

主题

155

帖子

135

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
105
发表于 2022-7-5 18:45:33 | 显示全部楼层
I've never even heard of tblobynamethingy....
 
I will search for en existing lisp to see how it works
 
Ta Lee
回复

使用道具 举报

21

主题

155

帖子

135

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
105
发表于 2022-7-5 18:46:13 | 显示全部楼层
I got as far as:
  1. (setq entdxf (entget(car(entsel))))(setq bn (cdr(assoc 2 entdxf)))(tblobjname "block" bn)
 
Then I got a bit lost
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-5 18:50:57 | 显示全部楼层
As Lee described earlier that you need to work on the Block definition and not on the Block reference , so I am just giving you an example to show you the way you should go.
 
  1. (defun c:Test (/ s e h dc bn tg) ;;    Tharwat 27.11.2015    ;; (if   (and (setq s (nentsel "\nSelect Attribute in a Block :"))        (= (cdr (assoc 0 (setq e (entget (car s))))) "ATTRIB")        (setq h (getdist (strcat "\nSpecify new height < current height [ " (rtos (cdr (assoc 40 e)) 2) " ] :" )))   )    (progn      (setq dc (vla-get-activedocument (vlax-get-acad-object))            bn (vla-get-effectivename (vlax-ename->vla-object (cdr (assoc 330 e))))            tg (strcase (cdr (assoc 2 e)))      )      (vlax-for x (vla-item (vla-get-blocks dc) bn)        (if (and (= (vla-get-objectname x) "AcDbAttributeDefinition")                 (= (strcase (vla-get-tagstring x)) tg)            )          (vla-put-height x h)        )      )      (vl-cmdf "_attsync" "_name" bn)    ) ) (princ))(vl-load-com)
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-12 19:35 , Processed in 0.486784 second(s), 72 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表