Small Fish Posted May 17, 2009 Posted May 17, 2009 I have rows of circles and they have the same y value centrepoint on each row. How can I process the rows starting from the bottom up? For example in my selection set I have 3 rows of the circles bottom row has 2 7.5 radius circles then 2 16 radius circles then 2 20 radius circles however the list "ListRowDia" in my returns: ((2 20.0 20.0) (1 7.5 7.5 7.5) (3 16.0 16.0)) but I want : ((1 7.5 7.5 7.5) (2 16.0 16.0)(3 20.0 20.0)) This is the code that needs adjusting: thanks for your help (defun c:RowA3 (/ jsx test dxf_ent jsx_ename new_xx total areaobj cLst big_Area rad ListRowDia) (vl-load-com) (if (setq jsx (ssget "_X" '((0 . "CIRCLE")))) (progn (setq test 1) (while (not (zerop (sslength jsx))) (setq dxf_ent (entget (setq jsx_ename (ssname jsx 0))) new_xx (ssget "_X" (list '(0 . "CIRCLE") '(-4 . "*,=,*") (assoc 10 dxf_ent))) total 0.0 big_Area nil) (foreach ent (setq new_xxlst (mapcar 'cadr (ssnamex new_xx))) (setq areaobj (vla-get-area (vlax-ename->vla-object ent)) total (+ total areaobj))) (setq cLst (vl-sort (mapcar '(lambda (x) (cdr (assoc 10 (entget x)))) new_xxlst) '(lambda (x1 x2) ( (setq Rad (vl-sort (mapcar '(lambda (x) (cdr (assoc 40 (entget x)))) new_xxlst) '(lambda (x1 x2) (> x1 x2)))) (setq ListRowDia(append (list (cons test Rad )) ListRowDia)) (mapcar '(lambda (x) (ssdel x jsx)) new_xxlst) (princ (strcat "\nRow " (itoa test) "; MinXCtr: " (vl-princ-to-string (car cLst)) " MaxRad = " (vl-princ-to-string (car rad)) " => " " Total = "(rtos total) "\n-----------------------------------------")) (ssdel jsx_ename jsx) (setq test (1+ test))) (textscr))) (princ "\n") (princ ListRowDia) (princ)) Quote
Lee Mac Posted May 17, 2009 Posted May 17, 2009 Give this a shot (defun c:RowA3 (/ jsx test dxf_ent jsx_ename new_xx total areaobj cLst big_Area rad ListRowDia) (vl-load-com) (if (setq jsx (ssget "_X" '((0 . "CIRCLE")))) (progn (setq test 1) (while (not (zerop (sslength jsx))) (setq dxf_ent (entget (setq jsx_ename (ssname jsx 0))) new_xx (ssget "_X" (list '(0 . "CIRCLE") '(-4 . "*,=,*") (assoc 10 dxf_ent))) total 0.0 big_Area nil) (foreach ent (setq new_xxlst (vl-sort (mapcar 'cadr (ssnamex new_xx)) '(lambda (y1 y2) (< (caddr (assoc 10 (entget y1))) (caddr (assoc 10 (entget y2))))))) (setq areaobj (vla-get-area (vlax-ename->vla-object ent)) total (+ total areaobj))) (setq cLst (vl-sort (mapcar '(lambda (x) (cdr (assoc 10 (entget x)))) new_xxlst) '(lambda (x1 x2) (< (car x1) (car x2))))) (setq Rad (vl-sort (mapcar '(lambda (x) (cdr (assoc 40 (entget x)))) new_xxlst) '(lambda (x1 x2) (> x1 x2)))) (setq ListRowDia (append (list (cons test Rad)) ListRowDia)) (mapcar '(lambda (x) (ssdel x jsx)) new_xxlst) (princ (strcat "\nRow " (itoa test) "; MinXCtr: " (vl-princ-to-string (car cLst)) " MaxRad = " (vl-princ-to-string (car rad)) " => " " Total = " (rtos total) "\n-----------------------------------------")) (ssdel jsx_ename jsx) (setq test (1+ test))) (textscr))) (princ "\n") (princ ListRowDia) (princ)) Quote
Lee Mac Posted May 17, 2009 Posted May 17, 2009 Just a tip Small Fish, when posting your code, enclose it in [/ code] tags (without the space) - then the indents in the code are retained. Quote
Small Fish Posted May 17, 2009 Author Posted May 17, 2009 Hi Lee Mac yes that works sweet. thanks..... However I can't figure out how to incorporate the new piece of code that you wrote into previous code also written by you or Wizman. I have tried to mold them together but it just hooks up on these lines. Any ideas how to add : (vl-remove-if 'listp (mapcar 'cadr(ssnamex subSs)))) ? thanks (vl-sort (mapcar 'cadr (ssnamex new_xx)) '(lambda (y1 y2) ( (caddr (assoc 10 (entget y2))))))) into [quote](setq subSs_lst (vl-remove-if 'listp (mapcar 'cadr (ssnamex subSs))))[/quote] this shows more the code I have already, that I want modified (if (setq subSs (ssget "_c" pt1 pt2 (list (cons 0 "CIRCLE") (cons -4 (if flag ">=,=,*" "<=,=,*")) (cons 10 (append (list (apply (if flag 'max 'min) (mapcar 'car lDat))) (cddr (assoc 10 (entget tCirc)))))))) (progn (setq total 0.0) (foreach ent (setq subSs_lst;This is the piece that needs modifying (vl-remove-if 'listp (mapcar 'cadr (ssnamex subSs)))); (setq total (+ total (vla-get-Area (vlax-ename->vla-object ent))))) (setq cLst(car (vl-sort (mapcar '(lambda (x) (cdr (assoc 10 (entget x)))) subSs_lst) '(lambda (x1 x2) (< (car x1) (car x2))))) Rad (car(vl-sort (mapcar '(lambda (x) (cdr (assoc 40 (entget x)))) subSs_lst) '(lambda (r1 r2) (> r1 r2))))) etc etc etc ] Quote
Lee Mac Posted May 17, 2009 Posted May 17, 2009 Like this maybe.... (if (setq subSs (ssget "_c" pt1 pt2 (list (cons 0 "CIRCLE") (cons -4 (if flag ">=,=,*" "<=,=,*")) (cons 10 (append (list (apply (if flag 'max 'min) (mapcar 'car lDat))) (cddr (assoc 10 (entget tCirc)))))))) (progn (setq total 0.0) (foreach ent (setq subSs_lst (vl-sort (vl-remove-if 'listp (mapcar 'cadr (ssnamex subSs))) '(lambda (y1 y2) (< (caddr (assoc 10 (entget y1))) (caddr (assoc 10 (entget y2))))))) (setq total (+ total (vla-get-Area (vlax-ename->vla-object ent))))) (setq cLst(car (vl-sort (mapcar '(lambda (x) (cdr (assoc 10 (entget x)))) subSs_lst) '(lambda (x1 x2) (< (car x1) (car x2))))) Rad (car(vl-sort (mapcar '(lambda (x) (cdr (assoc 40 (entget x)))) subSs_lst) '(lambda (r1 r2) (> r1 r2))))) etc etc etc Quote
Small Fish Posted May 17, 2009 Author Posted May 17, 2009 Thanks Lee mac - you're a genius! ....how many beers do I owe you and Wizman now? Small Fish Quote
Lee Mac Posted May 17, 2009 Posted May 17, 2009 Thanks Lee mac - you're a genius! ....how many beers do I owe you and Wizman now?Small Fish More than you can afford... Btw, I notice that you are using the [/ quote] tags along with the [/ code] tags - this isn't necessary, just the [code] [/ code] tags will do Quote
Small Fish Posted May 19, 2009 Author Posted May 19, 2009 Lee mac - sorry I spoke too soon. On further testing it does sort but only partially. For example if I have 4 rows of circles. The bottom row of 2 circles both have radius of 16 then 2 circles of radius 15, 2 circles of radius 10 and the top row 2 circles of of radius 6. So the list should return : ((4 6.0 6.0) (3 10.0 10.0) (2 15.0 15.0) (1 16.0 6.0)) however it returns: ((4 10.0 10.0) (3 6.0 6.0) (2 16.0 16.0) (1 15.0 15.0)) I have been trying to isolate the cause for a few hours now. Perhaps it is the filter on ssget or maybe the sort on "rad" but it appears to be okay. I thought it also could be not declaring variables as local-but this to looks okay. I am stumped now - any ideas? thanks Quote
Lee Mac Posted May 19, 2009 Posted May 19, 2009 I would have to see the whole code tbh - are you using the sorted this when compiling the dotted pairs? (could be something that simple).. Quote
Small Fish Posted May 19, 2009 Author Posted May 19, 2009 Did you mean I need to sort my list? I can not see how to sort the pairs into the correct order as the row numbers don't match the radius sizes. thanks... This is the code I have-which is the code(simple version) that you posted earlier (defun c:RowA3 (/ jsx test dxf_ent jsx_ename new_xx total areaobj cLst big_Area rad ListRowDia) (vl-load-com) (if (setq jsx (ssget "_X" '((0 . "CIRCLE")))) (progn (setq test 1) (while (not (zerop (sslength jsx))) (setq dxf_ent (entget (setq jsx_ename (ssname jsx 0))) new_xx (ssget "_X" (list '(0 . "CIRCLE") '(-4 . "*,=,*") (assoc 10 dxf_ent))) total 0.0 big_Area nil) (foreach ent (setq new_xxlst (vl-sort (mapcar 'cadr (ssnamex new_xx)) '(lambda (y1 y2) (< (caddr (assoc 10 (entget y1))) (caddr (assoc 10 (entget y2))))))) (setq areaobj (vla-get-area (vlax-ename->vla-object ent)) total (+ total areaobj))) (setq cLst (vl-sort (mapcar '(lambda (x) (cdr (assoc 10 (entget x)))) new_xxlst) '(lambda (x1 x2) (< (car x1) (car x2))))) (setq Rad (vl-sort (mapcar '(lambda (x) (cdr (assoc 40 (entget x)))) new_xxlst) '(lambda (x1 x2) (> x1 x2)))) (setq ListRowDia (append (list (cons test Rad)) ListRowDia)) (mapcar '(lambda (x) (ssdel x jsx)) new_xxlst) ;;; (princ (strcat "\nRow " ;;; (itoa test) ;;; "; MinXCtr: " ;;; (vl-princ-to-string (car cLst)) ;;; " MaxRad = " ;;; (vl-princ-to-string (car rad)) ;;; " => " ;;; " Total = " ;;; (rtos total) ;;; "\n-----------------------------------------")) (ssdel jsx_ename jsx) (setq test (1+ test))) (textscr))) (princ "\n") (princ ListRowDia) (princ)) Quote
Lee Mac Posted May 20, 2009 Posted May 20, 2009 Its a bit complicated, but maybe this is what you are trying to achieve? (defun c:RowA3 (/ jsx test dxf_ent jsx_ename new_xx total areaobj cLst big_Area rad ListRowDia FinalList) (vl-load-com) (if (setq jsx (ssget "_X" '((0 . "CIRCLE")))) (progn (while (not (zerop (sslength jsx))) (setq dxf_ent (entget (setq jsx_ename (ssname jsx 0))) new_xx (ssget "_X" (list '(0 . "CIRCLE") '(-4 . "*,=,*") (assoc 10 dxf_ent))) total 0.0 big_Area nil) (foreach ent (setq new_xxlst (mapcar 'cadr (ssnamex new_xx))) (setq areaobj (vla-get-area (vlax-ename->vla-object ent)) total (+ total areaobj))) (setq cLst (vl-sort (mapcar '(lambda (x) (cdr (assoc 10 (entget x)))) new_xxlst) '(lambda (x1 x2) (< (car x1) (car x2))))) (setq Rad (vl-sort (mapcar '(lambda (x) (cdr (assoc 40 (entget x)))) new_xxlst) '(lambda (x1 x2) (> x1 x2)))) (setq ListRowDia (cons (append (list (caddr (assoc 10 (entget (car new_xxlst))))) Rad) ListRowDia)) (mapcar '(lambda (x) (ssdel x jsx)) new_xxlst) ;;; (princ (strcat "\nRow " ;;; (itoa test) ;;; "; MinXCtr: " ;;; (vl-princ-to-string (car cLst)) ;;; " MaxRad = " ;;; (vl-princ-to-string (car rad)) ;;; " => " ;;; " Total = " ;;; (rtos total) ;;; "\n-----------------------------------------")) (ssdel jsx_ename jsx)) (setq test 1) (foreach x (mapcar 'cdr (vl-sort ListRowDia '(lambda (x1 x2) (< (car x1) (car x2))))) (setq FinalList (cons (list test x) FinalList) test (1+ test))) (princ (vl-princ-to-string FinalList)) (textscr))) (princ)) Quote
Small Fish Posted May 23, 2009 Author Posted May 23, 2009 Sorry about not replying sooner - our office caught fire overnight about 5 days ago. We are now in a temporary office. Now I have a chance to check it out. Yes that's what I am trying to achieve - its getting deep for me to understand. I am struggling adapt your changes to my code. I think I have found all your changes but I am not sure if I need to change the filter? I have attempted to try and copy your filter onto my code but it does not like it. Should the filter be changed? It gets stuck on the line: (setq ListRowDia (cons (append (list (caddr (assoc 10 (entget (car new_xxlst))))) Rad) ListRowDia)) I am almost there after this problem is fixed. Thanks Lee mac for you patience Attached is my code Small Fish RowareasX.LSP Quote
Small Fish Posted May 29, 2009 Author Posted May 29, 2009 Okay of have worked it out...after nearly 3 weeks!. I was making something a lot more complicated than need be! By trying to mould your selection set code with my selection set. All I needed to do was just a a separate selection set, so that it makes its own list. Now my project is almost finished. Thanks once again Lee Mac. cheers Small Fish Quote
Lee Mac Posted May 29, 2009 Posted May 29, 2009 Okay of have worked it out...after nearly 3 weeks!. I was making something a lot more complicated than need be! By trying to mould your selection set code with my selection set. All I needed to do was just a a separate selection set, so that it makes its own list. Now my project is almost finished. Thanks once again Lee Mac. cheers Small Fish I'm glad you got it sorted in the end - I haven't had the time to be looking at much recently, what with the exams going on here, but its great that you worked it out. Cheers, Lee 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.