geocad Posted November 11, 2009 Posted November 11, 2009 Hello all, I have a drawing which has many circle objects at different depths and with different color coding in one layer. Is there a LISP which will automatically select all the objects in a defined depth range (such as 0 to -1, -1 to -2, etc) and put them into a layer named for that depth range? A secondary objective would be able to sort by color, but depth is the most important. If not how difficult would it be for someone such as myself, with no code writing experience to write that routine? Thanks. Josh Quote
alanjt Posted November 11, 2009 Posted November 11, 2009 Select objects. Iterate through selection set, if object Z value matches certain criteria, put on specific layer. Cond would be the easiest. Have a list of what goes where? Quote
fixo Posted November 11, 2009 Posted November 11, 2009 Hello all, I have a drawing which has many circle objects at different depths and with different color coding in one layer. Is there a LISP which will automatically select all the objects in a defined depth range (such as 0 to -1, -1 to -2, etc) and put them into a layer named for that depth range? A secondary objective would be able to sort by color, but depth is the most important. If not how difficult would it be for someone such as myself, with no code writing experience to write that routine? Thanks. Josh (setq circleselection (ssget "X" (list (cons 0 "CIRCLE") '(-4 . "< AND") '(-4 . "*,*,>") (cons 10 (list 0. 0. -0.99999999) '(-4 . "*,*,<") (cons 10 (list 0. 0. -2.00000001) '(-4 . "AND >") ))) this filter will be select all circles with depth range from -1 to -2 Hope this make a sense ~'J'~ Quote
alanjt Posted November 11, 2009 Posted November 11, 2009 Maybe something like this: (defun c:Test (/ #SS #Layers #Z) (vl-load-com) (cond ((setq #SS (ssget "_:L")) (or *AcadDoc* (setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object)))) (setq #Layers (vla-get-layers *AcadDoc*)) (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex #SS))) (if (or (setq #Z (cdr (assoc 38 (entget x)))) (setq #Z (last (assoc 10 (entget x)))) ) ;_ or (cond ;; <= 0 ((<= #Z 0.) (or (tblsearch "layer" "A") (vla-put-color (vla-add #Layers "A") 1) ) ;_ or (vla-put-layer (vlax-ename->vla-object x) "A") ) ;; 0 < x < 5 ((and (> #Z 0.) (< #Z 5.)) (or (tblsearch "layer" "B") (vla-put-color (vla-add #Layers "B") 2) ) ;_ or (vla-put-layer (vlax-ename->vla-object x) "B") ) ) ;_ cond ) ;_ if ) ;_ foreach ) ) ;_ cond (princ) ) ;_ defun Quote
geocad Posted November 11, 2009 Author Posted November 11, 2009 Select objects. Iterate through selection set, if object Z value matches certain criteria, put on specific layer. Cond would be the easiest. Have a list of what goes where? I am not sure what you mean by "Iterate through selection set, " Are you referring to Quick Select each depth range? If so, I have done this, but I am looking for an automated way of doing this. If I misunderstood your response I apologize. I appreciate the help. Quote
geocad Posted November 11, 2009 Author Posted November 11, 2009 (setq circleselection (ssget "X" (list (cons 0 "CIRCLE") '(-4 . "< AND") '(-4 . "*,*,>") (cons 10 (list 0. 0. -0.99999999) '(-4 . "*,*,<") (cons 10 (list 0. 0. -2.00000001) '(-4 . "AND >") ))) this filter will be select all circles with depth range from -1 to -2 Hope this make a sense ~'J'~ I am showing my ignorance here as I could not get this lisp to run. Did I miss something? Quote
alanjt Posted November 11, 2009 Posted November 11, 2009 I am not sure what you mean by "Iterate through selection set, " Are you referring to Quick Select each depth range? If so, I have done this, but I am looking for an automated way of doing this. If I misunderstood your response I apologize. I appreciate the help. Look at my #4 post. Quote
geocad Posted November 11, 2009 Author Posted November 11, 2009 Maybe something like this: (defun c:Test (/ #SS #Layers #Z) (vl-load-com) (cond ((setq #SS (ssget "_:L")) (or *AcadDoc* (setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object)))) (setq #Layers (vla-get-layers *AcadDoc*)) (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex #SS))) (if (or (setq #Z (cdr (assoc 38 (entget x)))) (setq #Z (last (assoc 10 (entget x)))) ) ;_ or (cond ;; <= 0 ((<= #Z 0.) (or (tblsearch "layer" "A") (vla-put-color (vla-add #Layers "A") 1) ) ;_ or (vla-put-layer (vlax-ename->vla-object x) "A") ) ;; 0 < x < 5 ((and (> #Z 0.) (< #Z 5.)) (or (tblsearch "layer" "B") (vla-put-color (vla-add #Layers "B") 2) ) ;_ or (vla-put-layer (vlax-ename->vla-object x) "B") ) ) ;_ cond ) ;_ if ) ;_ foreach ) ) ;_ cond (princ) ) ;_ defun I successfully ran this lisp, but it put all of the objects into the layer "A". All of the objects have Z positions less than zero. In other words they are all negative. I tried to alter the lisp, but was unsuccessful. What should I change to have it select the objects from -1 to -1.99999999, for example? I think if I could figure out that part of the code I could copy and paste to reiterate for the other depth ranges. I think this is on the correct track. Thanks again. Your help is really appreciated. Quote
alanjt Posted November 11, 2009 Posted November 11, 2009 I successfully ran this lisp, but it put all of the objects into the layer "A". All of the objects have Z positions less than zero. In other words they are all negative. I tried to alter the lisp, but was unsuccessful. What should I change to have it select the objects from -1 to -1.99999999, for example? I think if I could figure out that part of the code I could copy and paste to reiterate for the other depth ranges. I think this is on the correct track. Thanks again. Your help is really appreciated. Right, I had to make it as generic as possible, since you didn't give the amounts. Look at this portion: ;; 0 < x < 5 [color=Red]((and (> #Z 0.) (< #Z 5.)) ; checks if greater than 0 and less than 5[/color] (or (tblsearch "layer" "B") (vla-put-color (vla-add #Layers "B") 2) ) ;_ or (vla-put-layer (vlax-ename->vla-object x) "B") ) Quote
geocad Posted November 11, 2009 Author Posted November 11, 2009 Right, I had to make it as generic as possible, since you didn't give the amounts. Look at this portion: ;; 0 < x < 5 [color=Red]((and (> #Z 0.) (< #Z 5.)) ; checks if greater than 0 and less than 5[/color] (or (tblsearch "layer" "B") (vla-put-color (vla-add #Layers "B") 2) ) ;_ or (vla-put-layer (vlax-ename->vla-object x) "B") ) I believe that works. Thanks for your time. I will use this to try and learn the commands used in lisp. Thanks again. Quote
alanjt Posted November 11, 2009 Posted November 11, 2009 I believe that works. Thanks for your time. I will use this to try and learn the commands used in lisp. Thanks again. It did when I tested it earlier. If you need any more help, don't hesitate to ask. Quote
fixo Posted November 11, 2009 Posted November 11, 2009 I am showing my ignorance here as I could not get this lisp to run. Did I miss something? I meant something like this one (defun C:demo (/) (setq range_list (list '(0 -1) '(-1 -2) '(-2 -3) '(-3 -4)) ;etc precision 0.00000001) (foreach item range_list (setq circleselection (ssget "_X" (list '(0 . "CIRCLE") '(-4 . "<AND") '(-4 . "*,*,>") (cons 10 (list 0. 0. (- (cadr item) precision))) '(-4 . "*,*,<") (cons 10 (list 0. 0. (+ (car item) precision))) '(-4 . "AND>") ))) (if circleselection (alert (strcat "Selected: " (itoa (sslength circleselection)) " circles\n" "at range from " (rtos (car item)) " to " (rtos (cadr item))))) ) (princ) ) ~'J'~ 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.