sadhu Posted March 28, 2013 Share Posted March 28, 2013 I need to make a list of blocks present in the drawing that are in front of reference block (front-list) and a second list of blocks that are behind (back-list). The front-list needs to be ordered left-to-right (clockwise) respect to the reference block while the back-list has to be ordered right-to-left(anticlockwise) . The reference block is a rectangle with an arrow pointing towards the front face. When the arrow (face) points down its rotation angle (dxf 50) is zero. I thought of comparing the rotation angle (dxf 50) of the reference block and the other blocks (insertion point - dxf 10) to get the front-list and back-list but I'm missing some fundamental mathematics/geometry and lisp comands. All help , thoughts and ideas to investigate is appreciated. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted March 28, 2013 Share Posted March 28, 2013 Post a image not sure about "in front" Quote Link to comment Share on other sites More sharing options...
sadhu Posted March 29, 2013 Author Share Posted March 29, 2013 This is how I'm proceeding. See attached file too. (defun C: test(/) (setq blklst (ssget "X" (list '(0 . "INSERT")))) (setq numblk (sslength blklst) blk_cnt 0) (while (< blk_cnt numblk) (setq en (ssname blklst blk_cnt)) (setq enlist (entget en)) (cond ((and (= (cdr (assoc 0 enlist)) "INSERT")(= (cdr (assoc 2 enlist)) "ITEMS")) "(get ITEMS angle [item_angle]) (compare with REF_BLK angle [ref_blk_angle]) [( if ref_blk_angle + 270° > Item_angle > ref_blk_angle + 90°) then add to back_list] [( if ref_blk_angle + 90° > Item_angle > ref_blk_angle - 90°) then add to front_list] " )) (setq blk_cnt (+ 1 blk_cnt)) )) TEST.dwg Quote Link to comment Share on other sites More sharing options...
David Bethel Posted March 29, 2013 Share Posted March 29, 2013 This could be a starting point: [b][color=BLACK]([/color][/b]defun c:fblst [b][color=FUCHSIA]([/color][/b]/ ss rn rd rp sa ea ia i en ed ip an[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]not rn[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]princ [color=#2f4f4f]"\nSelect Reference INSERT ..."[/color][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget '[b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]0 . [color=#2f4f4f]"INSERT"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]if [b][color=MAROON]([/color][/b]= [b][color=GREEN]([/color][/b]sslength ss[b][color=GREEN])[/color][/b] 1[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq rn [b][color=GREEN]([/color][/b]ssname ss 0[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq rd [b][color=NAVY]([/color][/b]entget rn[b][color=NAVY])[/color][/b] rp [b][color=NAVY]([/color][/b]cdr [b][color=MAROON]([/color][/b]assoc 10 rd[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] sa [b][color=NAVY]([/color][/b]cdr [b][color=MAROON]([/color][/b]assoc 50 rd[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] ea [b][color=NAVY]([/color][/b]+ sa pi[b][color=NAVY])[/color][/b] ia [b][color=NAVY]([/color][/b]if [b][color=MAROON]([/color][/b]> sa ea[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]+ [b][color=GREEN]([/color][/b]- [b][color=BLUE]([/color][/b]* 2 pi[b][color=BLUE])[/color][/b] sa[b][color=GREEN])[/color][/b] ea[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]- ea sa[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq rl [b][color=NAVY]([/color][/b]ssadd[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq fl [b][color=NAVY]([/color][/b]ssadd[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget [color=#2f4f4f]"X"[/color] '[b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]0 . [color=#2f4f4f]"INSERT"[/color][b][color=BLUE])[/color][/b][b][color=BLUE]([/color][/b]2 . [color=#2f4f4f]"ITEMS"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq i 0[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss i[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq i [b][color=GREEN]([/color][/b]1+ i[b][color=GREEN])[/color][/b] ed [b][color=GREEN]([/color][/b]entget en[b][color=GREEN])[/color][/b] ip [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 10 ed[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] an [b][color=GREEN]([/color][/b]angle rp ip[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]if [b][color=GREEN]([/color][/b]> sa an[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setq an [b][color=BLUE]([/color][/b]+ an pi pi[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]if [b][color=GREEN]([/color][/b]< sa an [b][color=BLUE]([/color][/b]+ sa ia[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]ssadd en rl[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]ssadd en fl[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] The PICKSET rl contains the entities that are to the 'rear', fl to the 'front' -David Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 29, 2013 Share Posted March 29, 2013 Another quick example, very similar to David's method: (defun c:orderblocks ( / 2pi ang blk bot ent inc ins rot sel top ) (if (and (princ "\nSelect Reference Block: ") (setq blk (ssget "_+.:E:S" '((0 . "INSERT")))) (setq sel (ssget "_X" '((0 . "INSERT") (2 . "ITEMS")))) ) (progn (setq blk (entget (ssname blk 0)) ins (cdr (assoc 10 blk)) rot (cdr (assoc 50 blk)) 2pi (+ pi pi) ) (repeat (setq inc (sslength sel)) (setq ent (ssname sel (setq inc (1- inc))) ang (rem (+ 2pi (- (angle ins (cdr (assoc 10 (entget ent)))) rot)) 2pi) ) (if (< 0 ang pi) (setq bot (cons (cons ang ent) bot)) (setq top (cons (cons ang ent) top)) ) ) (setq bot (vl-sort bot '(lambda ( a b ) (< (car a) (car b)))) top (vl-sort top '(lambda ( a b ) (> (car a) (car b)))) ) [color=green](getstring "\n-- 'Top' blocks --\n<Next>") (while top (redraw (cdar top) 3) (getstring "\n<Next>") (redraw (cdar top) 4) (setq top (cdr top)) ) (getstring "\n-- 'Bottom' blocks --\n<Next>") (while bot (redraw (cdar bot) 3) (getstring "\n<Next>") (redraw (cdar bot) 4) (setq bot (cdr bot)) )[/color] ) ) (princ) ) The highlighted section is purely to display the result. Quote Link to comment Share on other sites More sharing options...
sadhu Posted March 29, 2013 Author Share Posted March 29, 2013 Thank you David, thank you Lee. Just what I needed. You guys are real good. Lee, your code does the ordering too and the graphic effect is helpful. Thanks again. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 30, 2013 Share Posted March 30, 2013 You're very welcome sadhu 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.