乐筑天下

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

[编程交流] Small problem- a little rusty.

[复制链接]

15

主题

243

帖子

228

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
75
发表于 2022-7-5 22:41:01 | 显示全部楼层 |阅读模式
Hey all, I'm having to modify this routine pretty heavily for a new project that I've been on.
 
I'll be getting past each task as I come to it, and the first one I've came across is this....firstly, there are three tags for the blocks that I am extracting from the .dwg into excel...."Size" "Type" and "Tag".
 
The program I am using creates a "valllist" (values list), and then it shoots each bit of the vallist into excel, so I need these vallist to show the attribute values in a consistent manner.
 
Upon running the subfunction a few times over one drawing, I've noticed that some of the blocks have their attributes in reverse order, creating a fudged vallist. Where the size should be, I'm getting the "tag" in about half of the blocks.
 
I'll post how this vallist is looking, and then the code behind it.
 
  1. (createvallist ss)(("1623" "L6TM-H2" "02-0.5"") ("1624" "L6TM-H2" "02-0.5"") ("1625" "L6TM-H2" "02-0.5"") ("02-1.5"" "X1TF-H2" "1601") ("02-0.5"" "X1TR-H2" "1602") ("02-1"" "X4S-H2" "1603") ("02-1.5"" "X1TF-H2" "1606") ("02-0.5"" "X1TR-H2" "1607") ("02-1"" "X4S-H2" "1608") ("02-1.5"" "X1TF-H2" "1611") ("02-0.5"" "X1TR-H2" "1612") ("02-1"" "X4S-H2" "1613") ("02-1"" "U2TR-H2" "1616") ("1615" "L6TN-H2" "02-0.5"") ("1600" "L6TM-H2" "02-0.5"") ("1605" "L6TM-H2" "02-0.5"") ("1610" "L6TM-H2" "02-0.5"") ("1626" "X1TR-H2" "02-0.5"") ("1627" "X1TR-H2" "02-0.5"") ("1628" "X1TR-H2" "02-0.5"") ("1629" "X1TR-H2" "02-0.5"") ("1630" "X1TR-H2" "02-0.5"") ("1631" "X1TR-H2" "02-0.5"") ("02-0.5"" "X1TR-H2" "1632") ("02-0.5"" "X1TR-H2" "1633") ("0.5"" "X1TR-H2" "1634") ("0.5"" "X1TR-H2" "1637") ("0.5"" "L6TM-H2" "1636") ("0.5"" "L6TM-H2" "1635") ("0.5"" "X1TR-H2" "1638") ("02-0.5"" "X5TC-H2" "1639") ("02-0.5"" "X1TR-H2" "1640") ("" "" "") ("" "" "") ("" "" ""))
 
and here's what creates the vallist, the subfunction
  1. (defun createvallist ( ss / taglist tagrow valrow edata e i)(setq i -1);;FOR OAK GROVE VALVES(setq TagList '("TYPE" "TAG" "SIZE"))(repeat (sslength ss)(setq TagRow nil)(setq ValRow nil)(setq Edata (entget (setq e (ssname ss (setq i (1+ i))))))(while (/= (Dxf 0 Edata) "SEQEND")(if(and(= (Dxf 0 Edata) "ATTRIB")(member (dxf 2 Edata) TagList);;if tag is on list);and(progn(setq TagRow (cons (Dxf 2 Edata) TagRow))(setq valRow (cons (Dxf 1 Edata) ValRow)));progn)(setq Edata (entget (setq e (entnext e))))) ;while(setq vallist (cons valrow vallist)));repeat );defun
 
Now I've tried code like this, added right under the (setq TagRow...) and (setq ValRow...) portions
 
  1. (progn(setq TagRow (cons (Dxf 2 Edata) TagRow))(if (= (car tagrow) (strcase "TAG"))(reverse tagrow))(setq valRow (cons (Dxf 1 Edata) ValRow))(if (= (car tagrow)(strcase "TAG"))(reverse valrow)));progn
 
But unfortunately for me the vallist doesn't come out in a consistent manner, despite code that to me should work.
 
Could someone point me in the right direction, getting these attribute values to appear in a consistent fashion no matter the order that the attributes are showing in the blocks/vallist?
 
Thanks in advance!
回复

使用道具 举报

20

主题

338

帖子

323

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
100
发表于 2022-7-5 22:59:37 | 显示全部楼层
How about creating your value list as a list of dotted pairs ie. ("size" . value) ("tag" . value) and etc? I hope that I am understanding you correctly.
 
 
In further thought and testing.
 
Maybe use vlax commands to achieve the desired results.
 
Quick and dirty
 
  1. (setq blk-ref (vlax-ename->vla-object (car (entsel "\nSelect Block:"))))(setq att-list (vlax-safearray->list (vlax-variant-value (vlax-invoke-method blk-ref 'GetAttributes))))(setq att-ref (nth 0 att-list))(setq att-tag (vlax-get-property att-ref 'TagString))(setq att-string (vlax-get-property att-ref 'TextString))(setq att-item (cons att-tag att-string))
 
I hope this helps!
 
regards,
 
hippe013
回复

使用道具 举报

15

主题

243

帖子

228

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
75
发表于 2022-7-5 23:10:54 | 显示全部楼层
Can you show me how you'd accomplish this, and how the vallist would look?
回复

使用道具 举报

20

主题

338

帖子

323

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
100
发表于 2022-7-5 23:16:00 | 显示全部楼层
I edited my post. Does that help?
回复

使用道具 举报

15

主题

243

帖子

228

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
75
发表于 2022-7-5 23:22:40 | 显示全部楼层
Yes it does, thank you very much!
回复

使用道具 举报

20

主题

338

帖子

323

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
100
发表于 2022-7-5 23:31:27 | 显示全部楼层
You're welcome!
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 23:45:32 | 显示全部楼层
Why would you not use the TAG name as the test it would mean you have to write a few lines of code 3 times once for each tag, then they will always be in correct order.
 
Thinking a bit further pick a block create tag list pop DCL pick order then export does not matter how many attributes.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-11 03:16 , Processed in 0.396375 second(s), 66 queries .

© 2020-2025 乐筑天下

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