乐筑天下

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

[编程交流] How to ASSOC a DXF Code, only

[复制链接]

77

主题

298

帖子

232

银币

后起之秀

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

铜币
394
发表于 2022-7-5 20:11:06 | 显示全部楼层 |阅读模式
Hi guys,
 
I'm just in the process of modifying a Text-to-MText routine (not my own, all credit to Peter Jamtgaard for the original, which I found here... https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/text-to-mtext-without-txt2mtxt/td-p/1491008).
 
  1. ;;;Here is a program to convert a group of text to mtext.;;;They must be lined up vertically.;;;Peter Jamtgaard(defun C:t2m (/ CNT ENAM ELST INSP STRLST TSTR)(setq SSET (ssget (list (cons 0 "TEXT")))CNT 0)(repeat (sslength SSET)(setq ENAM (ssname SSET CNT)CNT (1+ CNT)ELST (entget ENAM)INSP (assoc 10 ELST)TXTCLR (cdr (assoc 62 ELST))TXTHT (cdr (assoc 40 ELST))TSTR (cdr (assoc 1 ELST)))(setq STRLST (cons (cons TSTR (cdr INSP)) STRLST))(setq INSP (mapcar '(lambda (X Y) (+ X Y)) INSP (list 0 0.0 TXTHT0.0))))(print STRLST)(setq STRLST (sort_list STRLST 2 '>=)MTSTR "")(print STRLST)(foreach N (mapcar 'car STRLST)(if (= MTSTR "")(setq MTSTR N)(setq MTSTR (strcat MTSTR "\\P" N))))(entmake(setq MLST (list(cons 0 "MTEXT")(cons 100 "AcDbEntity")(cons 410 (getvar "ctab"))(assoc 8 ELST)(cons 100 "AcDbMText")INSP(assoc 40 ELST)(cons 71 1)(cons 72 5)(cons 44 0.96)(cons 62 TXTCLR)(cons 1 MTSTR)(assoc 7 ELST))))(command "erase" SSET ""))(defun SORT_LIST (SLIST ITEM SYM)(setqSLIST (vl-sort SLIST '(lambda (n1 n2) ((eval SYM) (nth ITEM n1) (nthITEM n2))))))
I'm trying to get the newly created MTEXT to be the same colour of the source text.  It doesn't matter to me which DTEXT element is read for the colour, as most of the time the text selected will match each other for colour.
 
Where I'm falling down is... TXTCLR (cdr (assoc 62 ELST)).  It occurs to me that the DXF code for colour is only present if the element has a colour set other than 'ByLayer'.  So if the selected text is coloured 'ByLayer', there is not DXF code 62 to read.
 
So my question is, is it at all possible to only read the DXF code 62, if it is present?  And only assign this DXF code to the newly created MTEXT if it exists in the source text?
 
Hopefully that was a clear enough explanation.
 
Thanks a lot for any help.
回复

使用道具 举报

pBe

32

主题

2722

帖子

2666

银币

后起之秀

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

铜币
211
发表于 2022-7-5 20:26:32 | 显示全部楼层
Quick mod
 
  1. (cons 62 (if TXTCLR TXTCLR 256))
回复

使用道具 举报

77

主题

298

帖子

232

银币

后起之秀

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

铜币
394
发表于 2022-7-5 20:37:46 | 显示全部楼层
Hi pBe, thanks so much for the quick reply.
 
So the issue wasn't reading the colour, it was writing it?
回复

使用道具 举报

pBe

32

主题

2722

帖子

2666

银币

后起之秀

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

铜币
211
发表于 2022-7-5 20:58:18 | 显示全部楼层
 
Yes lamensterms, (62) is not valid
回复

使用道具 举报

77

主题

298

帖子

232

银币

后起之秀

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

铜币
394
发表于 2022-7-5 21:04:29 | 显示全部楼层
Awesome, thanks for that pBe.
回复

使用道具 举报

pBe

32

主题

2722

帖子

2666

银币

后起之秀

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

铜币
211
发表于 2022-7-5 21:22:31 | 显示全部楼层
 
NP lamensterms
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-11 09:04 , Processed in 0.387205 second(s), 64 queries .

© 2020-2025 乐筑天下

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