Jim Clayton Posted October 5, 2018 Posted October 5, 2018 Hello again. I'm trying to get started on a lisp but I can't find the groundwork needed to get me in the right direction. I want to create a rectangle, prompt for insertion point (preferably midpoint of on of the sides), X Dim, Y Dim, but only have the corners on one side chamfered to 0.03. That is my starting point. The goal is to then mirror this action in the opposite direction. Anyone able to offer some guidance with this? My lisp skills are currently a work in progress. Thanks for the help. Quote
Aftertouch Posted October 5, 2018 Posted October 5, 2018 Here you go: (defun C:test ( / dimx dimy dimcham inspt ) (while (not (setq dimx (getreal "\nWidth: ")))) (while (not (setq dimy (getreal "\nHeight: ")))) (while (not (setq dimcham (getreal "\nChamfer: ")))) (while (not (setq inspt (getpoint "\nInsertionpoint: ")))) (command "PLINE" inspt (strcat "@0," (rtos (- dimy dimcham) 2)) (strcat "@" (rtos dimcham 2) "," (rtos dimcham 2)) (strcat "@" (rtos (- dimx dimcham) 2) ",0") (strcat "@0,-" (rtos dimy 2)) "c" ) (princ) ) Quote
Jim Clayton Posted October 5, 2018 Author Posted October 5, 2018 Awesome. Thanks for the help. This might help get me going in the right direction. Quote
Jim Clayton Posted October 5, 2018 Author Posted October 5, 2018 I do have one question about this. I'm trying to have the chamfer on both top and bottom on only one side...currently it's only on top, but I'd like to try figuring that out. The question is that when I enter a chamfer of .03, 90% of the time I end up with crooked rectangle, rather than a chamfered rectangle. The other 10% it works as it should. Any idea why that might be? Thanks for the help. Quote
BIGAL Posted October 7, 2018 Posted October 7, 2018 Just me I work out the points of the pline rather than use a strcat method. In saying that you can have a chamfer on any corner using the method of calculating the pline points, for a rectang pline p1 p2 p3 p4 c, for say 1 chamfer, pline p1 p2 p3 p4 p5 c chamfer is say p3 - p4. Its pretty easy using the polar function. Quote
Jim Clayton Posted October 7, 2018 Author Posted October 7, 2018 Interesting. This might prove to be a more useful route for what I'm trying to achieve. Will have to mess around with it when I'm back in front of a computer. Thanks for the help. Quote
BIGAL Posted October 8, 2018 Posted October 8, 2018 (edited) You could have multi options and could do something like cnr 1 3 so diagonals only on corners 1 & 3, A for all etc. Diagram above would be 1 & 4 if you use a string input like 1,2 or 1,3 or A or 1,2,3,4 you can pull it apart before you draw. Use lee-marc pasrse csv. Thinking a bit more maybe use vl-string-search and look for 1 2 3 4 A in any sort of input ie 1234 is ok. (setq ans "1234") (if (> (vl-string-search "1" ans ) 0)(setq cnr 1)) start 1st point is chamfer add point to a list. (if (> (vl-string-search "2" ans ) 0)(setq cnr 2)) start 2nd point is -ve from end add to list do vert accordingly (if (> (vl-string-search "3" ans ) 0)(setq cnr 1)) and so on (if (> (vl-string-search "1" ans ) 0)(setq cnr 1)) and so on ; create pline by points from a list (command "_pline") (while (= (getvar "cmdactive") 1 ) (repeat (setq x (length lst)) (command (nth (setq x (- x 1)) lst)) ) (command "c") Edited October 8, 2018 by BIGAL Quote
Aftertouch Posted October 8, 2018 Posted October 8, 2018 just my 2 cents again... (defun C:test ( / dimx dimy dimcham inspt ) (while (not (setq dimx (getreal "\nWidth: ")))) (while (not (setq dimy (getreal "\nHeight: ")))) (while (not (setq dimcham (getreal "\nChamfer: ")))) (while (not (setq inspt (getpoint "\nInsertionpoint: ")))) (if (or (> (* 2 dimcham) dimx) (> (* 2 dimcham) dimy)) (progn (princ "Chamfer to large for dimensions...") ) (progn (command "PLINE" inspt (strcat "@0," (rtos (- dimy dimcham) 2)) (strcat "@" (rtos dimcham 2) "," (rtos dimcham 2)) (strcat "@" (rtos (- dimx (* dimcham 2)) 2) ",0") (strcat "@" (rtos dimcham 2) ",-" (rtos dimcham 2)) (strcat "@0,-" (rtos (- dimy dimcham) 2)) "c" ) ) ) (princ) ) Quote
BIGAL Posted October 9, 2018 Posted October 9, 2018 (edited) Started to have a play and wrote this try 1234 but there is a couple of mistakes so about to fully redo but posted for fun any way. getvals.lsp rectang with chamfer.lsp Edited October 10, 2018 by BIGAL Quote
Jim Clayton Posted October 9, 2018 Author Posted October 9, 2018 BigAl: I tried running the above but nothing seems to be happening. Possibly user error? Thanks for the help. Aftertouch: Also tried running your second suggestion and it only seems to be working some of the time. Again, user error? Also, thanks for all the help. Very much appreciated. Quote
Jim Clayton Posted October 9, 2018 Author Posted October 9, 2018 This might give you an idea of what I'm trying to achieve (attached). coordinates.dwg Quote
BIGAL Posted October 10, 2018 Posted October 10, 2018 Sorry rewrote it entirely using a different method will post again but when I get home thats like 9 hours from now. The code is for a rectang. If you want different shapes it will require a code per shape but the example will show you how. the obvious to me was to have radius instead of chamfer. This is more like a Length 1, Dia 1, len 2, dia 2, but with taper dia 3 needs a whole rethink. Quote
Jim Clayton Posted October 10, 2018 Author Posted October 10, 2018 Yeah my train of thy was to treat it like two chamfered rectangles back to back... the midpoint of where they meet would be the "X" location, treating the diameters as lengths since everything is 2d. Since I'm a noob to lisp though this may have only been good in theory and not reality. I honestly hadn't considered the taper but looking at it now I could see it posing a problem. Quote
Jim Clayton Posted October 10, 2018 Author Posted October 10, 2018 So far I've only been able to actually write a lisp for a simple rectangle. Not quite Lee Mac status but there was massive cubicle celebration underway upon completion. I appreciate all the help. Will see what sort of damage I can do with it in the morning. Tks. Quote
BIGAL Posted October 10, 2018 Posted October 10, 2018 I updated the chamfer code above you may be able to use it out of the box.But if you want tapers then may need to invoke chamfer command to save on the maths of a sloping side. Quote
Jim Clayton Posted October 11, 2018 Author Posted October 11, 2018 I tried using this again yesterday, but still wasn't able to get it operational. Downloaded both, placed them in the appropriate path, loaded "rectang with chamfer" lisp, typed command, nothing. Tried a bunch of different things but nothing seemed to work. Am I missing something? thanks for your help. 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.