cadman6735 Posted December 28, 2010 Posted December 28, 2010 I am looking for a shorter way to write the "not" part of my lisp below. I have 10 "not" statements in a row and for the life of me I can't seem to type the correct search term in Google to get the answer I am looking for. Keeping in the same logic of my macro how would one of you experiance programmers write the "not" part of my macro? Thanks for the help (defun C:test () (vl-load-com) (setq acadObject (vlax-get-acad-object) acadActiveDocument (vla-get-ActiveDocument acadObject) acadLayers (vla-get-Layers acadActiveDocument) ) (vlax-for Layer acadLayers (if (progn (not (eq (vla-get-PlotStyleName Layer) "As Drawn")) (not (eq (vla-get-PlotStyleName Layer) "10% Screen")) (not (eq (vla-get-PlotStyleName Layer) "20% Screen")) (not (eq (vla-get-PlotStyleName Layer) "30% Screen")) (not (eq (vla-get-PlotStyleName Layer) "40% Screen")) (not (eq (vla-get-PlotStyleName Layer) "50% Screen")) (not (eq (vla-get-PlotStyleName Layer) "60% Screen")) (not (eq (vla-get-PlotStyleName Layer) "70% Screen")) (not (eq (vla-get-PlotStyleName Layer) "80% Screen")) (not (eq (vla-get-PlotStyleName Layer) "90% Screen")) ) (vla-put-PlotStyleName Layer "As Drawn") ) ) (princ) ) Quote
Lee Mac Posted December 28, 2010 Posted December 28, 2010 Bear in mind how the progn function works - only the last not statement will be taken into account - the rest are redundant. In your code, you should replace progn with and to ensure all conditions are met, or better yet... This is how I might approach it: (defun c:test nil (vl-load-com) (vlax-for layer (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object)) ) (if (not (wcmatch (vla-get-PlotStyleName layer) "As Drawn,#0% Screen")) (vla-put-PlotStyleName layer "As Drawn") ) ) (princ) ) Quote
cadman6735 Posted December 28, 2010 Author Posted December 28, 2010 Thanks Lee I knew there was a way to turn my book into a sentance. I was putting spaces after each comma "As Drawn, 10% Screen, 20% Screen, " forcing everything to As Drawn, which led me to 10 "not" statements. Remove the spaces and it now works. Thanks for the (progn) tid bit, I was not 100% aware of that, I will keep this in mind The wild card function makes it even shorter. Question: I have seen it in my studies but what does the # symbol do? #0% Screen Thanks Quote
karl Posted December 28, 2010 Posted December 28, 2010 hi, i'd suggest using "cond" instead of "if" structure with the "nots". (cond ((eq (vla-get-PlotStyleName Layer) "As Drawn") (DO-SOMETHING)) ((eq (vla-get-PlotStyleName Layer) "10% Screen") (DO-SOMETHING-ELSE)) (ETCETERA) (T (DO-SOMETHING-IF-NONE-OF-ABOVE)) );end-of-conditional karl Quote
cadman6735 Posted December 28, 2010 Author Posted December 28, 2010 Thanks Karl It's great seeing different ways to do the same thing, it keeps the options open and I can see different ways to write code. Quote
Lee Mac Posted December 28, 2010 Posted December 28, 2010 Perhap the way to visualise the progn function is as a 'wrapper' to allow you to supply many expressions to a function taking a single argument - progn will merely evaluate the expressions supplied to it and hence the single progn expression can be fed to other functions. Some examples: IF (if <test expr> <do this> <else this> ) (if <test expr> (progn <do this> <and this> <and this> ) <else this> ) (if <test expr> <do this> (progn <else this> <and this> <and this> ) ) (if <test expr> (progn <do this> <and this> <and this> ) (progn <else this> <and this> <and this> ) ) (if (progn <do this> <and this> <test expr> ) <do this> <else this> ) WHILE: (while <test expr> <do this> <and this> <and this> ) (while (progn <do this> <and this> <test expr> ) <do this> <and this> <and this> ) Question: I have seen it in my studies but what does the # symbol do? #0% Screen Use the VLIDE Help, (see here and here), to check the documentation on the wcmatch function to see the full reference, the # matches any single numerical character. Quote
cadman6735 Posted December 29, 2010 Author Posted December 29, 2010 Lee I hope this is not a "dumb schmuk" question Your wildcard example works beautifully and Karls (cond) option works beautifully as well but for the life of me, I can not figure out how to use the (and) function. The help menu is giving me an example that I can not relate to what I am doing, I can't even find an example on Google or this forum can you help me with an example? Thanks Quote
Lee Mac Posted December 29, 2010 Posted December 29, 2010 Example: (if (and (setq pt1 (getpoint "\nPoint1: ")) (setq pt2 (getpoint "\nPoint2: ")) ) <do this> <else do this> ) Quote
cadman6735 Posted December 29, 2010 Author Posted December 29, 2010 Ok I am almost posative that is the way I am doing it. What is wrong with my code? (defun C:CleanPlot () (vl-load-com) (setq acadObject (vlax-get-acad-object) acadActiveDocument (vla-get-ActiveDocument acadObject) acadLayers (vla-get-Layers acadActiveDocument) ) (vlax-for Layer acadLayers (if (and (eq (vla-get-PlotStyleName Layer) "Normal") (eq (vla-get-PlotStyleName Layer) "Full Saturation") ) (vla-put-PlotStyleName Layer "As Drawn") ) ) (princ) ) Quote
Lee Mac Posted December 29, 2010 Posted December 29, 2010 How can something equal two things at once? Hint: Its either one OR the other. Quote
cadman6735 Posted December 29, 2010 Author Posted December 29, 2010 I would have never figured that out, I still have a long way to go. I got it working now. Thanks Quote
Lee Mac Posted December 30, 2010 Posted December 30, 2010 I would have never figured that out, I still have a long way to go. I find its easier to 'read it through', hence "if its either this OR that"; similarly "if its this AND that" etc, then just translate what you are saying into code expressions 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.