greatday2882 Posted November 23, 2011 Posted November 23, 2011 I have been searching for a lisp that will prompt you to select objects, and change all selected objects color from "By Layer" to whatever color they currently are. Has anyone seen something that will do that? Quote
alanjt Posted November 23, 2011 Posted November 23, 2011 (defun c:test (/ ss i d) (if (setq ss (ssget "_:L")) (repeat (setq i (sslength ss)) (entmod (append (setq d (entget (ssname ss (setq i (1- i))))) (list (assoc 62 (tblsearch "LAYER" (cdr (assoc 8 d))))) ) ) ) ) (princ) ) Quote
greatday2882 Posted November 28, 2011 Author Posted November 28, 2011 Thank you so much! That is exactly what i was looking for Quote
alanjt Posted November 28, 2011 Posted November 28, 2011 Thank you so much! That is exactly what i was looking for You're welcome. Quote
VVA Posted November 29, 2011 Posted November 29, 2011 My 5 cent COLORFL - Color From Layer PFL - Properties From Layer (color linetype lineweight) Quote
BlackBox Posted November 29, 2011 Posted November 29, 2011 (edited) My 5 centCOLORFL - Color From Layer PFL - Properties From Layer (color linetype lineweight) VVA, you might consider using VLAX-FOR when using VL* functions, and iterating a SelectionSet (much faster). :wink: Small example (based on your code - hope you don't mind): (defun c:CBL () (c:ColorByLayer)) (defun c:ColorByLayer (/ *error*) (princ "\rCOLORBYLAYER ") (vl-load-com) (defun *error* (msg) (cond ((not msg) (if acDoc (vla-endundomark acDoc))) ; Normal exit ((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit) ((princ (strcat "\n** Error: " msg " ** ")))) ; Fatal error, display it (princ)) ((lambda (acDoc / ss oLayer oLayers oLayersList) (if (setq ss (ssget "_:L")) (progn (vla-startundomark acDoc) (vlax-for x (setq ss (vla-get-activeselectionset acDoc)) (if (= :vlax-true (vla-get-lock (setq oLayer (vla-item (cond (oLayers) ((setq oLayers (vla-get-layers acDoc)))) (vla-get-layer x))))) (progn (setq oLayersList (cons oLayer oLayersList)) (vla-put-lock oLayer :vlax-false))) (vl-catch-all-apply 'vla-put-color (list x (vla-get-color oLayer)))) (vla-delete ss) (foreach oLayer oLayersList (vla-put-lock oLayer :vlax-true)) (*error* nil)) (*error* "Nothing selected"))) (vla-get-activedocument (vlax-get-acad-object)))) Edited November 29, 2011 by BlackBox Quote
ReMark Posted November 29, 2011 Posted November 29, 2011 Isn't changing an object's color from 'By Layer' to "whatever" color just encouraging bad CAD practices? How many of us have received a drawing from an outside source and found that an object's color did not coincide with the color of the layer that it was on? Frustrating to say the least. Quote
alanjt Posted November 29, 2011 Posted November 29, 2011 Isn't changing an object's color from 'By Layer' to "whatever" color just encouraging bad CAD practices? How many of us have received a drawing from an outside source and found that an object's color did not coincide with the color of the layer that it was on? Frustrating to say the least. Yes. .............. Quote
BlackBox Posted November 29, 2011 Posted November 29, 2011 That's a lot of code. It is... I only meant to provide VVA a "working" VLAX-FOR example using his own code. Besides, if you think that's bad, don't bother learning (advanced) .NET - Sample: Adding speech recognition to AutoCAD via Kinect (continued) ... The simpler stuff (i.e., getting, setting system variables, etc.) is a lot shorter by comparison, and still *more code* than LISP! LoL Poor ActiveX COM API. Isn't changing an object's color from 'By Layer' to "whatever" color just encouraging bad CAD practices? How many of us have received a drawing from an outside source and found that an object's color did not coincide with the color of the layer that it was on? Frustrating to say the least. Yes. .............. Yeah ... *kicks dirt* Quote
alanjt Posted November 29, 2011 Posted November 29, 2011 It is... I only meant to provide VVA a "working" VLAX-FOR example using his own code. Besides, if you think that's bad, don't bother learning (advanced) .NET Oh, I know other languages are much more labor intensive. I just meant all that work when entmod could accomplish it a lot easier. On the note of your stepping through the activeselectionset, I've actually abandoned using that method since I would randomly receive errors from routines that used that method. I know there's a slight time loss (I tested it myself long ago) with stepping through the selectionset with while/repeat and converting the ename to a vla-object, but I've stopped seeing the errors and the time loss is so minute you don't even notice. Quote
BlackBox Posted November 29, 2011 Posted November 29, 2011 Unfortunately, it appears that Autodesk is going to leave us behind so-to-speak, if we don't pick up .NET at some level. As it appears I'll be working with Civil 3D (at some point), and Microstation - .NET also suites a common thread for me personally. Even if I were fortunate to no longer need to work with Microstation, I'm still compelled to learn .NET for the simple purposes of gaining access to AECC* Objects that even Visual LISP fails (as we've discussed before). As for the vlax-for iteration errors, I've not personally had any issues (and I use this method a lot), but would be interested in understanding the cause. I typically have two "shell" iteration code snippets... One for VLA Objects (vlax-for), and one for eNames (while + ssname). In any event, thanks for the heads up - I'll keep a lookout for those errors. Cheers! 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.