cletero Posted September 1, 2014 Share Posted September 1, 2014 Hi, I'm using the following code as part of a lisp which draws polylines. Basically, the polyline is drawn, it's checked to be clock wise or ccw and if necesary, its direction is changed before further processing with this code: ;To reverse the direction of the selected polyline (defun reverse_pline (mypoly / e_lst p_lst v_lst l_vtx x) (setq e_lst (entget (vlax-vla-object->ename mypoly))) (setq p_lst (vl-remove-if-not '(lambda (x) (member (car x) '(10 40 41 42))) e_lst) e_lst (vl-remove-if '(lambda (x) (member x p_lst)) e_lst) ) (while p_lst (setq v_lst (cons (list (car p_lst) (cadr p_lst) (caddr p_lst) (cadddr p_lst)) v_lst) p_lst (member (assoc 10 (cdr p_lst)) (cdr p_lst)) ) ) (setq l_vtx (last v_lst) l_vtx (subst (cons 40 (cdr (assoc 41 (car v_lst)))) (assoc 40 l_vtx) l_vtx) l_vtx (subst (cons 41 (cdr (assoc 40 (car v_lst)))) (assoc 41 l_vtx) l_vtx) l_vtx (subst (cons 42 (- (cdr (assoc 42 (car v_lst))))) (assoc 42 l_vtx) l_vtx) ) (setq v_lst (mapcar '(lambda (x y) (setq x (subst (cons 40 (cdr (assoc 41 y))) (assoc 40 x) x) x (subst (cons 41 (cdr (assoc 40 y))) (assoc 41 x) x) x (subst (cons 42 (- (cdr (assoc 42 y)))) (assoc 42 x) x) )) v_lst (cdr v_lst)) ) (if (= (logand 1 (cdr (assoc 70 e_lst))) 1) (setq v_lst (append (list l_vtx) v_lst)) (setq v_lst (append v_lst (list l_vtx))) ) (setq e_lst (append e_lst (apply 'append v_lst))) (setq test_1 (cdr (assoc -1 (entmod e_lst)))) (entupd (cdr (assoc -1 (entmod e_lst)))) (princ) ) My problem is, it works perfectly the first time I run the program, but the second time I run it, entmod returns nil, unless before running the program for a second time I use any command (example, draw a line). Not sure how entmod works, so any help will be appreciated. Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted September 1, 2014 Share Posted September 1, 2014 This line (at the end) is sufficient... Remove it and try again... (setq test_1 (cdr (assoc -1 (entmod e_lst)))) HTH, M.R. If not try to add this line at the end before (princ) (command "_.regen") Quote Link to comment Share on other sites More sharing options...
cletero Posted September 1, 2014 Author Share Posted September 1, 2014 Hi Marko, I tried both without success, I had added the (setq test_1 (cdr (assoc -1 (entmod e_lst)))) line just to see what was being returned by entmod, since it's the first time I'm using it But the routine was failing before that. Quote Link to comment Share on other sites More sharing options...
cletero Posted September 1, 2014 Author Share Posted September 1, 2014 I did some trimming until the "entmod" worked as it should and apparently, this line is to be blamed: (command "_.-LAYER" "_OFF" "*" "N" "") I use it between selecting the object(s) and doing the reverse polyline routine. Basically, I do this: - Select objects - Copy them to a new layer - Turn off all layers except new layer, I need this for the following step - If objects are not lwpolyline, create a lwpolyline from them using boundary command (So I need other layers turned off so their objects do not interfere with the boundary) - Reverse the polyline, do a bunch of stuff and then restore layer states. As I said before, if I draw a line between each call to my funtion, it works fine no matter what. Example: call function (works), call function (fails) BUT call function (works), draw line, call function (works). After adding the "regen" command line: If I return the layer states before reversing, entmod works fine even if I call my function two consecutive times. If shademode is not set to 2D wireframe, entmod fails the second time around. Hope this makes sence So I found a solution but would like to understand the behaviour for future reference. Quote Link to comment Share on other sites More sharing options...
cletero Posted September 1, 2014 Author Share Posted September 1, 2014 (edited) ok... sooo.... it works fine on new drawings but once again it's failing in my "test" drawing... aarggghhhh!!! Maybe this is way too much info, but never the less: I tracked the list being used by endmod, if I run my routine twice with the same object, I get this: FIRST TIME: ((-1 . ) (0 . "LWPOLYLINE") (330 . ) (5 . "5E765") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "1001") (100 . "AcDbPolyline") (90 . 4) (70 . 1) (43 . 0.0) (38 . 0.0) (39 . 0.0) (210 0.0 0.0 1.0) (10 102.0 -81.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 102.0 -48.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 123.0 -48.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 123.0 -81.0) (40 . 0.0) (41 . 0.0) (42 . 0.0)) SECOND TIME: ((-1 . ) (0 . "LWPOLYLINE") (330 . ) (5 . "5E775") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "1001") (100 . "AcDbPolyline") (90 . 4) (70 . 1) (43 . 0.0) (38 . 0.0) (39 . 0.0) (210 0.0 0.0 1.0) (10 102.0 -81.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 102.0 -48.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 123.0 -48.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 123.0 -81.0) (40 . 0.0) (41 . 0.0) (42 . 0.0)) The difference is in the "handle" (assoc 5) and the entity name, however, the same happens in a new drawing where it does work: FIRST TIME: ((-1 . ) (0 . "LWPOLYLINE") (330 . ) (5 . "2E") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "1001") (100 . "AcDbPolyline") (90 . 4) (70 . 1) (43 . 0.0) (38 . 0.0) (39 . 0.0) (210 0.0 0.0 1.0) (10 79.0785 148.356) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 79.0785 303.162) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 170.341 303.162) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 170.341 148.356) (40 . 0.0) (41 . 0.0) (42 . 0.0)) SECOND TIME: ((-1 . ) (0 . "LWPOLYLINE") (330 . ) (5 . "74") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "1001") (100 . "AcDbPolyline") (90 . 4) (70 . 1) (43 . 0.0) (38 . 0.0) (39 . 0.0) (210 0.0 0.0 1.0) (10 79.0785 148.356) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 79.0785 303.162) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 170.341 303.162) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 170.341 148.356) (40 . 0.0) (41 . 0.0) (42 . 0.0)) Did a couple more tests and apparently, when it doesn't work is because the object (polyline) is not "write enabled" (vlax-write-enabled-p returns nil), so I added a vla-update object line before the reverse routine and seems to be working even on shaded mode.... lets hope it stays so!! Any thoughts?? Edited September 1, 2014 by cletero 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.