Jump to content

Recommended Posts

Posted

Hi,

 

I need to offset a polyline to both sides but with a tapered end on both sides.

Finally it must be a closed polyline.

 

jpg.gif

 

Is this possible with LISP?

 

Greetzzz

Z

Example.JPG

Offset Example.dwg

  • Replies 25
  • Created
  • Last Reply

Top Posters In This Topic

  • BIGAL

    7

  • Grrr

    7

  • gsc

    5

  • rlx

    4

Top Posters In This Topic

Posted Images

Posted

Question:

Is this possible with LISP?

Answer:

Yes it's possible.
Posted

How I'd approach it:

 

  • Divide one of the curves into n-segments (construct a point list [pL1])
  • For that point list, construct a paralel pointlist [pL2], by projecting on the second curve
  • Find mids from these pL1, and pL2 - construct new point list of middles [mL]
  • Entmake a pline/spline for mL - which will result the interpolated curve
  • Prompt for the 'Y' value (in the picture) [that would be my first thing to collect the input, whateva]
  • Find the tangent angles from the starting and ending point of the interpolated curve, use polar and re-append the extended points to the mL
  • Well, having all the required points - one will know what to do next.

Posted

My $0.05 take a starting pline of total length required. Get end points. Trim pline the y length both ends. Do left and right offsets. Add to 1 pline offset start pt join other offset pline repeat endpt joining the bits as you go. Redo original pline by reseting endpoints. This should work with curved ends as well using pointatdist.

Posted

Thanx people, this will help me along the way!

Posted (edited)

Give this a try

 

; taper ends on a line arc or pline
; by Alan H March 2018


(defun alg-ang (object pnt)
(angle '(0. 0. 0.)
(vlax-curve-getfirstderiv obj  (vlax-curve-getparamatpoint object pnt ) )
)
)
(defun c:AHtaper ( / oldsnap y off len obj stpt endpt pt1 pt2 pt3 pt4 L1 L2 O1 O2) 
(setq oldsnap (getvar 'osmode))

; (set y (getreal "Enter end distance"))
;(setq off (getreal ("Enter Offset"))
; remove next 4 lines if no getvals3.lsp

(if (not AH:getval2)(Load "getvals3"))
(ah:getval2 "Enter end distance " 9 8 "50" "Enter offset" 9 8 "20")
(setq y (atof val1))
(setq off (atof val2))

(setvar 'osmode 0)

(setq ent (entsel))
(setq obj (vlax-ename->vla-object (car ent)))
(setq stpt (vlax-curve-getstartpoint obj))
(setq endpt (vlax-curve-getendpoint obj))
(if (= (vla-get-objectname obj) "AcDbArc")
(setq len (vla-get-arclength obj))
(setq len (vla-get-length obj))
)
(setq pt1 (vlax-curve-getpointatdist obj y))
(setq pt2 (vlax-curve-getpointatdist obj (- len y)))

(setq ang (alg-ang obj pt1))
(setq pt3 (polar pt1 (+ ang 1.5707) (* 2.0 off)))
(setq pt4 (polar pt1 (- ang 1.5707)  (* 2.0 off)))
(command "Line" pt3 pt4 "")
(setq L1 (entlast))

(setq ang2 (alg-ang obj pt2))
(setq pt3 (polar pt2 (+ ang2 1.5707) (* 2.0 off)))
(setq pt4 (polar pt2 (- ang2 1.5707)  (* 2.0 off)))
(command "Line" pt3 pt4 "")
(setq L2 (entlast))

(command "offset" off ent pt3 "")
(setq O1 (vlax-ename->vla-object  (entlast)))
(setq stpt2 (vlax-curve-getstartpoint  O1))
(setq endpt2 (vlax-curve-getendpoint  O1))

(command "trim" L1 "" stpt2 "")
(command "trim" L2 "" endpt2 "")

(setq obj2 (entlast))
(setq stpt2 (vlax-curve-getstartpoint (vlax-ename->vla-object obj2)))
(setq endpt2 (vlax-curve-getendpoint (vlax-ename->vla-object obj2)))

(command "offset" off ent pt4 "")
(setq O2 (vlax-ename->vla-object  (entlast)))
(setq stpt3 (vlax-curve-getstartpoint  O2))
(setq endpt3 (vlax-curve-getendpoint  O2))

(command "trim" L1 "" stpt3 "")
(command "trim" L2 "" endpt3 "")
(command "erase" L1 L2 "")

(setq obj3 (entlast))
(setq stpt3 (vlax-curve-getstartpoint (vlax-ename->vla-object obj3)))
(setq endpt3 (vlax-curve-getendpoint (vlax-ename->vla-object obj3)))

(command "pline" stpt2 stpt stpt3 "")
(setq obj4 (entlast))
(command "pline" endpt2 endpt endpt3 "")
(command "pedit" "L" "j" obj2 obj4 obj3 "" "")
(princ)
)
; taper ends on a line arc or pline
; by Alan H March 2018


(defun alg-ang (object pnt)
(angle '(0. 0. 0.)
(vlax-curve-getfirstderiv obj  (vlax-curve-getparamatpoint object pnt ) )
)
)
(defun c:AHtaper ( / oldsnap y off len obj stpt endpt pt1 pt2 pt3 pt4 L1 L2 O1 O2) 
(setq oldsnap (getvar 'osmode))

; (set y (getreal "Enter end distance"))
;(setq off (getreal ("Enter Offset"))
; remove next 4 lines if no getvals3.lsp

(if (not AH:getval2)(Load "getvals3"))
(ah:getval2 "Enter end distance " 9 8 "50" "Enter offset" 9 8 "20")
(setq y (atof val1))
(setq off (atof val2))

(setvar 'osmode 0)

(setq ent (entsel))
(setq obj (vlax-ename->vla-object (car ent)))
(setq stpt (vlax-curve-getstartpoint obj))
(setq endpt (vlax-curve-getendpoint obj))
(if (= (vla-get-objectname obj) "AcDbArc")
(setq len (vla-get-arclength obj))
(setq len (vla-get-length obj))
)
(setq pt1 (vlax-curve-getpointatdist obj y))
(setq pt2 (vlax-curve-getpointatdist obj (- len y)))

(setq ang (alg-ang obj pt1))
(setq pt3 (polar pt1 (+ ang 1.5707) (* 2.0 off)))
(setq pt4 (polar pt1 (- ang 1.5707)  (* 2.0 off)))
(command "Line" pt3 pt4 "")
(setq L1 (entlast))

(setq ang2 (alg-ang obj pt2))
(setq pt3 (polar pt2 (+ ang2 1.5707) (* 2.0 off)))
(setq pt4 (polar pt2 (- ang2 1.5707)  (* 2.0 off)))
(command "Line" pt3 pt4 "")
(setq L2 (entlast))

(command "offset" off ent pt3 "")
(setq O1 (vlax-ename->vla-object  (entlast)))
(setq stpt2 (vlax-curve-getstartpoint  O1))
(setq endpt2 (vlax-curve-getendpoint  O1))

(command "trim" L1 "" stpt2 "")
(command "trim" L2 "" endpt2 "")

(setq obj2 (entlast))
(setq stpt2 (vlax-curve-getstartpoint (vlax-ename->vla-object obj2)))
(setq endpt2 (vlax-curve-getendpoint (vlax-ename->vla-object obj2)))

(command "offset" off ent pt4 "")
(setq O2 (vlax-ename->vla-object  (entlast)))
(setq stpt3 (vlax-curve-getstartpoint  O2))
(setq endpt3 (vlax-curve-getendpoint  O2))

(command "trim" L1 "" stpt3 "")
(command "trim" L2 "" endpt3 "")
(command "erase" L1 L2 "")

(setq obj3 (entlast))
(setq stpt3 (vlax-curve-getstartpoint (vlax-ename->vla-object obj3)))
(setq endpt3 (vlax-curve-getendpoint (vlax-ename->vla-object obj3)))

(command "pline" stpt2 stpt stpt3 "")
(setq obj4 (entlast))
(command "pline" endpt2 endpt endpt3 "")
(command "pedit" "L" "j" obj2 obj4 obj3 "" "")
(princ)
)

Edited by BIGAL
Posted

gsc did you have a look ? It could work with singles lines as well with a simple mod of check if line .

Posted
gsc did you have a look ? It could work with singles lines as well with a simple mod of check if line .

 

Hi Al, had a quick look and it kinda worked...

 

 

bigal.jpg

Posted (edited)

Yeah Rlx I realised that I may have posted the 95% version I added a few more lines but may have hit dont save when testing, it did put original pline back to where it started will double check right now. The newlst2 is the problem nothing worse than when testing it works then suddenly does not.

 

I have no idea as I tested a few times but it was a typo I had stp not STPT for start point. I corrected code and tested again

 

But have removed this section of code altogether as not required as I have CORDS which is the original points and just update pline vertices back to where they were.

 

I will check again on a shapes like you have with curves on end.

 

Thanks for testing.

 

A side advantage enter distance as 0 and get square end.

Edited by BIGAL
Posted

yeah know 'bug' when writing & testing , vaviables and functions still in memory. Kinda make sense now why Lee is allways trying to write his functions with the minimum number of variables.

Posted
yeah know 'bug' when writing & testing , vaviables and functions still in memory. Kinda make sense now why Lee is allways trying to write his functions with the minimum number of variables.

 

Darn, Rlx you've drawn my attention:

 

Just somewhat quoting myself from this discussion:

For large programs you could even use assoc list, instead of defining & localising multiple variables:

(setq 
 depth 5
 width 60 
 len 140
 thickness 1
 material "Concrete"
 elevation 300
)

Instead of localising 6 symbols, like in the above this require localising only 'L':

(setq L
 '(
   (depth 5)
   (width 60)
   (len 140)
   (thickness 1)
   (material "Concrete")
   (elevation 300)
 )
)

The accessor to such list is this:

(assoc 'len L)

 

 

And I have the habbit (in my head) to use symbols like this to name my lists:

L - list (in general)
aL - assoc list (in general)
rL - return list (used for return)
pL - point list
eL - entity list (list of enames - not DXF!)
oL - object list (list of VLA-OBJECTS)
sL - string list (list of strings)
vL - vectors list
xL, yL, zL - more lists (assoc or simple), when one list is not enough for my code.

'L' character in uppercase and not 'l' because I could mistake it with 1 or I.

But when working with customly-made assoc list a short description is required for easier maintain:

; Assoc list of: (<Text Content> <Font Size> <Bold> <Alignment>)

 

And now we can associate the subfunction our weapon, the assoc list as our weapon's magazine and every set of provided arguments as a bullet, and fire:

; aL - Assoc list of: (<Text Content> <Font Size> <Bold> <Alignment>)
(foreach itm aL ; magazine
 (
   (lambda (itm / txtcont fontsize bold alignm ) ; weapon
     (mapcar 'set '(txtcont fontsize bold alignm) itm)
     ; < do stuff >
   ); lambda
   itm ; bullet
 )
); foreach

 

Thats how I visualise lisp. :)

HTH

Posted

@Grrr yeah I saw you using this 'L'-technique in the merge pdf and I believe another function a not so long ago. Allways in search for shorter, faster and (hopefully) more efficient code :-) In my own code I not always put too much focus on short or efficient but easier to change the digital oil so to speak haha.

Posted
@Grrr yeah I saw you using this 'L'-technique in the merge pdf and I believe another function a not so long ago. Allways in search for shorter, faster and (hopefully) more efficient code :-) In my own code I not always put too much focus on short or efficient but easier to change the digital oil so to speak haha.

 

I'm just in hope you would slowly migrate your coding style. :lol:

Your programs are awesome, but exploring your code is a pain (i.e.: constantly switching rows number 500 1200 3000 to trace whats happening to a single variable).

Posted (edited)
I'm just in hope you would slowly migrate your coding style. :lol:

Your programs are awesome, but exploring your code is a pain (i.e.: constantly switching rows number 500 1200 3000 to trace whats happening to a single variable).

 

Speaking in ergonomic term some of my appies are nice but my programming skills itself are nowhere as advanced as yours or Lee's (just to name a few). But I'm still trying new ways all the time. Last program I wrote (update) is one to insert a special vendor title block on a set of drawings received from a vendor. Tried writing all variables in the registry... wow , works great , why haven't I done this sooner... the answer came a week later when my windows profile needed to be reset by IT : and now they're gone (my variables haha)

 

(we are doing it again , hijacking someone elses thread haha)

 

gr. Rlx

Edited by rlx
Posted
Speaking in ergonomic term some of my appies are nice but my program skills itself are nowhere as advanced as yours or Lee's (just to name a few).

 

We(most of us) just structure the whole code into 'code blocks', so its easier to maintain...

I even have the habbit to use annonymous functions on-the-fly with their own localised variables to see in 'real-time' whats happening to my variable in the #main.

Your style looks very comfortable when designing, but also looks nightmarish for localising :lol:

 

 

But I'm still trying new ways all the time. Last program I wrote (update) is one to insert a special vendor title block on a set of drawings recievend from a vendor.

 

Nice to hear that you are open-minded!

 

 

Tried writing all variables in the registry... wow , works great , why havend I done this sooner... the answer came a week later when my windows profile needed to be reset by IT : and now they're gone (my variables haha)

 

Ah, storing variables... well you probably know all the approaches to store 'em,

but still would advise to check the "Storing Variables" discussions on the lisp forums, aswell Lee's programs (remember in one he did a custom .cfg file). :P

 

 

(we are doing it again , hijacking someone elses thread haha)

 

BIGAL solved it (I think), but okay stopping now. :lol:

Posted

Hi Bigal,

 

This works like a charm! Thanx

 

Greetzzz,

 

Gerben

Posted (edited)

Just thought I would throw this out there still working on it but Plines, arcs and lines supported. I know have to fix the arc offset problem. The code needs a tidy like using cond rather than if's and maybe a couple of new defuns. Added a dcl for questions just the way I am going now.

 

Rlx and Grrr I drew ortho pline then routine does not work would appreciate any ideas.

 

Ok bug in arcs is when shorten for offset radius changes so need to recreate arc correctly modify start end and RADIUS.

 

see 2nd post for final code

Getvals3 has been updated

GETVALS3.lsp

Edited by BIGAL
see 1st post

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