乐筑天下

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

[编程交流] Select by Color - TIP 1046

[复制链接]

5

主题

27

帖子

22

银币

初来乍到

Rank: 1

铜币
25
发表于 2022-7-6 06:49:56 | 显示全部楼层 |阅读模式
I tried to get the following LISP routine to run. However, I was trying to locate the error but without success and I would like that someone can help me please:
 
  1. ;TIP1046.LSP: CLR.LSP Select by Color (C)1994, Grant Kiba;Collection function;--------------------------------------------------------------------(defun collect (E1) ;Define the collection funtion(if (= c nil) ;Set if no selection set(setq C(ssadd E1)) ;THEN ;Then create the set(setq C(ssadd E1 C)) ;ELSE ;or add this object to the current set);end if);end defun;Color selection function;-------------------------------------------------------------------(defun clr (/ A B C COUNT NUM CLRLAY) ;Define function(setq COUNT 0) ;Set counter to 0(initget 6) ;Don't negative values(princ "\nRed=1,Yellow-2,Green=3,Cyan=4,Blue=5,Magenta=6,White=7,Byblock=0")(setq CLRNUM (getint"\nEnter color number or press "Enter" to select: ")) ;Get color number(if(= CLRNUM nil)(progn(initget 1)(setq SAMPLE (entget(car(entsel "\nSelect object /w color to filter: "))))(if (null (assoc 62 SAMPLE))(progn ;THEN(setq LAY(cdr(assoc 8 SAMPLE)))(setq CLRNUM(cdr(assoc 62 (tblsearch "layer" LAY)))));end progn(setq CLRNUM (cdr (assoc 62 SAMPLE))) ;ELSE);end if);end progn);end if(setq MSG (strcat "\nFiltering color #" (itoa CLRNUM)))(princ MSG)(princ "\nWindow or select objects to filter then press "Enter"")(while (null A)(setq A (ssget)) ;Get initial selection(if (null A) (princ "No objects to filter! Select again or ^C to abort.")));end while(setq NUM (sslength A)) ;Get number of objects selected(while (< COUNT NUM)(setq B (entget (ssname A COUNT))) ;Get entity list(if (/= (assoc 62 B) nil) ;If the object has a color;THEN(if (equal (assoc 62 B) (cons 62 CLRNUM)) ;If the color matches(collect (ssname A COUNT)) ;Then Collect object);end if;ELSE ;Else get object's layer(progn(setq LAY(cdr(assoc 8 B)))(setq CLRLAY(cdr(assoc 62 (tblsearch "layer" LAY))))(if (= CLRNUM CLRLAY) ;If the layer matches color(collect (ssname A COUNT)) ;Collect the object);end if);end progn);end if(setq COUNT (+ 1 COUNT)) ;Check next object in set);end while(if (null C)(progn(command "")(princ "No objects match filter color!")(princ));end progn(setq X C) ;Sends the selection set to the current commad);end if);end clr.lsp
回复

使用道具 举报

9

主题

71

帖子

62

银币

初来乍到

Rank: 1

铜币
45
发表于 2022-7-6 07:04:11 | 显示全部楼层
  1. (setq CLRNUM (getint "\nEnter color number or press "Enter" to select: ")) ;Get color number
 
maybe
回复

使用道具 举报

5

主题

27

帖子

22

银币

初来乍到

Rank: 1

铜币
25
发表于 2022-7-6 07:10:02 | 显示全部楼层
 
I think it has to do with the parentheses but where I don't know.
回复

使用道具 举报

9

主题

71

帖子

62

银币

初来乍到

Rank: 1

铜币
45
发表于 2022-7-6 07:17:02 | 显示全部楼层
 
No, haha
In your code it is (getint"\nEnter...
Maybe you just need to get a space there like (getint "\nEnter...
 
edit: nvm, it works even without space
回复

使用道具 举报

26

主题

1495

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 07:25:47 | 显示全部楼层
First off, that is a horribly written routine.
 
So don't blame yourself for having difficulties in debugging it.
 
Basic question:
 
Do you to make a selection based on the group 62 number value a user enters?
 
or
 
Do you want to make selection of entities that match the color of a user picked entity?
 
-David
回复

使用道具 举报

5

主题

27

帖子

22

银币

初来乍到

Rank: 1

铜币
25
发表于 2022-7-6 07:29:14 | 显示全部楼层
 
I'm sorry I didn't looked at that space in your reply.
 
However, I don't get it work and still don't know why.
回复

使用道具 举报

GP_

8

主题

248

帖子

245

银币

初来乍到

Rank: 1

铜币
42
发表于 2022-7-6 07:40:23 | 显示全部楼层
(defun c:clr (/ A B C COUNT............
.............
.............
.............
(setq X C) ;Sends the selection set to the current commad
.............
.............
 
 
(i.e.)
 
Command: MOVE
Select object: 'clr
Red=1,Yellow-2,Green=3,Cyan=4,Blue=5,Magenta=6,White=7,Byblock=0
Enter color number or press "Enter" to select: 3
Filtering color #3
Window or select objects to filter then press "Enter"
etc.
etc.
回复

使用道具 举报

5

主题

27

帖子

22

银币

初来乍到

Rank: 1

铜币
25
发表于 2022-7-6 07:43:42 | 显示全部楼层
 
Thank you very much for your effort! However, now it's getting complicated for me and I get lost.
I put that c: after defun but where exactly the rest goes I don't know.
回复

使用道具 举报

GP_

8

主题

248

帖子

245

银币

初来乍到

Rank: 1

铜币
42
发表于 2022-7-6 07:55:50 | 显示全部楼层
I posted an example from the command line:
 
 
 
 
 
In lisp, simpler:
 
  1. ;Move by Color(defun c:[b]mbc[/b] ()   (command "_MOVE" (clr) "" pause))
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-10 15:12 , Processed in 0.669235 second(s), 70 queries .

© 2020-2025 乐筑天下

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