Jump to content

Recommended Posts

Posted

Hello!

 

I have to check many closed polylines whether their direction is counter clockwise. If they run clockwise, they should be reversed.

In the end, all polylines counterclockwise run.

Is there a solution?

Thank you in advance for your help.

Excuse my bad English. My helper is a results per program

lg. Martin:)

  • Replies 21
  • Created
  • Last Reply

Top Posters In This Topic

  • martinle

    8

  • VVA

    5

  • irneb

    3

  • MarcoW

    2

Top Posters In This Topic

Posted Images

Posted

Hi Mircea!

This works as far as Lisp.

Only:

I'm running no text in my polylines and I know in advance nor in which direction the polyline.

This Lisp simply changes the direction of the polyline shown. Only when the direction already fits (counterclockwise), it turns it to me anyway. But this should not be.

This Lisp can only individual polylines can be selected. It should, however, all the polylines in the entire drawing will be checked for the direction.

Can you help me there?

 

Greetings

 

Martin:)

Posted

@ Martinle, just a little hint: please start your topics with an English title, it will then be more usefull for others as well.

 

I remember a routine that reversed lines, polylines and arcs as well but don't have it currently. Maybe you want to google a bit for existing routines... there is a lot out there.

 

What I am wondering is this: when reversing a polyline, all segments are reversed. I would like to create a routine that would reverse only those segments of a polyline if the angle of that specific segment is > 90 degrees but

 

Maybe someone wants to help me get started?

 

Kind regards,

MarcoW

Posted

Marcow Hello!

 

Thanks for the note!

I'll just have to keep looking!

 

Thank you.

 

Greetings

 

Martin

Posted
What I am wondering is this: when reversing a polyline, all segments are reversed. I would like to create a routine that would reverse only those segments of a polyline if the angle of that specific segment is > 90 degrees but I don't think that's possible, at least not without changing the appearance of the polyline or exploding it. E.g. see this image:

capture_05312011_111623.png

White line is the original PL, Red is exploded with yellow as reversed segments, Green is what you'll get by reversing the PL's vectors themselves - not what you're after (methinks).

Posted
Hello!

 

I have to check many closed polylines whether their direction is counter clockwise. If they run clockwise, they should be reversed.

In the end, all polylines counterclockwise run.

Is there a solution?

Thank you in advance for your help.

Excuse my bad English. My helper is a results per program

lg. Martin:)

Try it

(defun C:PL-CW()(Pl-CW t));;;Clockwise
(defun C:PL-CCW()(Pl-CW nil));;;CounterClockwise
(defun Pl-CW ( what / int:i e1 res clk+ ss)
 ;;; what - t Clockwise
 ;;; what - nil CounterClockwise
 (vl-load-com)
 (or  *pl-activedoc*
      (setq  *pl-activedoc* (vla-get-activedocument (vlax-get-acad-object))))
 (vla-startundomark  *pl-activedoc*)
 (princ (strcat "\n" (if what "Clockwise mode"  "CounterClockwise mode") " Select Polyline"))
 (setq ss nil
 ss (ssget "_:L" '((0 . "*POLYLINE"))))
 (setq int:i '-1 clk+ 0)
 (while (and ss (setq e1 (ssname ss (setq int:i (1+ int:i)))))
   (if what
     ;;;Reverse CounterClockwise->Clockwise
     (if (null(pl:clockwise-p e1))
(progn
  (pl:geom-allpline-reverse e1)
  (setq clk+ (1+ clk+))
  )
)
     ;;;Reverse Clockwise->CounterClockwise
     (if (pl:clockwise-p e1)
(progn
  (pl:geom-allpline-reverse e1)
  (setq clk+ (1+ clk+))
  )
)
     )
 )
 (princ (strcat "\nCheck " (itoa int:i) " polyline."))
 (princ "\n\t")(princ clk+)(princ (if what  " \tCounterClockwise (reverse)" " \tClockwise (reverse)"))
 (princ "\n\t")(princ (- int:i clk+))(princ (if what " \tClockwise" " \tCounterClockwise"))
 (setq ss nil)(vla-endundomark  *pl-activedoc*) (princ))
(defun pl:geom-allpline-reverse ( pl / pln ret)
 (if (= (type pl) 'VLA-OBJECT)
   (setq pln (vlax-vla-object->ename pl))
   (setq pln pl))
 (cond ((= (pl:dxf 0 (entget pln)) "LWPOLYLINE")
 (setq ret (pl:geom-LWpolyline-revers pln)))
((= (pl:dxf 0 (entget pln)) "POLYLINE")
 (setq ret (pl:geom-polyline-revers  pln)))
(t (setq ret nil))
)
 ret
 )
(defun pl:geom-LWpolyline-revers ( lw / e x1 x2 x3 x4 x5 x6)
 (if (= (type lw) 'VLA-OBJECT)
   (setq lw (vlax-vla-object->ename lw)))
   (setq e (entget lw ))
(foreach a1 e 
  (cond 
    ((= (car a1) 10) (setq x2 (cons a1 x2))) 
    ((= (car a1) 40) (setq x4 (cons (cons 41 (cdr a1)) x4))) 
    ((= (car a1) 41) (setq x3 (cons (cons 40 (cdr a1)) x3))) 
    ((= (car a1) 42) (setq x5 (cons (cons 42 (- (cdr a1))) x5))) 
    ((= (car a1) 210) (setq x6 (cons a1 x6))) 
    (t (setq x1 (cons a1 x1))) 
    ) ;_ end of cond 
  )
(entmod (append(reverse x1)(append(apply(function append)
 (apply (function mapcar)(cons 'list (list x2 
        (cdr (reverse (cons (car x3) (reverse x3)))) 
        (cdr (reverse (cons (car x4) (reverse x4)))) 
        (cdr (reverse (cons (car x5) (reverse x5)))) 
        ) ;_ end of list 
       ) ;_ end of cons 
     ) ;_ end of apply 
        ) ;_ end of apply 
      x6 
      ) ;_ end of append 
    ) ;_ end of append 
  ) ;_ end of entmod 
 (entupd lw) 
 ) ;_ end of defun
(defun pl:geom-polyline-revers  
                              (ent_name        / 
                               _dxf-code-data  tmp_ent 
                               i               poly_ent 
                               vert_ent        vertex_list 
                               bulge_list      start_width_list 
                               end_width_list 
                              )
(if (= (type ent_name) 'VLA-OBJECT)
   (setq ent_name (vlax-vla-object->ename ent_name)))
 ;; Reverse "POLYLINE" 
 (setq tmp_ent ent_name 
         i       0 
 ) ;_ end of setq
 (setq bulge_list nil vertex_list nil start_width_list nil end_width_list nil)
 (while 
   (not (= "SEQEND" (pl:dxf 0 (setq tmp_ent (entnext tmp_ent))))) ;_ end of not 
    (setq bulge_list 
           (cons (pl:dxf 42 tmp_ent) bulge_list) 
          vertex_list 
           (cons (entget tmp_ent) vertex_list) 
          start_width_list 
           (cons (pl:dxf 40 tmp_ent) 
                 start_width_list 
           ) ;_ end of cons 
          end_width_list 
           (cons (pl:dxf 41 tmp_ent) end_width_list) 
          i (1+ i) 
    ) ;_ end of setq 
 ) ;_ end of while
 
 (setq
       bulge_list       (append (cdr bulge_list) (list (car bulge_list))) 
       start_width_list (append (cdr start_width_list) 
                                (list (car start_width_list)) 
                        ) ;_ end of append 
       end_width_list   (append (cdr end_width_list) 
                                (list (car end_width_list)) 
                        ) ;_ end of append
       i                0
       bulge_list       (mapcar '(lambda (x) (- 0 x)) bulge_list) 
       tmp_ent          ent_name 
       poly_ent         (cdr (entget tmp_ent '("*"))) ;;;Added to revers with XData
       poly_ent         (subst (cons 40 (car end_width_list)) 
                               (assoc 40 poly_ent) 
                               poly_ent 
                        ) ;_ end of subst 
       poly_ent         (subst (cons 41 (last start_width_list)) 
                               (assoc 41 poly_ent) 
                               poly_ent 
                        ) ;_ end of subst 
 ) ;_ end of setq 
 (entmakex poly_ent)          ; polyline
 (while 
   (not (= "SEQEND" (pl:dxf 0 (setq tmp_ent (entnext tmp_ent)))) 
   ) ;_ end of not 
    (progn 
      (setq vert_ent (nth i vertex_list) 
            vert_ent (subst (cons 40 (nth i end_width_list)) 
                            (assoc 40 vert_ent) 
                            vert_ent 
                     ) ;_ end of subst 
            vert_ent (subst (cons 41 (nth i start_width_list)) 
                            (assoc 41 vert_ent) 
                            vert_ent 
                     ) ;_ end of subst 
            vert_ent (subst (cons 42 (nth i bulge_list)) 
                            (assoc 42 vert_ent) 
                            vert_ent 
                     ) ;_ end of subst 
            i        (1+ i) 
      ) ;_ end of setq
      (entmakex vert_ent) 
    ) ;_ end of progn 
 ) ;_ end of while 
 (entmakex (cdr (entget tmp_ent))) ; seqend
 (entdel ent_name) 
 (redraw (entlast))
 (entlast)
) ;_ end of defun
(defun pl:dxf (code lst)
 (if (= (type lst) 'ENAME)
   (setq lst (entget lst)))
 (cdr (assoc code lst))
 )
(defun pl:clockwise-p  ( lw  / LST MAXP MINP)
(if (= (type lw) 'ENAME)
   (setq lw (vlax-ename->vla-object lw)))  
(vla-GetBoundingBox lw 'MinP 'MaxP)
(setq
minp(vlax-safearray->list minp)
MaxP(vlax-safearray->list MaxP)
lst(mapcar(function(lambda(x)
(vlax-curve-getParamAtPoint lw
(vlax-curve-getClosestPointTo lw x))))
(list minp(list(car minp)(cadr MaxP))
MaxP(list(car MaxP)(cadr minp)))))
(if(or
(<=(car lst)(cadr lst)(caddr lst)(cadddr lst))
(<=(cadr lst)(caddr lst)(cadddr lst)(car lst))
(<=(caddr lst)(cadddr lst)(car lst)(cadr lst))
(<=(cadddr lst)(car lst)(cadr lst)(caddr lst))) t nil))
(princ "\nType Pl-CW (ClockWise) or PL-CCW (CounterClockWise) in command line")

Posted

Man VVA!

 

You are the hero of the day.

I'm looking for months for this Lisp.

It works really well.

Could this be done without a window selection

as ssx .. Polyline ...

so that all the polylines of the entire drawing will be changed at once?

 

Many thanks for your help!

 

Greetings

 

Martin

 

Please excuse the English. My friend is the Google translator!

Posted
Man VVA!

Could this be done without a window selection

as ssx .. Polyline ...

so that all the polylines of the entire drawing will be changed at once?

Found (ssget "_:L" and replace (ssget "_ALL"

 

PS We have at least one common friend (Google translator) :)

Posted

I thing *reverse* command could make things upside down as needed. :)

 

Regards.

Posted

@ VVA

 

Ha Ha!

I like you!

Thanks worked great!

 

@ Tharwat

Reverse works like this unfortunately!

Thank you all!

 

Greetings

 

Martin

:D:D

Posted

Replacing (ssget "_: L" at (ssget "_ALL" before calling the command must be sure that the polylines are on unlocked layers

Posted

o.k.

 

Thanks!

 

lg Martin:)

Posted
Try it

(defun pl:clockwise-p (lw / LST MAXP MINP)
 (if (= (type lw) 'ENAME)
   (setq lw (vlax-ename->vla-object lw))
 )
 (vla-GetBoundingBox lw 'MinP 'MaxP)
 (setq
   minp (vlax-safearray->list minp)
   MaxP (vlax-safearray->list MaxP)
   lst  (mapcar (function (lambda (x)
                            (vlax-curve-getParamAtPoint
                              lw
                              (vlax-curve-getClosestPointTo lw x)
                            )
                          )
                )
                (list minp
                      (list (car minp) (cadr MaxP))
                      MaxP
                      (list (car MaxP) (cadr minp))
                )
        )
 )
 (if (or
       (<= (car lst) (cadr lst) (caddr lst) (cadddr lst))
       (<= (cadr lst) (caddr lst) (cadddr lst) (car lst))
       (<= (caddr lst) (cadddr lst) (car lst) (cadr lst))
       (<= (cadddr lst) (car lst) (cadr lst) (caddr lst))
     )
   t
   nil
 )
)

Just as a query, that checks the closest points on the polyline to each of the 4 corners of an imaginary rectangle surrounding the polyline. So it checks only 4 points from the outermost points. Usually this is ok, but what if the PL has lots of loops and even some cross-overs? What about something like this:
;;; Function to test if polyline is counter-clock-wise
;;; obj= vla-object / ename of the polyline
;;; Result is nil if clockwise, T if counter-clockwise
(defun PL-CounterClockWise-p (obj / ang ang1 ang2 angT param)
 (setq param 1.5
       angT  0.0
       ang1  (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv obj 0.5))
 )
 (while (< param (vlax-curve-getEndParam obj))
   (setq ang2 (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv obj param)))
   (setq ang (- ang2 ang1))
   (if (> (abs ang) pi)
     (setq ang (* (if (< ang 0.0) -1.0 1.0) (- (abs ang) (* pi 2))))
   )
   (setq angT  (+ angT ang)
         ang1  ang2
         param (1+ param)
   )
 )
 (>= angT 0.0)
)

I'm not sure which is "best", perhaps it doesn't matter :?

Posted

Hello Mr. Irneb.

 

I'm not Lispler.

 

How do I build this now is a Lisp in the above?

 

LG Martin

Posted (edited)

pl: clockwise-p - is transformed into a function of command C:LWCL ElpanovEvgeniy. I've been using it for a long time, but in the notes (translated Google) says:

And to heap checking directions crawl vertices, unlike many programs, gives the correct result in all difficult cases, however, if there is no intersection .

....

PS. Complicated cases I have called a polyline with a bunch of vertices in the middle, but outside of having only one arc segment, such as open ring, having at the inner circle of many segments, but only on the external one, and a very small width of the ...

Edited by VVA
actual link
Posted
I don't think that's possible, at least not without changing the appearance of the polyline or exploding it. E.g. see this image:

[ATTACH]27907[/ATTACH]

White line is the original PL, Red is exploded with yellow as reversed segments, Green is what you'll get by reversing the PL's vectors themselves - not what you're after (methinks).

You hit the nail, totally right.

 

After exploding the pline, reversing the specified segments and re-joining it to a pline it comes back to where it was. SO no solution possible I believe.

 

Thanks for the time!

Posted
How do I build this now is a Lisp in the above?
It's actually meant as a "replacement" for VVA's function pl:clockwise-p. But as he's indicated his function rarely goes wrong, only when the pl crosses itself "could" it show different. And because his would be quicker on long polylines I wouldn't bother changing.

 

After exploding the pline, reversing the specified segments and re-joining it to a pline it comes back to where it was. SO no solution possible I believe.
Not if you want to stick with polylines. The problem is that by definition a polyline consists of a number of vector points - the lines start where the previous vector ended. You could "possibly" force an old type of polyline (see the PLineType system variable) into something like this, since it is saved more like a block with sub-entities than the new LWPolyLines, but it's probably going to cause errors.

 

The only thing I can think of is to explode the PL, change the arcs & lines to suit, then either group / anomymous block them to make them into a "single" entity again. Perhaps something like this could then be added as an ARX custom object - so that it still works like a polyline (but that's going to be quite a lot of extra coding in C++).

Posted

Try new version

Added a few new commands and processing locked layers

(defun C:PL-CW()(Pl-CW-VVA "_:L" t));;;Clockwise

(defun C:PL-CCW()(Pl-CW-VVA "_:L" nil));;;CounterClockwise

(defun C:PL-CWA()(Pl-CW-VVA "_ALL" t));;;Clockwise ALL

(defun C:PL-CCWA()(Pl-CW-VVA "_ALL" nil));;;CounterClockwise ALL

(defun C:PLI-CCW()(Pl-CW-Irneb "_:L" nil));;;CounterClockwise Irneb version

(defun C:PLI-CW()(Pl-CW-Irneb "_:L" t));;;Clockwise Irneb version

(defun C:PL-CW()(Pl-CW-VVA "_:L" t));;;Clockwise
(defun C:PL-CCW()(Pl-CW-VVA "_:L" nil));;;CounterClockwise
(defun C:PL-CWA()(Pl-CW-VVA "_ALL" t));;;Clockwise ALL
(defun C:PL-CCWA()(Pl-CW-VVA "_ALL" nil));;;CounterClockwise ALL
(defun C:PLI-CCW()(Pl-CW-Irneb "_:L" nil));;;CounterClockwise Irneb version
(defun C:PLI-CW()(Pl-CW-Irneb "_:L" t));;;Clockwise Irneb version

(defun Pl-CW-Irneb ( mode what / int:i e1 res clk+ ss)
 ;;; posted Irneb
 ;;; url http://www.cadtutor.net/forum/showthread.php?59671-all-polylinienrichtungen-counterclockwise
 ;;; what - t Clockwise
 ;;; what - nil CounterClockwise
 ;;; mode - string for ssget "_:L" or "_ALL:
 (vl-load-com)
 (or  *pl-activedoc*
      (setq  *pl-activedoc* (vla-get-activedocument (vlax-get-acad-object))))
 (vla-startundomark  *pl-activedoc*)
 (princ (strcat "\n" (if what "Clockwise mode"  "CounterClockwise mode") " Select Polyline"))
 (setq ss nil
 ss (ssget mode '((0 . "*POLYLINE"))))
 (setq int:i '-1 clk+ 0)
 (while (and ss (setq e1 (ssname ss (setq int:i (1+ int:i)))))
   (if (vlax-write-enabled-p (vlax-ename->vla-object e1)) ;_editable
   (if what
     ;;;Reverse CounterClockwise->Clockwise
     (if (PL-CounterClockWise-p e1)
(progn
  (pl:geom-allpline-reverse e1)
  (setq clk+ (1+ clk+))
  )
)
     ;;;Reverse Clockwise->CounterClockwise
     (if (null (PL-CounterClockWise-p e1))
(progn
  (pl:geom-allpline-reverse e1)
  (setq clk+ (1+ clk+))
  )
)
     )
     )
 )
 (princ (strcat "\nCheck " (itoa int:i) " polyline."))
 (princ "\n\t")(princ clk+)(princ (if what  " \tCounterClockwise (reverse)" " \tClockwise (reverse)"))
 (princ "\n\t")(princ (- int:i clk+))(princ (if what " \tClockwise" " \tCounterClockwise"))
 (setq ss nil)(vla-endundomark  *pl-activedoc*) (princ))
(defun Pl-CW-VVA ( mode what / int:i e1 res clk+ ss)
 ;;; Posted VVA
 ;;; Url http://www.cadtutor.net/forum/showthread.php?59671-all-polylinienrichtungen-counterclockwise
 ;;; what - t Clockwise
 ;;; what - nil CounterClockwise
 (vl-load-com)
 (or  *pl-activedoc*
      (setq  *pl-activedoc* (vla-get-activedocument (vlax-get-acad-object))))
 (vla-startundomark  *pl-activedoc*)
 (princ (strcat "\n" (if what "Clockwise mode"  "CounterClockwise mode") " Select Polyline"))
 (setq ss nil
 ss (ssget mode '((0 . "*POLYLINE"))))
 (setq int:i '-1 clk+ 0)
 (while (and ss (setq e1 (ssname ss (setq int:i (1+ int:i)))))
   (if what
     ;;;Reverse CounterClockwise->Clockwise
     (if (null(pl:clockwise-p e1))
(progn
  (pl:geom-allpline-reverse e1)
  (setq clk+ (1+ clk+))
  )
)
     ;;;Reverse Clockwise->CounterClockwise
     (if (pl:clockwise-p e1)
(progn
  (pl:geom-allpline-reverse e1)
  (setq clk+ (1+ clk+))
  )
)
     )
 )
 (princ (strcat "\nCheck " (itoa int:i) " polyline."))
 (princ "\n\t")(princ clk+)(princ (if what  " \tCounterClockwise (reverse)" " \tClockwise (reverse)"))
 (princ "\n\t")(princ (- int:i clk+))(princ (if what " \tClockwise" " \tCounterClockwise"))
 (setq ss nil)(vla-endundomark  *pl-activedoc*) (princ))
(defun pl:geom-allpline-reverse ( pl / pln ret)
 (if (= (type pl) 'VLA-OBJECT)
   (setq pln (vlax-vla-object->ename pl))
   (setq pln pl))
 (cond ((= (pl:dxf 0 (entget pln)) "LWPOLYLINE")
 (setq ret (pl:geom-LWpolyline-revers pln)))
((= (pl:dxf 0 (entget pln)) "POLYLINE")
 (setq ret (pl:geom-polyline-revers  pln)))
(t (setq ret nil))
)
 ret
 )
(defun pl:geom-LWpolyline-revers ( lw / e x1 x2 x3 x4 x5 x6)
 (if (= (type lw) 'VLA-OBJECT)
   (setq lw (vlax-vla-object->ename lw)))
   (setq e (entget lw ))
(foreach a1 e 
  (cond 
    ((= (car a1) 10) (setq x2 (cons a1 x2))) 
    ((= (car a1) 40) (setq x4 (cons (cons 41 (cdr a1)) x4))) 
    ((= (car a1) 41) (setq x3 (cons (cons 40 (cdr a1)) x3))) 
    ((= (car a1) 42) (setq x5 (cons (cons 42 (- (cdr a1))) x5))) 
    ((= (car a1) 210) (setq x6 (cons a1 x6))) 
    (t (setq x1 (cons a1 x1))) 
    ) ;_ end of cond 
  )
(entmod (append(reverse x1)(append(apply(function append)
 (apply (function mapcar)(cons 'list (list x2 
        (cdr (reverse (cons (car x3) (reverse x3)))) 
        (cdr (reverse (cons (car x4) (reverse x4)))) 
        (cdr (reverse (cons (car x5) (reverse x5)))) 
        ) ;_ end of list 
       ) ;_ end of cons 
     ) ;_ end of apply 
        ) ;_ end of apply 
      x6 
      ) ;_ end of append 
    ) ;_ end of append 
  ) ;_ end of entmod 
 (entupd lw) 
 ) ;_ end of defun
(defun pl:geom-polyline-revers  
                              (ent_name        / 
                               _dxf-code-data  tmp_ent 
                               i               poly_ent 
                               vert_ent        vertex_list 
                               bulge_list      start_width_list 
                               end_width_list 
                              )
(if (= (type ent_name) 'VLA-OBJECT)
   (setq ent_name (vlax-vla-object->ename ent_name)))
 ;; Reverse "POLYLINE" 
 (setq tmp_ent ent_name 
         i       0 
 ) ;_ end of setq
 (setq bulge_list nil vertex_list nil start_width_list nil end_width_list nil)
 (while 
   (not (= "SEQEND" (pl:dxf 0 (setq tmp_ent (entnext tmp_ent))))) ;_ end of not 
    (setq bulge_list 
           (cons (pl:dxf 42 tmp_ent) bulge_list) 
          vertex_list 
           (cons (entget tmp_ent) vertex_list) 
          start_width_list 
           (cons (pl:dxf 40 tmp_ent) 
                 start_width_list 
           ) ;_ end of cons 
          end_width_list 
           (cons (pl:dxf 41 tmp_ent) end_width_list) 
          i (1+ i) 
    ) ;_ end of setq 
 ) ;_ end of while
 
 (setq
       bulge_list       (append (cdr bulge_list) (list (car bulge_list))) 
       start_width_list (append (cdr start_width_list) 
                                (list (car start_width_list)) 
                        ) ;_ end of append 
       end_width_list   (append (cdr end_width_list) 
                                (list (car end_width_list)) 
                        ) ;_ end of append
       i                0
       bulge_list       (mapcar '(lambda (x) (- 0 x)) bulge_list) 
       tmp_ent          ent_name 
       poly_ent         (cdr (entget tmp_ent '("*"))) ;;;Added to revers with XData
       poly_ent         (subst (cons 40 (car end_width_list)) 
                               (assoc 40 poly_ent) 
                               poly_ent 
                        ) ;_ end of subst 
       poly_ent         (subst (cons 41 (last start_width_list)) 
                               (assoc 41 poly_ent) 
                               poly_ent 
                        ) ;_ end of subst 
 ) ;_ end of setq 
 (entmakex poly_ent)          ; polyline
 (while 
   (not (= "SEQEND" (pl:dxf 0 (setq tmp_ent (entnext tmp_ent)))) 
   ) ;_ end of not 
    (progn 
      (setq vert_ent (nth i vertex_list) 
            vert_ent (subst (cons 40 (nth i end_width_list)) 
                            (assoc 40 vert_ent) 
                            vert_ent 
                     ) ;_ end of subst 
            vert_ent (subst (cons 41 (nth i start_width_list)) 
                            (assoc 41 vert_ent) 
                            vert_ent 
                     ) ;_ end of subst 
            vert_ent (subst (cons 42 (nth i bulge_list)) 
                            (assoc 42 vert_ent) 
                            vert_ent 
                     ) ;_ end of subst 
            i        (1+ i) 
      ) ;_ end of setq
      (entmakex vert_ent) 
    ) ;_ end of progn 
 ) ;_ end of while 
 (entmakex (cdr (entget tmp_ent))) ; seqend
 (entdel ent_name) 
 (redraw (entlast))
 (entlast)
) ;_ end of defun
(defun pl:dxf (code lst)
 (if (= (type lst) 'ENAME)
   (setq lst (entget lst)))
 (cdr (assoc code lst))
 )

;;; Function to test if polyline is counter-clock-wise
;;; obj= vla-object / ename of the polyline
;;; Result is nil if clockwise, T if counter-clockwise
(defun PL-CounterClockWise-p (obj / ang ang1 ang2 angT param)
 (if (= (type Obj) 'ENAME)(setq Obj (vlax-ename->vla-object Obj)))  
 (setq param 1.5
       angT  0.0
       ang1  (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv obj 0.5))
 )
 (while (< param (vlax-curve-getEndParam obj))
   (setq ang2 (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv obj param)))
   (setq ang (- ang2 ang1))
   (if (> (abs ang) pi)
     (setq ang (* (if (< ang 0.0) -1.0 1.0) (- (abs ang) (* pi 2))))
   )
   (setq angT  (+ angT ang)
         ang1  ang2
         param (1+ param)
   )
 )
 (>= angT 0.0)
)
(defun pl:clockwise-p  ( lw  / LST MAXP MINP)
(if (= (type lw) 'ENAME)
   (setq lw (vlax-ename->vla-object lw)))  
(vla-GetBoundingBox lw 'MinP 'MaxP)
(setq
minp(vlax-safearray->list minp)
MaxP(vlax-safearray->list MaxP)
lst(mapcar(function(lambda(x)
(vlax-curve-getParamAtPoint lw
(vlax-curve-getClosestPointTo lw x))))
(list minp(list(car minp)(cadr MaxP))
MaxP(list(car MaxP)(cadr minp)))))
(if(or
(<=(car lst)(cadr lst)(caddr lst)(cadddr lst))
(<=(cadr lst)(caddr lst)(cadddr lst)(car lst))
(<=(caddr lst)(cadddr lst)(car lst)(cadr lst))
(<=(cadddr lst)(car lst)(cadr lst)(caddr lst))) t nil))
(princ "\nType Pl-CW, PL-CWA (ClockWise) or PL-CCW, PL-CCWA (CounterClockWise) in command line")
(princ "\nFor difficult cases with a polyline use PlI-CW (ClockWise) or PLI-CCW (CounterClockWise) in command line")
(princ)

Posted

@ VVA

 

They are truly a master of their craft!

 

Thank you!

 

LG Martin

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