Jump to content

Recommended Posts

Posted

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

Posted

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.

peditaccept options.JPG

Posted
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

Posted

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.

Posted
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:

 

xfillet.jpg

 

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

Posted

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

in a nutshell.JPG

Posted

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

Posted

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.

Posted
Excellent Lee... Only slight modification to your code (highlighted) :

 

Did the original not work for you?

Posted

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

Posted
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 .:)

Posted

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.jpg

xf.dwg

Posted
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 . ;)

Posted

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

Posted (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:

fx_1.jpg

 

Lisp by Marko Ribar:

fx_2.jpg

 

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 by careca
Posted
wow - I feel flattened

 

:? Which command did you use? :beer:

Posted
:? Which command did you use? :beer:

 

LOL - guess my brain was thinking about a different issue while writing the post!

Posted

I can relate, I was a bit deflated by my failure to offer you a workable solution. :beer:

Posted (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 by marko_ribar
Posted

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.

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