Author Topic: change direction to start and arc LWPOLYLINE  (Read 5267 times)

0 Members and 1 Guest are viewing this topic.

TopoWAR

  • Newt
  • Posts: 135
change direction to start and arc LWPOLYLINE
« on: July 27, 2014, 08:28:32 PM »
hi all, any of you have a routine to change the start and direction of the polyline? but this polyline contains arcs, the try but could not, I was hindered much of the codes 40 41 42, maybe if someone has something? thank you very much
PS: I tried to do it but I could not. :-(
Thanks for help

Crank

  • Water Moccasin
  • Posts: 1503
Re: change direction to start and arc LWPOLYLINE
« Reply #1 on: July 28, 2014, 02:41:50 AM »
There are many lisp routines that can do this, also here on the Swamp.

If you want to write your own, you should look at the REVERSE command and the PLINEREVERSEWIDTHS variable.
Study the dxf-codes what has changed before and after the command has been applied to the polyline.
Vault Professional 2023     +     AEC Collection

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: change direction to start and arc LWPOLYLINE
« Reply #2 on: July 28, 2014, 07:23:26 AM »
Reverse "LWPOLYLINE"

 :-)
Code - Auto/Visual Lisp: [Select]
  1. (defun c:rlw (/ E LW X1 X2 X3 X4 X5 X6)
  2. ;; Reverse "LWPOLYLINE"
  3. ;; by ElpanovEvgeniy
  4.   (if (and (setq lw (car (entsel "\nSelect lwpolyline")))
  5.            (= (cdr (assoc 0 (setq e (entget lw)))) "LWPOLYLINE")
  6.       ) ;_  and
  7.     (progn
  8.       (foreach a1 e
  9.         (cond
  10.           ((= (car a1) 10) (setq x2 (cons a1 x2)))
  11.           ((= (car a1) 40) (setq x4 (cons (cons 41 (cdr a1)) x4)))
  12.           ((= (car a1) 41) (setq x3 (cons (cons 40 (cdr a1)) x3)))
  13.           ((= (car a1) 42) (setq x5 (cons (cons 42 (- (cdr a1))) x5)))
  14.           ((= (car a1) 210) (setq x6 (cons a1 x6)))
  15.           (t (setq x1 (cons a1 x1)))
  16.         ) ;_  cond
  17.       ) ;_  foreach
  18.       (entmod
  19.         (append
  20.           (reverse x1)
  21.           (append
  22.             (apply
  23.               (function append)
  24.               (apply
  25.                 (function mapcar)
  26.                 (cons
  27.                   'list
  28.                   (list x2
  29.                         (cdr (reverse (cons (car x3) (reverse x3))))
  30.                         (cdr (reverse (cons (car x4) (reverse x4))))
  31.                         (cdr (reverse (cons (car x5) (reverse x5))))
  32.                   ) ;_  list
  33.                 ) ;_  cons
  34.               ) ;_  apply
  35.             ) ;_  apply
  36.             x6
  37.           ) ;_  append
  38.         ) ;_  append
  39.       ) ;_  entmod
  40.       (entupd lw)
  41.     ) ;_  progn
  42.   ) ;_  if
  43. ) ;_  defun


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: change direction to start and arc LWPOLYLINE
« Reply #3 on: July 28, 2014, 08:45:36 AM »
There are several routines here at the Swamp to do that but you will not find more elegant code than from Evgeniy.  8)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

TopoWAR

  • Newt
  • Posts: 135
Re: change direction to start and arc LWPOLYLINE
« Reply #4 on: July 28, 2014, 04:22:02 PM »
thanks, I'm going to study the information, but what I want is complicated and I'm getting there.
1 - choose which one is the vertex
2 - choose the direction
Thanks for help

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: change direction to start and arc LWPOLYLINE
« Reply #5 on: July 28, 2014, 09:18:30 PM »
Can you post a picture or DWG file with a before & after of what you want?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

TopoWAR

  • Newt
  • Posts: 135
Re: change direction to start and arc LWPOLYLINE
« Reply #6 on: July 28, 2014, 09:32:34 PM »
Hello, after trying for a whole day I managed to work, it is a routine that by biting on a point choose the closest and put it as vertex 1 in the polyline, also depending on the side where pique that will mean the polyline, I have set a code to be seen, it is important to replace dos_ functions for alert or princ, is that the code is not very fine but it does the trick. thanks and if anyone can improve it better! :lol:


Code: [Select]
(defun c:test (/ BUCLE   CONT    COORD   D1      D2      DIST_INICIO     ENAME   ENTIDAD INFO    INICIO  NTHLIST P1
      P2      PO      PTO_INI SENTIDO SS      TIPO    X1      X2      X2_N    X3      X4      X5      X5_N
      X6)
  ;seleccionar la polylinea
  (setvar "osmode" 512)
  (setq ss nil)
  (while (= ss nil)
    (setq po (getpoint "\nSeleccione la Polylínea Cerrada.\n1- Cerca del Inicio 2- Elija la Dirección."))
    (if (/= po nil)
      (setq ss (ssget po))
    )
  )
  (setq entidad (cons (ssname ss 0) (list po)))
  (if entidad
    (if (or (= (cdr (assoc 0 (entget (car entidad)))) "POLYLINE")
    (= (cdr (assoc 0 (entget (car entidad)))) "LWPOLYLINE"))
      (if (= (setq tipo (cdr (assoc 0 (entget (car entidad))))) "POLYLINE")
(if (= (cdr (assoc 100 (reverse (entget (car entidad))))) "AcDb3dPolyline")
  (progn (dos_msgbox "La Entidad que Seleccionó no es Polylínea 2D" "TopoWAR" 1 3) (exit))
  (if (= (getvar "product") "AutoCAD")
    (progn (command "_convertpoly" "l" (car entidad) "") (setq entidad (cons (entlast) (list (cadr entidad)))))
    (progn (convertpoly_bricscad (car entidad) "l") (setq entidad (cons (entlast) (list (cadr entidad)))))
  )
)
      )
      (progn (dos_msgbox "La Entidad que Seleccionó no es Polylínea" "TopoWAR" 1 3) (exit))
    )
    (progn (dos_msgbox "No seleccionó Nada." "TopoWAR" 1 3) (exit))
  )
 
  (setq tipo   (cdr (assoc 0 (entget (car entidad))))
ename  (car entidad)
inicio (cadr entidad)
info   (entget ename))
 
  (if (/= (cdr (assoc 70 info)) 1)
    (progn
      (dos_msgbox "La Polylínea no está Cerrada." "TopoWAR" 1 3)
      (exit)
    )
  )
     
  (setq x1 nil
x2 nil
x3 nil
x4 nil
x5 nil
x6 nil)
 
  (foreach a1 info
        (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)))
        ) ;_  cond
      )
  (setq x1 (reverse x1)
x2 (reverse x2)
;;; x3 (reverse x3)
;;; x4 (reverse x4)
x5 (reverse x5))
  ;localizar el punto
  (setq dist_inicio (vlax-curve-getDistAtPoint ename inicio))
  ;localizar el sentido!
  (setq cont 0
bucle t
coord (append x2 (list (nth 0 x2))))
  (while (and bucle (<= cont (- (length coord) 2)))
    (setq p1 (cdr (nth cont coord))
  p2 (cdr (nth (1+ cont) coord))
  d1 (vlax-curve-getDistAtParam ename cont)
  d2 (vlax-curve-getDistAtParam ename (1+ cont)))
    (if (and (>= dist_inicio d1) (<= dist_inicio d2))
      (if (< (- dist_inicio d1) (- d2 dist_inicio))
(setq sentido "derecha"
      nthlist cont
      pto_ini p1
      bucle nil)
(setq sentido "izquierda"
      nthlist (1+ cont)
      pto_ini p2
      bucle nil)
      )
    )
    (setq cont (1+ cont))
  )
  (if (= nthlist (1- (length coord)))
    (setq nthlist 0)
  )
  ;formar los nuevos datos
  (setq cont nthlist
x2_n nil
;;; x3_n nil
;;; x4_n nil
x5_n nil)
 
  (if (= sentido "izquierda")
    (progn
      ;coord
      (while (>= cont 0)
(setq x2_n (append x2_n (list (nth cont x2)))
      cont (1- cont))
      )
      (setq cont (1- (length x2)))
      (while (> cont nthlist)
(setq x2_n (append x2_n (list (nth cont x2)))
      cont (1- cont))
      )
      ;arcos
      (setq cont (1- nthlist))
      (if (< cont 0) (setq cont (1- (length x5))))
      (repeat (length x5)
(setq x5_n (append x5_n (list (nth cont x5)))
      cont (1- cont))
(if (< cont 0) (setq cont (1- (length x5))))
      )
    )
    (progn
      ;coord
      (while (<= cont (1- (length x2)))
(setq x2_n (append x2_n (list (nth cont x2)))
      x5_n (append x5_n (list (cons 42 (- (cdr (nth cont x5))))))
      cont (1+ cont))
      )
      (setq cont 0)
      (while (< cont nthlist)
(setq x2_n (append x2_n (list (nth cont x2)))
      x5_n (append x5_n (list (cons 42 (- (cdr (nth cont x5))))))
      cont (1+ cont))
      )
    )
  )
  (setq X2 X2_N
X5 X5_N)
  (entmod
        (append
          x1
          (append
            (apply
              (function append)
              (apply
                (function mapcar)
                (cons
                  'list
                  (list x2
;;;                        (cdr (cons (car x3)  x3))
;;;                        (cdr (cons (car x4)  x4))
                        (cdr (cons (car x5)  x5))
                  ) ;_  list
                ) ;_  cons
              ) ;_  apply
            ) ;_  apply
            x6
          ) ;_  append
        ) ;_  append
      ) ;_  entmod
      (entupd ename)
  (princ "\nListo...Polylínea Modificada.") (princ)
);fin defun
 

 
 
 

 

 
;|«Visual LISP© Format Options»
(120 2 40 0 nil "end of " 100 20 1 2 0 T nil nil T)
;*** DO NOT add text below the comment! ***|;
« Last Edit: July 28, 2014, 09:49:57 PM by TopoWAR »
Thanks for help

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: change direction to start and arc LWPOLYLINE
« Reply #7 on: July 28, 2014, 11:26:00 PM »
Read this thread
Look for Gile's routine
http://www.theswamp.org/index.php?topic=18720.0
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

TopoWAR

  • Newt
  • Posts: 135
Re: change direction to start and arc LWPOLYLINE
« Reply #8 on: July 29, 2014, 11:44:20 AM »
CAB, the very good routine of gile, but I did not try to add a vertex, look at the code in execution:
1 - depending where click, that will be the vertex 1 of the polyline.
2 - depending on where that will be click the sense of vertices, 1 2 3 4 ....


me and mine code works fine, but I guess you can improve
Thanks for help

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: change direction to start and arc LWPOLYLINE
« Reply #9 on: July 30, 2014, 07:09:09 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun C:T1 (/ E LW P)
  2.   ;;
  3.   ;; by ElpanovEvgeniy
  4.   (if (and (setq P (entsel "\nSelect lwpolyline"))
  5.            (setq LW (car P))
  6.            (= (cdr (assoc 0 (setq E (entget LW)))) "LWPOLYLINE")
  7.            (setq P (vlax-curve-getpointatparam
  8.                      LW
  9.                      (fix (vlax-curve-getparamatpoint LW (vlax-curve-getclosestpointto LW (cadr P))))
  10.                      )
  11.                  P (list 10 (car P) (cadr P))
  12.                  )
  13.            )
  14.     (progn (entmod (append (reverse (member (assoc 39 E) (reverse E)))
  15.                            (reverse (cdr (reverse (member P E))))
  16.                            (reverse (cdr (member P (reverse (member (assoc 10 E) E)))))
  17.                            (list (last E))
  18.                            )
  19.                    )
  20.            (entupd LW)
  21.            )
  22.     )
  23.   )

TopoWAR

  • Newt
  • Posts: 135
Re: change direction to start and arc LWPOLYLINE
« Reply #10 on: July 30, 2014, 01:32:05 PM »
hello ElpanovEvgeniy, you who know a lot about this maybe you can help me calculate the data of an arc in a LWPOLYLINE, review the information in there is only information LWPOLYLINE bow in the code 42, but I require this post:
1 - delta
2 - Radio
3 - tangent
4 - arc length
5 - distance p1 to p2, (arc)

I have the code to calculate this but a target, but not how to do it
in an arc LWPOLYLINE, appreciate if you help me, because only I have the information of the code 42 of the polyline, thanks
view uploaded files!

and I need less
RADIO:
Code: [Select]
;; Bulge Radius  -  Lee Mac
;; p1 - start vertex
;; p2 - end vertex
;; b  - bulge
;; Returns the radius of the arc described by the given bulge and vertices
 
(defun LM:BulgeRadius ( p1 p2 b )
    (/ (* (distance p1 p2) (1+ (* b b))) 4 (abs b))
DELTA Y TANGENT ?????? :-(
« Last Edit: July 30, 2014, 03:29:36 PM by TopoWAR »
Thanks for help

TopoWAR

  • Newt
  • Posts: 135
Re: change direction to start and arc LWPOLYLINE
« Reply #11 on: July 30, 2014, 03:45:24 PM »
and I managed to perform all calculations occupied, but I only need one, as is done to calculate the area of the arc?? can someone help me with this, thanks!
Thanks for help

ronjonp

  • Needs a day job
  • Posts: 7529
Re: change direction to start and arc LWPOLYLINE
« Reply #12 on: July 30, 2014, 03:54:22 PM »
Code: [Select]
(defun _getarea (object)
  (if (and (= (type object) 'vla-object) (vlax-property-available-p object 'area))
    (vla-get-area object)
    0
  )
)
;; (_getarea (vlax-ename->vla-object (car (entsel))))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

TopoWAR

  • Newt
  • Posts: 135
Re: change direction to start and arc LWPOLYLINE
« Reply #13 on: July 30, 2014, 04:02:02 PM »
ronjonp  , thanks for the reply, what happens is that the bow is in a lwpolylinea, we only have this data:

Code: [Select]
;; Bulge to Arc  -  Lee Mac
;; p1 - start vertex
;; p2 - end vertex
;; b  - bulge
;; Returns: (<center> <start angle> <end angle> <radius>)
(defun LM:Bulge->Arc ( p1 p2 b / c r )
    (setq r (/ (* (distance p1 p2) (1+ (* b b))) 4 b)
          c (polar p1 (+ (angle p1 p2) (- (/ pi 2) (* 2 (atan b)))) r)
    )
    (if (minusp b)
        (list c (angle c p2) (angle c p1) (abs r))
        (list c (angle c p1) (angle c p2) (abs r))
    )
)

is possible to calculate the area of this arc using this data retorma routine "lee mac"???
Thanks for help

ronjonp

  • Needs a day job
  • Posts: 7529
Re: change direction to start and arc LWPOLYLINE
« Reply #14 on: July 30, 2014, 04:27:55 PM »
Code: [Select]
(/ (* RADIUS ARCLENGTH) 2.)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC