joemc Posted May 25, 2014 Posted May 25, 2014 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. Quote
joemc Posted May 25, 2014 Author Posted May 25, 2014 (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) Quote
Dadgad Posted May 25, 2014 Posted May 25, 2014 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? Quote
joemc Posted May 25, 2014 Author Posted May 25, 2014 (edited) 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): (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. Edited May 25, 2014 by joemc Quote
joemc Posted May 25, 2014 Author Posted May 25, 2014 Seems to identify any lines. Guess i will read AutoLISP pdf all weekend lol Quote
hmsilva Posted May 25, 2014 Posted May 25, 2014 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 necessary HTH Henrique Quote
Tharwat Posted May 25, 2014 Posted May 25, 2014 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) ) Quote
joemc Posted May 25, 2014 Author Posted May 25, 2014 Thanks ! I have done thousands of files by hand. This will save me a lot of time. Quote
Tharwat Posted May 25, 2014 Posted May 25, 2014 Thanks ! I have done thousands of files by hand. This will save me a lot of time. You're welcome , and good luck for the next files . Quote
joemc Posted June 30, 2014 Author Posted June 30, 2014 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 . <Entity name: 7ff729f1d110>) (0 . "LINE") (330 . <Entity name: 7ff729f1bf00>) (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. Quote
Tharwat Posted June 30, 2014 Posted June 30, 2014 Replace this . (setq sstri(ssadd (entget sn) sstri)) With this. (ssadd sn sstri) And this is enough . and this . (if (eval ss) With this . (if ss Quote
joemc Posted June 30, 2014 Author Posted June 30, 2014 With your two changes I get: ; error: bad function: and no lines change color. Below still works: Command: (colorgray (ssget)) I added eval because it seemed to fix an issue that doesn't exist anymore. Quote
joemc Posted June 30, 2014 Author Posted June 30, 2014 Could it be a scope issue? will sstri still exist when used in this context? I would think it is returning the list as a "value" I come more from a C environment. LISP has been something else so far. Quote
joemc Posted June 30, 2014 Author Posted June 30, 2014 Got it to work, but i don't really understand why. I added (eval sstri) at end of function instead of just (sstri). (defun GetMTriangle (/ ss i sn l ) ( 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)) (ssadd sn sstri) ) ) ) (eval sstri) ) Quote
Tharwat Posted June 30, 2014 Posted June 30, 2014 Explain what you are trying to do to avoid tons of questions and wasting of time . Quote
joemc Posted June 30, 2014 Author Posted June 30, 2014 ColorGray( ss) Modify color attribute of all entities in a selection set to pen 8 (defun GetMTriangle (/ ss i sn l ) Return all lines in drawing of length 0.1876 or 0.1875 as a selection set My code works. Just didn't understand why you need to use (eval ss) to return selection set instead of just (ss). If I am wasting your time, don't bother. Just trying to learn, maybe I am on the wrong forum. Quote
Tharwat Posted July 1, 2014 Posted July 1, 2014 ColorGray( ss) Modify color attribute of all entities in a selection set to pen 8 What was wrong with my previous post HERE ? [code](defun GetMTriangle (/ ss i sn l ) My code works. Just didn't understand why you need to use (eval ss) to return selection set instead of just (ss). Not needed . Quote
joemc Posted July 1, 2014 Author Posted July 1, 2014 I should of started a new thread, because my question is unrelated to the initial thread. I will. My goal is to learn how to return a selection set for more than this only purpose. I have got it to work. I think the eval is required because there is an extra set of () around the set. What was wrong with my previous post HERE ? Nothing, code works great and taught me a lot. Not needed . I disagree I think it is more clear to be able to write code like below even though it is less efficient. Obviously just an opinion. (Color Gray GetMTriangle) (Color Gray GetBendLines) (Color Blue GetWeldMarkers) (Color Blue GetEtchText) Gray = no cut Blue = etch in my CAM software. Thank you for your help. I have read through your other posts and you have a lot of knowledge. Quote
Tharwat Posted July 1, 2014 Posted July 1, 2014 Thank you for your help. I have read through your other posts and you have a lot of knowledge. You're welcome , and hope you understand that when I said to avoid wasting of time in post # 15 , that was to save time for you and to get the best reply when you explain your aim clearly to allow more users to participate with their knowledge as well and nothing's more . Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.