Jump to content

Recommended Posts

Posted

I am working on a project that a lsp routine would help a lot.  The problem is I don't know if it is even possible. I assume it is, but don't know.  Thought someone here with more knowledge would be able to tell me if it is.  I have several polylines that need to be offset a variable I enter for an offset and then snapped back to the beginning and ending of that polyline that it is offset to.  I know crazy.  I attached an image to illustrate what i am talking about. Let me know your thoughts.

Thanks!

LSP ROUTINE QUESTION.jpg

Posted

Hi,

(defun C:test ( / _2d e enx d o L )
  
  (defun _2d ( L )
    (mapcar ''((x) (nth x L)) '(0 1))
  )
  
  (and
    (setq e (car (entsel "\nPick open LWpolyline: ")))
    (setq enx (entget e))
    (vl-every ''((x) (member x enx)) '((0 . "LWPOLYLINE")(70 . 0))) 
    (setq d (getdist (vlax-curve-getPointAtParam e (* (vlax-curve-getEndParam e) 0.5)) "\nSpecify offset distance: "))
    (setq o (vlax-ename->vla-object e))
    (setq L (mapcar ''((a b)(list (vlax-invoke o 'Offset ((eval a) d)) ((eval b) o))) '(+ -) '(vlax-curve-getStartPoint vlax-curve-getEndPoint)))
    (progn 
      (apply 
        ''((a b)
          (foreach x b
            (vlax-put x 'Coordinates
              (append 
                (_2d (car a))
                ('((v)(reverse (cddr (reverse (cddr v))))) (vlax-get x 'Coordinates))
                (_2d (cadr a))
              )
            )
          ); foreach
        )
        (list (mapcar 'cadr L) (mapcar 'caar L))
      ); apply 
      (entdel e)
    )
  ); and 
  (princ)  
); defun 

 

Leaf.gif

Posted

Wow thanks guys I am going to check the lsp and the link!  😃

 

Posted
1 hour ago, Grrr said:

(vl-every ''((x) (member x enx)) '((0 . "LWPOLYLINE")(70 . 0)))

Nice code Grrr :) .. this check fails if line type generation is enabled for the polyline. Is there a reason for that?

Posted
27 minutes ago, ronjonp said:

Nice code Grrr :) .. this check fails if line type generation is enabled for the polyline. Is there a reason for that?

 

Thanks, and thanks for the correction ! :thumbsup:

Yeah, just wanted to prompt to pick an opened LWPOLY - i should use logand 1 to check the 70 gc bit, or the vlax-curve-isClosed function.

 

Posted

Wow thanks all.  I will check it all out.  I appreciate you all taking the time to answer this post.

 

Posted

Please forgive my ignorance on this because anything I ask is from my lack of knowledge in the area of lisps.  Is there a command I can type in to use the “pline offset with taper ends.lps”, right now I am having to load it each time to use it?  Is there a way to be able to window and pick multiple lines at one time?  And lastly is there a way for it to be a smooth and straight from the start and end lines like I have in my attached picture?   It may not be possible.  I just thought I would ask.  I do really appreciate everybody’s time and help.  Thank you! 😃

LSP ROUTINE.jpg

Posted

Few quick answers:

 

2 hours ago, MoeJoe said:

Is there a command I can type in to use the “pline offset with taper ends.lps”, right now I am having to load it each time to use it?

 

You can autoload lisp programs, so you don't have to do it manually everytime. (ironically while working half of the lisps I use, I'm loading manually)

 

2 hours ago, MoeJoe said:

Is there a way to be able to window and pick multiple lines at one time? 

 

Yes, I'd call it an 'easy' modification.

 

2 hours ago, MoeJoe said:

And lastly is there a way for it to be a smooth and straight from the start and end lines like I have in my attached picture?   It may not be possible. 

 

Its possible, but I don't have that much free time to play with:

From each endpoint of the original polyline, find the vector that is tangent to the offseted polyline, resulting in finding the intersection point from where the straight taper would start.

Although looking at the picture the above algorithm may not produce the desired result, because a curve/bulge is used for the taper.

 

Another easier approach would be to use Lee's Polyline Taper and Polyline Outline, so you could manipulate each start/end segment's width for every polyline and in the end outline them.

And I believe that would produce the desired result.

  • Like 1
Posted (edited)

You won't be able to achieve the desired result purely through manipulation of an offset polyline, as the required object is elliptic and polylines do not support elliptic segments, the closest would be an approximation using multiple linear or arc segments.

 

Note that my Polyline Outline as suggested by others in this thread is also an approximation, with the result for a varying width arc segment obtained through the construction of an ellipse from 5 points calculated on the polyline outline boundary.

 

Edited by Lee Mac
Posted (edited)
33 minutes ago, Lee Mac said:

You won't be able to achieve the desired result purely through manipulation of an offset polyline, as the required object is elliptic and polylines do not support elliptic segments, the closest would be an approximation using multiple linear or arc segments.

 

But Lee, I believe that would be enough since OP is looking for a graphical result (instead of a mathematical).

^^ Ofcourse thats my assumption of what OP exactly wants.

 

And you seem right, about this:

33 minutes ago, Lee Mac said:

You won't be able to achieve the desired result purely through manipulation of an offset polyline

By looking at this demo, the outline isn't really an offset - hence the algorithm of my routine is wrong. :dammit:

Leaf-2.gif

Edited by Grrr
Posted

I would suggest something like this for polyline widths followed by Lee's Advanced Polyline Outline...

 

(defun c:lwtaperbothends ( / *error* osm lw p stt mdt ent d1 d2 k d w wl )

  (vl-load-com)

  (defun *error* ( m )
    (if osm
      (setvar 'osmode osm)
    )
    (if m
      (prompt m)
    )
    (princ)
  )

  (setq osm (getvar 'osmode))
  (while
    (or
      (not (setq lw (car (entsel "\nPick LWPOLYLINE..."))))
      (/= (cdr (assoc 0 (entget lw))) "LWPOLYLINE")
    )
    (prompt "\nMissed or picked wrong entity type...")
  )
  (setvar 'osmode 1)
  (initget 1)
  (setq p (getpoint "\nPick or specify middle vertex for taper both ends : "))
  (setq p (trans p 1 0))
  (initget 1)
  (setq stt (getdist "\nPick or specify start taper width value : "))
  (initget 1)
  (setq mdt (getdist "\nPick or specify middle taper width value : "))
  (initget 1)
  (setq ent (getdist "\nPick or specify end taper width value : "))
  (setq d1 (vlax-curve-getdistatpoint lw p))
  (setq d2 (- (vlax-curve-getdistatparam lw (vlax-curve-getendparam lw)) d1))
  (setq k -1)
  (repeat (fix (1+ (vlax-curve-getendparam lw)))
    (setq d (vlax-curve-getdistatparam lw (setq k (1+ k))))
    (setq w (cond
              ( (< d d1)
                (+ stt (* (/ d d1) (- mdt stt)))
              )
              ( (equal d d1 1e-6)
                mdt
              )
              ( t
                (+ mdt (* (/ (- d d1) d2) (- ent mdt)))
              )
            )
    )
    (setq wl (cons w wl))
  )
  (setq wl (mapcar '(lambda ( a b ) (list a b)) (reverse wl) (cdr (reverse wl))))
  (setq k -1)
  (foreach w wl
    (vla-setwidth (vlax-ename->vla-object lw) (setq k (1+ k)) (car w) (cadr w))
  )
  (*error* nil)
)

Regards, M.R.

Posted

@marko_ribar - I tried the code above and received  - bad character read (octal): 0  Any suggestions on what I should try.  Thanks marco_ribar

 

 

Posted

I tried pedit  spline and fit to the version I did to the outside plines created they smooth but the ends are not super smooth.

 

I had another go at it and rather than 1 pline I made 2 left and right the used pedit F ended up with this. I have to redo the code.

 

MoeJoe  try manually explode the pline and rejoin one side at a time then pedit. If thats what you want I am sure you will get 2 or 3 answers.

 

nimage.png.6e23d003b968821d52c434029912b01c.png

 

; add to acaddoc.lsp or just drag and drop from explorer type AHpltaper or type (load "Pline offset taper.lsp")

Change this AH:pltaper to  C:AHpltaper in the code type ahpltaper to run

add to acaddoc.lsp (load "Pline offset taper.lsp") to load every time

Posted

@BIGAL - Does that create a lot of nodes like that?  I will take a look it.  I need to have minimal nodes if possible.  Thanks Bigal!

Posted
19 hours ago, MoeJoe said:

@marko_ribar - I tried the code above and received  - bad character read (octal): 0  Any suggestions on what I should try.  Thanks marco_ribar

 

 

 

Does this error occur when you try to load *.lsp?... Make sure you copy+paste entire code correctly into *.lsp file... Also, someone else have this issue? - if so reply to this post, thanks... I am not sure, but this kind of error has happened to me if code was badly saved...

Posted (edited)

Marko I have had a couple of times pasting direct from forums to Autocad  if so just paste into notepad ++ then re-copy back into Autocad it does not happen very often hard to put an exact error problem to it.

Edited by BIGAL

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