乐筑天下

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

[编程交流] Add Dimension Then Change It&#

[复制链接]

180

主题

639

帖子

463

银币

中流砥柱

Rank: 25

铜币
897
发表于 2022-7-6 06:27:53 | 显示全部楼层 |阅读模式
I have a bit of code which adds a dimension to the drawing. Based on some other criteria in the drawing I'd like to change the color of this dimension to red to indicate to the user there are some special considerations to be made. We thought about a note but the users prefer that the color of this dimension object be a different color.
 
Ok, so I add the dimension and then try to change it's color using "CHPROP" but that's not working. Can anyone offer some advice on how to change the color of a dimension? I'll be able to use (entlast) to select it. Any by doing so I get the properties of the dimension and cheat by copying it into the IDE and formatting it. I end up with this:
 
  1. ((-1 . ) (0 . "DIMENSION") (5 . "F9867") (102 . "{ACAD_XDICTIONARY") (360 . ) (102 . "}") (102 . "{ACAD_REACTORS") (330 . ) (102 . "}") (330 . ) (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "Dim1") (100 . "AcDbDimension") (280 . 0) (2 . "*D157") (10 -9.48943 -93.5625 0.0) (11 -9.48943 -90.5625 0.0) (12 0.0 0.0 0.0) (70 . 32) (1 . "") (71 . 5) (72 . 1) (41 . 1.0) (42 . 6.0) (73 . 0) (74 . 0) (75 . 0) (52 . 0.0) (53 . 0.0) (54 . 0.0) (51 . 0.0) (210 0.0 0.0 1.0) (3 . "Standard") (100 . "AcDbAlignedDimension") (13 -6.0 -87.5625 0.0) (14 -4.0 -93.5625 0.0) (15 0.0 0.0 0.0) (16 0.0 0.0 0.0) (40 . 0.0) (50 . 1.5708) (100 . "AcDbRotatedDimension"))
 
I believe the DXF code 67 is the color, but how would I go about setting it to "Red" given that this object will the (entlast) or I will have assigned it to something using (entlast) before moving on. In the end, if certain criteria are true, I want to change this dimension's color to "Red".
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-6 06:41:32 | 显示全部楼层
???
  1. (vla-put-color  acred)
回复

使用道具 举报

180

主题

639

帖子

463

银币

中流砥柱

Rank: 25

铜币
897
发表于 2022-7-6 06:54:02 | 显示全部楼层
Thanks BB.. I tried this first:
 
  1. (setq enlist(entget (entlast)))(subst (cons 67 1) (assoc 67 enlist) enlist)
 
But that's not it. So I tried your suggestion like so:
 
  1. vla-put-color (entlast) acred)
 
That missed the mark as well. Am I getting the syntax right in your suggestion? I'm still not very sharp on DXF codes. I was amazed at how with the first shot I was able to change the 67 value in the list, but that apparently is not for the color.
回复

使用道具 举报

22

主题

326

帖子

185

银币

后起之秀

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

铜币
243
发表于 2022-7-6 07:05:42 | 显示全部楼层
67 isn't dxf code of color (62). With Dimension, you must specify what u want to change color (text, diménsion lines, extension line, arrow .. ?), and i think u should use Visualisp in this case
 
Etc :
With obj = (vlax-ename->vla-object ename_of_dimension_object) = (vlax-ename->vla-object (entlast))
 
You can find what u need  more by dump dimension object :
回复

使用道具 举报

180

主题

639

帖子

463

银币

中流砥柱

Rank: 25

铜币
897
发表于 2022-7-6 07:12:01 | 显示全部楼层
Ok, I think I have it. Once the dimension is in and I can call it (entlast) or anything else...... and now for the finished product. I'm still a long way off from understanding all of the vlax and vla stuff. But this is what I've put together and it's working:
 
  1. (defun dim_color_change (dimcolor / obj) (setq obj (vlax-ename->vla-object (entlast))) (mapcar '(lambda (x)            (vl-catch-all-apply 'vlax-put (list obj x dimcolor))          ) ;_ end of lambda         '("Color"           "DimensionLineColor"           "ExtensionLineColor"           "TextColor"          ) ) ;_ end of mapcar (vlax-release-object obj) (princ)) ;_ end of defun
 
Thanks for the helpful pointers.
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-6 07:23:47 | 显示全部楼层
Bill,
 
You're dealing with internal Object's which do not have to be released; only external Objects (i.e., FileScriptingObject, Shell.Application, etc.) need to be released.
 
The Visual LISP extension Methods only work on Vla-Object (i.e., Vlax-Ename->Vla-Object, etc.), with exception to the Vlax-Curve* functions which also accept Ename as a valid argument.
 
The last entity added to the Database (entlast), is not always going to be your dimension... At minimum, you'll want to check that either (wcmatch (cdr (assoc 0 )) "DIM*"), or (wcmatch (strcase (vla-get-objectname )) "*DIM*"), prior to evaluating the rest of your code, IMO.
回复

使用道具 举报

180

主题

639

帖子

463

银币

中流砥柱

Rank: 25

铜币
897
发表于 2022-7-6 07:31:14 | 显示全部楼层
All very good points except that with my code I add the dimension and then immediately, and I mean immediately, hit the (entlast) thing. Sometimes I use (entlast) itself, other times I immediately assign (entlast) to a temp variable. Recall, that my projects for these guys are completely automated. There is no chance that a user would interrupt it or any other object be confused for (entlast). It serves me well, but only in this totally automated process can one be assured of such.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-10 18:26 , Processed in 0.527326 second(s), 66 queries .

© 2020-2025 乐筑天下

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