ahyin Posted August 4, 2010 Share Posted August 4, 2010 (edited) Dear all, I'm writing a lisp,anybody can help me ? I have many layers for user to select by dcl dialog box, after selected the items (may be more than one) by user,I will turn on this layer and check have circle objects in this layer or not. Because of more than 50 items.If I use if then else to check each flag will make my lisp program become very long. Any other good method to do that ? (if (= item1 1) (progn (setq acadDocument (vla-get-activedocument (vlax-get-acad-object))) (setq theLayers (vla-get-layers acadDocument)) (vlax-for item theLayers (vlax-put-property item "LayerON" ':vlax-false)) (command "-layer" "On" (vlax-get-property item1-layer 'Name) "") (setq sset (ssget "_a" (LIST '(0 . "CIRCLE") (8 . item1-layer) (cons 410 (getvar "CTAB"))))) ) ) (if (= item2 1) (progn (setq acadDocument (vla-get-activedocument (vlax-get-acad-object))) (setq theLayers (vla-get-layers acadDocument)) (vlax-for item theLayers (vlax-put-property item "LayerON" ':vlax-false)) (command "-layer" "On" (vlax-get-property item2-layer 'Name) "") (setq sset (ssget "_a" (LIST '(0 . "CIRCLE") (8 . item2-layer) (cons 410 (getvar "CTAB"))))) ) ) . . . . . Edited August 4, 2010 by Tiger added code-tags Quote Link to comment Share on other sites More sharing options...
MSasu Posted August 4, 2010 Share Posted August 4, 2010 Take a look to FOREACH function - this means that you will have to store those layer names in a list. (foreach Item '(1 2 3 4 5) (print Item) ) Regards, Quote Link to comment Share on other sites More sharing options...
ahyin Posted August 6, 2010 Author Share Posted August 6, 2010 thanks ! I will try use to this function to complete my lisp Take a look to FOREACH function - this means that you will have to store those layer names in a list. (foreach Item '(1 2 3 4 5) (print Item) ) Regards, Quote Link to comment Share on other sites More sharing options...
MSasu Posted August 6, 2010 Share Posted August 6, 2010 No problem! Also, to deal with repetitive codes may be a good idea to write a function with parameters for that part and call it instead of having the same piece of code in more than one place. This will ensure a more compact code and help you to maintain it – that it, make changes in only one places. In this case your code excerpt will become: (defun [color=Blue]CirclesInLayer[/color]( [color=DarkGreen]theLayer[/color] ) (setq acadDocument (vla-get-activedocument (vlax-get-acad-object))) (setq theLayers (vla-get-layers acadDocument)) (vlax-for item theLayers (vlax-put-property item "LayerON" ':vlax-false)) (command "-layer" "On" (vlax-get-property theLayer 'Name) "") (setq sset (ssget "_a" (LIST '(0 . "CIRCLE") (8 . theLayer) (cons 410 (getvar "CTAB"))))) ) ) (if (= item1 1) ([color=Blue]CirclesInLayer[/color] [color=DarkGreen]item1-layer[/color]) ) (if (= item2 1) ([color=Blue]CirclesInLayer[/color] [color=DarkGreen]item2-layer[/color]) ) Regards, Quote Link to comment Share on other sites More sharing options...
ahyin Posted August 10, 2010 Author Share Posted August 10, 2010 Thank you very much, this would be really great ! No problem! Also, to deal with repetitive codes may be a good idea to write a function with parameters for that part and call it instead of having the same piece of code in more than one place. This will ensure a more compact code and help you to maintain it – that it, make changes in only one places. In this case your code excerpt will become: (defun [color=Blue]CirclesInLayer[/color]( [color=DarkGreen]theLayer[/color] ) (setq acadDocument (vla-get-activedocument (vlax-get-acad-object))) (setq theLayers (vla-get-layers acadDocument)) (vlax-for item theLayers (vlax-put-property item "LayerON" ':vlax-false)) (command "-layer" "On" (vlax-get-property theLayer 'Name) "") (setq sset (ssget "_a" (LIST '(0 . "CIRCLE") (8 . theLayer) (cons 410 (getvar "CTAB"))))) ) ) (if (= item1 1) ([color=Blue]CirclesInLayer[/color] [color=DarkGreen]item1-layer[/color]) ) (if (= item2 1) ([color=Blue]CirclesInLayer[/color] [color=DarkGreen]item2-layer[/color]) ) Regards, Quote Link to comment Share on other sites More sharing options...
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.