乐筑天下

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

[编程交流] Selecting a unique object (tri

[复制链接]

2

主题

12

帖子

10

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-5 22:50:07 | 显示全部楼层 |阅读模式
This may be a general Autocad question.
 
How do I find a unique object and change it's color with a lisp routine?  It is in different locations on every drawing.
 
 
It's always the same size  0.1876 x 0.1875 x 0.1875
 
 
I've been researching myself and it appears some form of ssget should be able to filter this object out.  or qselect or selectsimilar. Any ideas?
 
Thanks for your time,
Joe
 
Sorry for double post, first one is being held back because it had links to screenshots in it.
回复

使用道具 举报

2

主题

12

帖子

10

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-5 22:54:01 | 显示全部楼层
  1. (defun J:CHCOLOR (/ ss ) (setq ss (ssget))(if ss    (command "._CHANGE" ss "" "Properties" "Color" "8" ""))(princ) );defun
 
What I have done so far. (missing the hard part of finding the triangle)
回复

使用道具 举报

5

主题

1074

帖子

1088

银币

初来乍到

Rank: 1

铜币
9
发表于 2022-7-5 22:56:58 | 显示全部楼层
Welcome to CADTutor.  
 
You could use QSELECT.
Might these all be POLYLINES?
If so, define your selection set as Polylines with AREA equal to whatever it works out to.
Once selected you can change their color with Properties.\\Do you really want to change their color?
 
Might you want to create a new layer with that color, and move all these triangels onto that layer,
rather than Override their color by layer?
回复

使用道具 举报

2

主题

12

帖子

10

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-5 23:01:08 | 显示全部楼层
Layer would be ok too.  
 
I work in the sheetmetal industry and triangle is to show bend orientation on flat file.  
 
Changing layer would be ok too, just some way to make CAM software know not to cut the triangle into the part.
 
I am fairly new to Autocad in general.  It appears to be independent lines.  Properties when selected shows  Line(3) and alot of "*VARIES*"
 
 
I tried adapting code I found here (http://www.cadtutor.net/forum/showthread.php?72546-Erase-specified-length-of-lines-in-by-Script-Lisp):
  1. (defun j:CHCOLORB (/ ss i sn l) (if (setq ss (ssget "_:L" '((0 . "LINE"))))   (repeat (setq i (sslength ss))     (setq sn (ssname ss (setq i (1- i))))     (setq l (distance (cdr (assoc 10 (entget sn))) (cdr (assoc 11 (entget sn)))))     (if (or (eq l 0.1876 ) (eq l 0.1875) )       (command "._CHANGE" sn "" "Properties" "Color" "8" ""))            )   ) (princ) )
 
  There aren't likely any other lines this length.  Not ideal but would work until I learn more.  
 
The code above requires I make a selection than  says "x objects found"  but does not change their color.
 
Thanks for the help.
回复

使用道具 举报

2

主题

12

帖子

10

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-5 23:05:09 | 显示全部楼层
Seems to identify any lines.  Guess i will read AutoLISP pdf all weekend lol
回复

使用道具 举报

1

主题

475

帖子

481

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 23:09:58 | 显示全部楼层
Hi Joe,
try to chage
  1. (or (eq l 0.1876 ) (eq l 0.1875) )
to
  1. (equal l 0.1875 0.001);; change the fuzz if necessaryHTHHenrique
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-5 23:12:46 | 显示全部楼层
Try this .
 
  1. (defun c:Test (/ ss i sn l) (if (setq ss (ssget "_:L" '((0 . "LINE"))))   (repeat (setq i (sslength ss))     (setq sn (ssname ss (setq i (1- i))))     (setq l (distance (cdr (assoc 10 (entget sn))) (cdr (assoc 11 (entget sn)))))     (if (or (equal l 0.1876 1e- (equal l 0.1875 1e-4))       (entmod (append (entget sn) '((62 . )))   )     )   ) (princ) )
回复

使用道具 举报

2

主题

12

帖子

10

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-5 23:16:49 | 显示全部楼层
Thanks !  I have done thousands of files by hand.  This will save me a lot of time.
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-5 23:19:52 | 显示全部楼层
You're welcome , and good luck for the next files .
回复

使用道具 举报

2

主题

12

帖子

10

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-5 23:21:36 | 显示全部楼层
I need to color other entities to pen 8 as well so i split the function up.
 
I can do
  1. ( ColorGray ( ssget ) )
and the code works fine.
 
But I am trying to pass the triangle to it and having no luck.
  1. (ColorGray ( GetMTriangle ) )

 
I have tried many small variations, but below is where I am at.
 
 
 
  1. (defun ColorGray (ss / i )(if (eval ss)         (repeat (setq i (sslength ss))                (setq sn (ssname ss (setq i (1- i))))                (entmod (append (entget sn) '((62 . )))        ))(princ))(defun GetMTriangle (/ ss i sn l sstri )( setq sstri (ssadd)) (if (setq ss (ssget "_X" '((0 . "LINE"))))        (repeat (setq i (sslength ss))                (setq sn (ssname ss (setq i (1- i))))                (setq l (distance        (cdr (assoc 10 (entget sn)))                                        (cdr (assoc 11 (entget sn)))                                )                )                (if (or (equal l 0.1876 1e- (equal l 0.1875 1e-4))                        (setq sstri(ssadd (entget sn) sstri))                                      )        ))(sstri))
 
 
Output:
  1. Command: (colorgray (getmtriangle)); error: bad argument type: lentityp ((-1 . ) (0 . "LINE") (330 . ) (5 . "89") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "1") (62 . 3) (100 . "AcDbLine") (10 0.2187 2.4759 0.0) (11 0.3125 2.6383 0.0) (210 0.0 0.0 1.0))
 
 
Any ideas? Thanks.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-11 03:02 , Processed in 0.774178 second(s), 72 queries .

© 2020-2025 乐筑天下

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