joemc 发表于 2022-7-5 22:50:07

Selecting a unique object (tri

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 size0.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.

joemc 发表于 2022-7-5 22:54:01

(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)

Dadgad 发表于 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?

joemc 发表于 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 showsLine(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):

(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 thansays "x objects found"but does not change their color.
 
Thanks for the help.

joemc 发表于 2022-7-5 23:05:09

Seems to identify any lines.Guess i will read AutoLISP pdf all weekend lol

hmsilva 发表于 2022-7-5 23:09:58

Hi Joe,
try to chage

(or (eq l 0.1876 ) (eq l 0.1875) )
to

(equal l 0.1875 0.001);; change the fuzz if necessaryHTHHenrique

Tharwat 发表于 2022-7-5 23:12:46

Try this .
 

(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) )

joemc 发表于 2022-7-5 23:16:49

Thanks !I have done thousands of files by hand.This will save me a lot of time.

Tharwat 发表于 2022-7-5 23:19:52

You're welcome , and good luck for the next files .

joemc 发表于 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
( ColorGray ( ssget ) ) and the code works fine.
 
But I am trying to pass the triangle to it and having no luck.
(ColorGray ( GetMTriangle ) )
 
I have tried many small variations, but below is where I am at.
 
 
 

(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:

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.
页: [1] 2
查看完整版本: Selecting a unique object (tri