Jump to content

Lisp. Rectangle. Chamfered on One Side Only.


Jim Clayton

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...