Jump to content
Jim Clayton

Lisp. Rectangle. Chamfered on One Side Only.

Recommended Posts

Jim Clayton

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.

Share this post


Link to post
Share on other sites
Aftertouch

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)
)

Share this post


Link to post
Share on other sites
Jim Clayton

Awesome.  Thanks for the help.  This might help get me going in the right direction.

Share this post


Link to post
Share on other sites
Jim Clayton

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.

Share this post


Link to post
Share on other sites
BIGAL

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.

ScreenShot141.jpg

Share this post


Link to post
Share on other sites
Jim Clayton

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.

Share this post


Link to post
Share on other sites
BIGAL
Posted (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 by BIGAL

Share this post


Link to post
Share on other sites
Aftertouch

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)
)

Share this post


Link to post
Share on other sites
BIGAL
Posted (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 by BIGAL

Share this post


Link to post
Share on other sites
Jim Clayton

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.

Share this post


Link to post
Share on other sites
Jim Clayton

This might give you an idea of what I'm trying to achieve (attached).

coordinates.dwg

Share this post


Link to post
Share on other sites
BIGAL

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.

 

 

 

 

 

Screen Shot 10-10-18 at 08.28 AM.PNG

Share this post


Link to post
Share on other sites
Jim Clayton

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.

Share this post


Link to post
Share on other sites
Jim Clayton

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.

Share this post


Link to post
Share on other sites
BIGAL

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.

Share this post


Link to post
Share on other sites
Jim Clayton

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×