careca Posted August 30, 2012 Posted August 30, 2012 Hi all, this might be one of my first lisp scripts....and I am kind of stuck. What I want to create is an app that automatizes the process of creating a boundary, making an internal offset, fillet the created offset, and finally delete the original boundary. All should work while picking points. As I found out that I have to explode the offset element first, to make all segments into polylines for proper filleting (otherwise arcs etc don't work), that's where I got stuck. If somebody had any helpful hints for me, this would be highly appreciated. thnx. careca Here's the code of how far I got: (defun c:xfillet (/ pt) ; while picking point ----------------------------- (while (setq pt (getpoint "\nPick internal point: ")) (command "_.-boundary" "_a" "_i" "_n" "" "" "_non" pt "") ; store original boundary object (setq original_boundary (entlast)) ; make offset (command "_.offset" 10 (entlast) "_non" pt "") ; explode offset (command "_.explode" (entlast)) ; load selection set (setq ss (ssget "_P")) ;counter (setq x 1) ;loop for all elements ------------------- (repeat (sslength ss) (setq pa (getvar "peditaccept")) ; convert all segments into polylines -> so fillet works on all elements (setvar "peditaccept" 1) (command "pedit" ss nil) (setvar "peditaccept" pa) ; copy element onto layer 0 (command "_.chprop" (entlast) "" "LA" "0" "") ; change color of element (included just for texting) (command "change" (entlast) "" "prop" "color" x "") ; ++++++++++++++++++++++++++++++++ ; ++++++++++++++++++++++++++++++++ ; what I want to accomplish ; store first element if x = 1 then store element in el1 ; loop though elements, make fillets bit by bit if x >= 2 make fillet with el1 store new element as el1 ; ++++++++++++++++++++++++++++++++ ; ++++++++++++++++++++++++++++++++ (setvar "peditaccept" pa) ; counter up (setq x (+ x 1)) ; _end repeat ) ; delete original boundary (command "_.erase" original_boundary "") ) ; end while ;(princ) ) ; end Quote
Dadgad Posted August 30, 2012 Posted August 30, 2012 Hello careca, welcome to the forum. If you set your PEDITACCEPT system variable setting to 1, at your commandline, then you will be able to fillet the offset entity by using the POLYLINE option in the FILLET commandline prompts. I hope that helps you. Quote
careca Posted August 30, 2012 Author Posted August 30, 2012 Hello careca, welcome to the forum. If you set your PEDITACCEPT system variable setting to 1, at your commandline, then you will be able to fillet the offset entity by using the POLYLINE option in the FILLET commandline prompts. I hope that helps you. Hi Dadgad, thanks for your reply. I actually tried this, but it seems not to be working. The arc sections will be spared out when trying to do all at once via polyline. That's why I thought I loop though the selection set of elements... Martin Quote
Dadgad Posted August 30, 2012 Posted August 30, 2012 You could create your arcs using the POLYLINE command. Specify the starting point, then A> and any arcs created in this way will be POLYLINES. Quote
careca Posted August 30, 2012 Author Posted August 30, 2012 You could create your arcs using the POLYLINE command.Specify the starting point, then A> and any arcs created in this way will be POLYLINES. ok, in a nutshell, here is what I want to achieve: basically a continuous one-click operation that takes me from step 1 to 6. but as it happens, between step 5 and 6, the offset polyline needs to be exploded to handle all fillets, otherwise the edges where (original) arc elements touch do not work. careca Quote
Dadgad Posted August 30, 2012 Posted August 30, 2012 I see what you mean, I was quite surprised that when the BOUNDARY command creates a CLOSED POLYLINE, which having been OFFSET with the POLYLINE option, and despite having been a closed polyline, still yields the following message ..... another message that keeps coming up about one line having been divergent (polyline arc). Quote
Lee Mac Posted August 30, 2012 Posted August 30, 2012 Give this a try: (defun c:xf ( / *error* cm e0 e1 e2 e3 el p1 pe ) (defun *error* ( msg ) (if (= 'int (type cm)) (setvar 'cmdecho cm) ) (if (= 'int (type pe)) (setvar 'peditaccept pe) ) (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")) (princ (strcat "\nError: " msg)) ) (princ) ) (setq cm (getvar 'cmdecho) pe (getvar 'peditaccept) ) (setvar 'cmdecho 0) (setvar 'peditaccept 1) (while (setq p1 (getpoint "\nPick Internal Point <Exit>: ")) (setq e0 (entlast) el nil ) (command "_.-boundary" "_A" "_I" "_N" "" "_O" "_P" "" "_non" p1 "") (setq e1 (entlast)) (if (not (eq e0 e1)) (progn (command "_.offset" 10.0 e1 "_non" p1 "") (setq e2 (entlast)) (if (not (eq e1 e2)) (progn (command "_.chprop" e2 "" "_LA" "0" "_C" 1 "") (command "_.explode" e2) (setq e3 e2) (while (setq e3 (entnext e3)) (setq el (cons e3 el)) ) (mapcar '(lambda ( a b ) (setvar 'filletrad 10.0) (command "_.fillet" a b)) (cons (last el) el) el ) (command "_.pedit" "_M") (while (setq e2 (entnext e2)) (command e2) ) (command "" "_J" "" "") ) (alert "Unable to perform offset.") ) (entdel e1) ) (alert "Unable to detect boundary.") ) ) (setvar 'peditaccept pe) (setvar 'cmdecho cm) (princ) ) Quote
marko_ribar Posted August 30, 2012 Posted August 30, 2012 Excellent Lee... Only slight modification to your code (highlighted) : (defun c:xf ( / *error* cm e0 e1 e2 e3 el p1 pe ) [highlight](vl-load-com)[/highlight] (defun *error* ( msg ) (if (= 'int (type cm)) (setvar 'cmdecho cm) ) (if (= 'int (type pe)) (setvar 'peditaccept pe) ) (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")) (princ (strcat "\nError: " msg)) ) (princ) ) (setq cm (getvar 'cmdecho) pe (getvar 'peditaccept) ) (setvar 'cmdecho 0) (setvar 'peditaccept 1) (while (setq p1 (getpoint "\nPick Internal Point <Exit>: ")) (setq e0 (entlast) el nil ) (command "_.-boundary" "_A" "_I" "_N" "" "_O" "_P" "" "_non" p1 "") (setq e1 (entlast)) (if (not (eq e0 e1)) (progn (command "_.offset" 10.0 e1 "_non" p1 "") (setq e2 (entlast)) (if (not (eq e1 e2)) (progn (command "_.chprop" e2 "" "_LA" "0" "_C" 1 "") (command "_.explode" e2) (setq e3 e2) (while (setq e3 (entnext e3)) [highlight](setq el (cons (vlax-curve-getpointatparam e3 (+ (vlax-curve-getstartparam e3) (/ (- (vlax-curve-getendparam e3) (vlax-curve-getstartparam e3)) 2.0))) el))[/highlight] ) (mapcar '(lambda ( a b ) (setvar 'filletrad 10.0) (command "_.fillet" a b)) (cons (last el) el) el ) (command "_.pedit" "_M") (while (setq e2 (entnext e2)) (command e2) ) (command "" "_J" "" "") ) (alert "Unable to perform offset.") ) (entdel e1) ) (alert "Unable to detect boundary.") ) ) (setvar 'peditaccept pe) (setvar 'cmdecho cm) (princ) ) M.R. Quote
Lee Mac Posted August 30, 2012 Posted August 30, 2012 Excellent Lee... Only slight modification to your code (highlighted) : Did the original not work for you? Quote
marko_ribar Posted August 30, 2012 Posted August 30, 2012 I tried to replicate case OP posted in jpg, and with your original it wrongly filleted last line with arc but only on left portion - one pick boundary; right one it did correctly... I suppose it has something with fillet - it don't know how to connect entities (line filleted with arc extending it to make almost whole circle) when they are supplied rather then mid points like in my modification... Quote
Tharwat Posted August 30, 2012 Posted August 30, 2012 Did the original not work for you? It did worked very nice here . And I have been thinking that doing fillet on multiple entities is not possible , but you destroyed that idea . Quote
marko_ribar Posted August 30, 2012 Posted August 30, 2012 I am not laying, this is what I get - see attached files... Maybe its my netbook that can't do it correctly - don't know, please test it with posted dwg... M.R. xf.dwg Quote
Tharwat Posted August 30, 2012 Posted August 30, 2012 I am not laying, this is what I get - see attached files... Maybe its my netbook that can't do it correctly - don't know, please test it with posted dwg... M.R. I don't think that anyone has thought that you or anyone else is lying . Just flatten the entities and try again . Quote
marko_ribar Posted August 30, 2012 Posted August 30, 2012 But they are already flattened - they are drawn in 2d like usual... With Lee's code, sometimes it does correctly, but sometimes not... When I execute my code, then it's OK... Like I said it has something to do with the thing that when entities are supplied to fillet, it doesn't know on what side to do it, and when you supply mid points there are no mistakes... Please, don't check it with my code, but with firstly posted... M.R. P.S. I did test it on my other comp. A2012 and also results were the same... Sometimes it does correctly, sometimes not... Quote
careca Posted August 31, 2012 Author Posted August 31, 2012 (edited) wow - I feel flattered to see replies by such lisp experts dealing with by amateurish coding problem! well, i have tried both versions of the updated lisp, still they produce funny results: Lisp by Lee Mac: Lisp by Marko Ribar: maybe that's because I included a change of bending direction of one of the polylines... many thanks for your efforts, with my limited knowledge I will do additional testing. Edited August 31, 2012 by careca Quote
Dadgad Posted August 31, 2012 Posted August 31, 2012 wow - I feel flattened Which command did you use? Quote
careca Posted August 31, 2012 Author Posted August 31, 2012 Which command did you use? LOL - guess my brain was thinking about a different issue while writing the post! Quote
Dadgad Posted August 31, 2012 Posted August 31, 2012 I can relate, I was a bit deflated by my failure to offer you a workable solution. Quote
marko_ribar Posted September 5, 2012 Posted September 5, 2012 (edited) For outside offset - maybe simply this : (defun c:xf ( / *error* cm e0 e1 e2 e3 el p1 pe ch ) (vl-load-com) (defun *error* ( msg ) (if (= 'int (type cm)) (setvar 'cmdecho cm) ) (if (= 'int (type pe)) (setvar 'peditaccept pe) ) (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")) (princ (strcat "\nError: " msg)) ) (princ) ) (setq cm (getvar 'cmdecho) pe (getvar 'peditaccept) ) (setvar 'cmdecho 0) (setvar 'peditaccept 1) (while (setq p1 (getpoint "\nPick Internal Point <Exit>: ")) (setq e0 (entlast) el nil ) (command "_.-boundary" "_A" "_I" "_N" "" "_O" "_P" "" "_non" p1 "") (setq e1 (entlast)) (if (not (eq e0 e1)) (progn (initget "Outside Inside") (setq ch (getkword "\nOutside or Inside <Inside> : ")) (if (or (null ch) (eq ch "Inside")) (command "_.offset" 10.0 e1 "_non" p1 "") (command "_.offset" 10.0 e1 "_non" (getvar 'extmax) "") ) (setq e2 (entlast)) (if (not (eq e1 e2)) (progn (command "_.chprop" e2 "" "_LA" "0" "_C" 1 "") (command "_.explode" e2) (setq e3 e2) (while (setq e3 (entnext e3)) (setq el (cons (vlax-curve-getpointatparam e3 (+ (vlax-curve-getstartparam e3) (/ (- (vlax-curve-getendparam e3) (vlax-curve-getstartparam e3)) 2.0))) el)) ) (mapcar '(lambda ( a b ) (setvar 'filletrad 10.0) (command "_.fillet" a b)) (cons (last el) el) el ) (command "_.pedit" "_M") (while (setq e2 (entnext e2)) (command e2) ) (command "" "_J" "" "") ) (alert "Unable to perform offset.") ) (entdel e1) ) (alert "Unable to detect boundary.") ) ) (setvar 'peditaccept pe) (setvar 'cmdecho cm) (princ) ) M.R. Edited September 5, 2012 by marko_ribar Quote
careca Posted September 6, 2012 Author Posted September 6, 2012 that's great marko - thanks a lot. I was not aware of the sysvar extmax. I think I can take it from here, really appreciated all your support a lot - you made me learn a lot ;-) For outside offset - maybe simply this : (defun c:xf ( / *error* cm e0 e1 e2 e3 el p1 pe ch ) (vl-load-com) (defun *error* ( msg ) (if (= 'int (type cm)) (setvar 'cmdecho cm) ) (if (= 'int (type pe)) (setvar 'peditaccept pe) ) (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")) (princ (strcat "\nError: " msg)) ) (princ) ) (setq cm (getvar 'cmdecho) pe (getvar 'peditaccept) ) (setvar 'cmdecho 0) (setvar 'peditaccept 1) (while (setq p1 (getpoint "\nPick Internal Point <Exit>: ")) (setq e0 (entlast) el nil ) (command "_.-boundary" "_A" "_I" "_N" "" "_O" "_P" "" "_non" p1 "") (setq e1 (entlast)) (if (not (eq e0 e1)) (progn (initget "Outside Inside") (setq ch (getkword "\nOutside or Inside <Inside> : ")) (if (or (null ch) (eq ch "Inside")) (command "_.offset" 10.0 e1 "_non" p1 "") (command "_.offset" 10.0 e1 "_non" (getvar 'extmax) "") ) (setq e2 (entlast)) (if (not (eq e1 e2)) (progn (command "_.chprop" e2 "" "_LA" "0" "_C" 1 "") (command "_.explode" e2) (setq e3 e2) (while (setq e3 (entnext e3)) (setq el (cons (vlax-curve-getpointatparam e3 (+ (vlax-curve-getstartparam e3) (/ (- (vlax-curve-getendparam e3) (vlax-curve-getstartparam e3)) 2.0))) el)) ) (mapcar '(lambda ( a b ) (setvar 'filletrad 10.0) (command "_.fillet" a b)) (cons (last el) el) el ) (command "_.pedit" "_M") (while (setq e2 (entnext e2)) (command e2) ) (command "" "_J" "" "") ) (alert "Unable to perform offset.") ) (entdel e1) ) (alert "Unable to detect boundary.") ) ) (setvar 'peditaccept pe) (setvar 'cmdecho cm) (princ) ) M.R. 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.