Jump to content

direction of polyline upon picked point


motee-z

Recommended Posts

hello

i have polyline i want to make it start from end point and leave it if it is start from same picked point

i mean reverse the polyline if i pick end point of it and leave it if i pick start point of it

any help will be appreciated

thank you

Link to comment
Share on other sites

(defun C:PLREV ( / s e p p1)
 (if
   (and
     (setq s (entsel))
     (wcmatch (cdr (assoc 0 (entget (setq e (car s))))) "*POLYLINE")
     )
   (progn
     (setq p (vlax-curve-getParamAtPoint e (vlax-curve-getClosestPointTo e (trans (cadr s) 1 0)))
                                      ; or (trans (osnap (cadr s) "_nea") 1 0) - for any view and UCS
           p1 (vlax-curve-getEndParam e)
           )
     (if (> p (/ p1 2.0))
       (vl-cmdf "_PEDIT" e "_R" "") ;will convert 2dPolyline to LWpolyline
       )
     )
   )
 (princ)
 )

Link to comment
Share on other sites

thank stefan

i don't know to use your routin

what i want the sequence of command line

select polyline

choose a point to be start point

result polyline change its direction if picked point is the end of polyline and stay as is if it picked point is the start of polyline

Link to comment
Share on other sites

thank stefan

i don't know to use your routin

what i want the sequence of command line

select polyline

choose a point to be start point

result polyline change its direction if picked point is the end of polyline and stay as is if it picked point is the start of polyline

Hi motee-z,

My routine combine first two steps. So when you are prompted to select object, just click on a polyline near to the desired end.

plrev1.gif

Link to comment
Share on other sites

Motee-z, you didn't listed in your profile the software/version you are currently using. Please note that the built-in PEDIT command have - starting with version 2010, I believe - an option named Reverse that seems exactly what you were looking for.

Edited by MSasu
Link to comment
Share on other sites

You are welcome motee-z.

I just realized that parameter of pline is not the correct way to establish what end you've picked.

So I've switched to distance and added some new features. Now it becomes:

(defun C:PLREV (/ *error* acDoc msg s e en d d1 l)
 (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
 (vla-StartUndoMark acDoc)

 (defun *error* (msg)
   (and msg (not (eq msg "Function cancelled")) (princ msg))
   (vla-EndUndoMark acDoc)
 )

 (while
   (progn
     (setvar 'errno 0)
     (or
       (progn
         (initget "Undo")
         (setq s (entsel "\nSelect a polyline [undo] <Exit>: "))
       )
       (= (getvar 'errno) 7)
     )
   )
    (cond
      ((eq s "Undo")
       (if l
         (progn
           (vl-cmdf "_PEDIT" (car l) "_R" "")
           (setq l (cdr l))
         )
         (princ "\nNothing to undo")
       )
      )
      ((and
         (setq msg "\nNothing selected. Try again")
         s
         (setq msg "\nPlease select a polyline")
         (wcmatch (cdr (assoc 0 (setq en (entget (setq e (car s)))))) "*POLYLINE")
         (setq msg "\nObject is on a locked layer")
         (zerop (logand (cdr (assoc 70 (tblsearch "layer" (cdr (assoc 8 en))))) 4))
         )
       (setq d  (vlax-curve-getDistAtPoint e (vlax-curve-getClosestPointTo e (trans (cadr s) 1 0)))
             d1 (vlax-curve-getDistAtPoint e (vlax-curve-getEndPoint e))
       )
       (if (> d (/ d1 2.0))
         (progn
           (vl-cmdf "_PEDIT" e "_R" "")
           (setq l (cons e l))
         )
         (princ "\nPick the other end to reverse")
       )
      )
      (T (princ msg))
    )
 )
 (*error* nil)
 (princ)
)

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