Author Topic: REVERSE curve  (Read 3859 times)

0 Members and 1 Guest are viewing this topic.

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
REVERSE curve
« on: April 23, 2017, 01:49:31 PM »
Hi, recently I coded some sub functions for reversing some curve types, but I have a question about old heavy 2d polyline and splined 3d polyline... I want to have all possible options for reversing curves collected as I want to use and also old CAD releases that didn't have REVERSE command implemented...

Here is what I have now :

Code: [Select]
(defun rlw ( LW / E X1 X2 X3 X4 X5 X6 )
  ;; by ElpanovEvgeniy
  ;; reverse lwpolyline
  (if (= (cdr (assoc 0 (setq e (entget lw)))) "LWPOLYLINE")
    (progn (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)))
             )
           )
           (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))))
                                                       )
                                                 )
                                          )
                                   )
                                   x6
                           )
                   )
           )
           (entupd lw)
    )
  )
)

Code: [Select]
;; Reverse SPLINE - Marko Ribar, d.i.a.
(defun rspl ( spl / enx x12 x13 x1 x2 x3 x4 x5 )
  (if (= (cdr (assoc 0 (setq enx (entget spl)))) "SPLINE")
    (progn
      (foreach a1 enx
        (cond
          ( (= (car a1) 12) (setq x13 (cons (cons 13 (mapcar '- (cdr a1))) x13)) )
          ( (= (car a1) 13) (setq x12 (cons (cons 12 (mapcar '- (cdr a1))) x12)) )
          ( (= (car a1) 40) (setq x2 (cons a1 x2)) )
          ( (= (car a1) 10) (setq x3 (cons a1 x3)) )
          ( (= (car a1) 41) (setq x4 (cons a1 x4)) )
          ( (= (car a1) 11) (setq x5 (cons a1 x5)) )
          ( t (setq x1 (cons a1 x1)) )
        )
      )
      (entmod
        (append
          (reverse x1)
          x12
          x13
          (mapcar '(lambda ( x ) (cons 40 (- (cdar x2) (cdr x)))) x2)
          (if x4
            (apply 'append (mapcar '(lambda ( a b ) (list a b)) x3 x4))
            x3
          )
          x5
        )
      )
      (entupd spl)
    )
  )
)

Code: [Select]
;; Reverse HELIX - Marko Ribar, d.i.a.
(defun rhel ( hel / enx enx1 enx2 v x1 x2 x3 )
  (if (= (cdr (assoc 0 (setq enx (entget hel)))) "HELIX")
    (progn
      (setq enx1 (reverse (cdr (member '(100 . "AcDbHelix") (reverse enx)))))
      (setq enx2 (member '(100 . "AcDbHelix") enx))
      (foreach a1 enx1
        (cond
          ( (= (car a1) 40) (setq x2 (cons a1 x2)) )
          ( (= (car a1) 10) (setq x3 (cons a1 x3)) )
          ( t (setq x1 (cons a1 x1)) )
        )
      )
      (setq enx2 (subst (cons 40 (distance (cdr (assoc 10 enx2)) (cdr (assoc 11 enx2)))) (assoc 40 enx2) enx2))
      (setq enx2 (subst (cons 10 (mapcar '+ (cdr (assoc 10 enx2)) (mapcar '* (cdr (assoc 12 enx2)) (list (* (cdr (assoc 41 enx2)) (cdr (assoc 42 enx2))) (* (cdr (assoc 41 enx2)) (cdr (assoc 42 enx2))) (* (cdr (assoc 41 enx2)) (cdr (assoc 42 enx2))))))) (assoc 10 enx2) enx2))
      (setq enx2 (subst (cons 11 (cdr (car x3))) (assoc 11 enx2) enx2))
      (setq enx2 (subst (cons 12 (mapcar '- (cdr (assoc 12 enx2)))) (assoc 12 enx2) enx2))
      (entmod
        (append
          (reverse x1)
          (mapcar '(lambda ( x ) (cons 40 (- (cdar x2) (cdr x)))) x2)
          x3
          enx2
        )
      )
      (entupd hel)
    )
  )
)

Code: [Select]
;; Reverse LINE - Marko Ribar, d.i.a.
(defun rli ( li / enx sp ep )
  (if (= (cdr (assoc 0 (setq enx (entget li)))) "LINE")
    (progn
      (setq sp (cdr (assoc 10 enx)) ep (cdr (assoc 11 enx)))
      (setq enx (subst (cons 10 ep) (assoc 10 enx) enx))
      (setq enx (subst (cons 11 sp) (assoc 11 enx) enx))
      (entmod enx)
      (entupd li)
    )
  )
)

Code: [Select]
;; Reverse 3DPOLYLINE - Marko Ribar, d.i.a.
(defun r3dp ( 3dp / v p pl sfa var )

  (vl-load-com)

  (if
    (and
      (= (cdr (assoc 0 (entget 3dp))) "POLYLINE")
      (< 7 (cdr (assoc 70 (entget 3dp))) 10)
    )
    (progn
      (setq v 3dp)
      (while (= (cdr (assoc 0 (entget (setq v (entnext v))))) "VERTEX")
        (setq p (cdr (assoc 10 (entget v))))
        (setq pl (cons p pl))
      )
      (setq pl (apply 'append pl))
      (setq sfa (vlax-make-safearray vlax-vbdouble (cons 0 (1- (length pl)))))
      (vlax-safearray-fill sfa pl)
      (setq var (vlax-make-variant sfa))
      (vla-put-coordinates (vlax-ename->vla-object 3dp) var)
      (entupd 3dp)
    )
  )
)

Thanks for attention,
regards, M.R.
« Last Edit: April 23, 2017, 04:41:53 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: REVERSE curve
« Reply #1 on: April 25, 2017, 08:56:07 AM »
Just to inform you - I did find a solution to this topic, but I thought someone will help me - guide me in right direction... My solution is little bit cumbersome - for old 2d heavy polyline it uses command "CONVERTPOLY", but it works just like I wanted - ename is preserved and doesn't change after reversing...

Code: [Select]
;; Reverse old heavy 2d POLYLINE - Marko Ribar, d.i.a.
(defun rhpl ( hpl / rlw )

  (vl-load-com)

  (defun rlw ( LW / E X1 X2 X3 X4 X5 X6 )
    ;; by ElpanovEvgeniy
    ;; reverse lwpolyline
    (if (= (cdr (assoc 0 (setq e (entget lw)))) "LWPOLYLINE")
      (progn (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)))
               )
             )
             (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))))
                                                         )
                                                   )
                                            )
                                     )
                                     x6
                             )
                     )
             )
             (entupd lw)
      )
    )
  )

  (if
    (and
      (= (cdr (assoc 0 (entget hpl))) "POLYLINE")
      (or
        (< -1 (cdr (assoc 70 (entget hpl))) 6)
        (< 127 (cdr (assoc 70 (entget hpl))) 134)
      )
    )
    (progn
      (cond
        ( (or (< -1 (cdr (assoc 70 (entget hpl))) 2) (< 127 (cdr (assoc 70 (entget hpl))) 130))
          (command "_.CONVERTPOLY" "_L" hpl "")
          (rlw hpl)
          (command "_.CONVERTPOLY" "_H" hpl "")
          (entupd hpl)
        )
        ( (or (< 1 (cdr (assoc 70 (entget hpl))) 4) (< 129 (cdr (assoc 70 (entget hpl))) 132))
          (vla-put-type (vlax-ename->vla-object hpl) (- (vla-get-type (vlax-ename->vla-object hpl)) 1))
          (command "_.CONVERTPOLY" "_L" hpl "")
          (rlw hpl)
          (command "_.CONVERTPOLY" "_H" hpl "")
          (vla-put-type (vlax-ename->vla-object hpl) (+ (vla-get-type (vlax-ename->vla-object hpl)) 1))
          (entupd hpl)
        )
        ( (and (or (< 3 (cdr (assoc 70 (entget hpl))) 6) (< 131 (cdr (assoc 70 (entget hpl))) 134)) (= (cdr (assoc 75 (entget hpl))) 5))
          (vla-put-type (vlax-ename->vla-object hpl) (- (vla-get-type (vlax-ename->vla-object hpl)) 2))
          (command "_.CONVERTPOLY" "_L" hpl "")
          (rlw hpl)
          (command "_.CONVERTPOLY" "_H" hpl "")
          (vla-put-type (vlax-ename->vla-object hpl) (+ (vla-get-type (vlax-ename->vla-object hpl)) 2))
          (entupd hpl)
        )
        ( (and (or (< 3 (cdr (assoc 70 (entget hpl))) 6) (< 131 (cdr (assoc 70 (entget hpl))) 134)) (= (cdr (assoc 75 (entget hpl))) 6))
          (vla-put-type (vlax-ename->vla-object hpl) (- (vla-get-type (vlax-ename->vla-object hpl)) 3))
          (command "_.CONVERTPOLY" "_L" hpl "")
          (rlw hpl)
          (command "_.CONVERTPOLY" "_H" hpl "")
          (vla-put-type (vlax-ename->vla-object hpl) (+ (vla-get-type (vlax-ename->vla-object hpl)) 3))
          (entupd hpl)
        )
      )
    )
  )
)

Code: [Select]
;; Reverse 3DPOLYLINE - Marko Ribar, d.i.a.
(defun r3dp ( 3dp / r3dppol typ )

  (defun r3dppol ( 3dp / v p pl sfa var )

    (vl-load-com)

    (setq v 3dp)
    (while (= (cdr (assoc 0 (entget (setq v (entnext v))))) "VERTEX")
      (setq p (cdr (assoc 10 (entget v))))
      (setq pl (cons p pl))
    )
    (setq pl (apply 'append pl))
    (setq sfa (vlax-make-safearray vlax-vbdouble (cons 0 (1- (length pl)))))
    (vlax-safearray-fill sfa pl)
    (setq var (vlax-make-variant sfa))
    (vla-put-coordinates (vlax-ename->vla-object 3dp) var)
    (entupd 3dp)
  )

  (setq typ (vla-get-type (vlax-ename->vla-object 3dp)))
  (vla-put-type (vlax-ename->vla-object 3dp) acsimplepoly)
  (r3dppol 3dp)
  (if typ (vla-put-type (vlax-ename->vla-object 3dp) typ))
  (entupd 3dp)
)

HTH., M.R.
 8-)
« Last Edit: April 28, 2017, 05:24:56 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: REVERSE curve
« Reply #2 on: April 25, 2017, 02:59:58 PM »
For reversing 'heavy' and 'lw' polylines I use:
Code - Auto/Visual Lisp: [Select]
  1. ; (KGA_List_Divide_2 '(0 1 2 3 4 5 6 7 8 9)) => ((0 1) (2 3) (4 5) (6 7) (8 9))
  2. ; (KGA_List_Divide_2 '(0 1 2 3 4 5 6 7 8))   => ((0 1) (2 3) (4 5) (6 7))
  3. (defun KGA_List_Divide_2 (lst / ret)
  4.   (repeat (/ (length lst) 2)
  5.     (setq ret (cons (list (car lst) (cadr lst)) ret))
  6.     (setq lst (cddr lst))
  7.   )
  8.   (reverse ret)
  9. )
  10.  
  11. ; (KGA_List_Divide_3 '(0 1 2 3 4 5 6 7 8)) => ((0 1 2) (3 4 5) (6 7 8))
  12. ; (KGA_List_Divide_3 '(0 1 2 3 4 5 6 7))   => ((0 1 2) (3 4 5))
  13. (defun KGA_List_Divide_3 (lst / ret)
  14.   (repeat (/ (length lst) 3)
  15.     (setq ret (cons (list (car lst) (cadr lst) (caddr lst)) ret))
  16.     (setq lst (cdddr lst))
  17.   )
  18.   (reverse ret)
  19. )
  20.  
  21. ; Make a zero based list of integers.
  22. ; With speed improvement based on Reini Urban's (std-%setnth).
  23. ; (KGA_List_IndexSeqMakeLength 7) => (0 1 2 3 4 5 6)
  24. (defun KGA_List_IndexSeqMakeLength (len / ret)
  25.   (repeat (rem len 4)
  26.     (setq ret (cons (setq len (1- len)) ret))
  27.   )
  28.   (repeat (/ len 4)
  29.     (setq ret
  30.       (vl-list*
  31.         (- len 4)
  32.         (- len 3)
  33.         (- len 2)
  34.         (- len 1)
  35.         ret
  36.       )
  37.     )
  38.     (setq len (- len 4))
  39.   )
  40.   ret
  41. )
  42.  
  43. ; Obj must be an "AcDb2dPolyline" of the acsimplepoly type or an "AcDbPolyline".
  44. ; (KGA_Geom_PolylineReverse (vlax-ename->vla-object (car (entsel))))
  45. (defun KGA_Geom_PolylineReverse (obj / bulgeLst idxLst ptLst widLst)
  46.   (setq ptLst
  47.     ((if (= "AcDb2dPolyline" (vla-get-objectname obj)) KGA_List_Divide_3 KGA_List_Divide_2)
  48.       (vlax-get obj 'coordinates)
  49.     )
  50.   )
  51.   (setq idxLst (KGA_List_IndexSeqMakeLength (length ptLst)))
  52.   (setq bulgeLst
  53.     (mapcar
  54.       '(lambda (idx) (vla-getbulge obj idx))
  55.       idxLst
  56.     )
  57.   )
  58.   (setq widLst
  59.     (mapcar
  60.       '(lambda (idx / widSta widEnd)
  61.         (vla-getwidth obj idx 'widSta 'widEnd)
  62.         (list widSta widEnd)
  63.       )
  64.       idxLst
  65.     )
  66.   )
  67.   (mapcar
  68.     '(lambda (idx pt bulge widSub)
  69.       (vlax-put obj 'coordinate idx pt)
  70.       (vla-setbulge obj idx (- bulge))
  71.       (vla-setwidth obj idx (cadr widSub) (car widSub))
  72.     )
  73.     idxLst
  74.     (reverse ptLst)
  75.     (append (cdr (reverse bulgeLst)) (list (car bulgeLst)))
  76.     (append (cdr (reverse widLst)) (list (car widLst)))
  77.   )
  78. )

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: REVERSE curve
« Reply #3 on: April 26, 2017, 02:07:37 AM »
@Roy, that was not the problem. The problem was reversing splined 2d polyline... As you know there are 3 types beside normal one : curve fit, quadratic and qubic...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: REVERSE curve
« Reply #4 on: April 26, 2017, 03:38:54 AM »
@Roy, I see now that you wanted to avoid "CONVERTPOLY" command... But I've found some lacks in your last sub - if pline had constant width it failed, so I revised it and successfully implemented into my (rhpl) sub... So it can be better - no flickering from CONVERTPOLY... Thanks for the code, it's very smart...

Code - Auto/Visual Lisp: [Select]
  1. ;; Reverse old heavy 2d POLYLINE - Marko Ribar, d.i.a. - sub functions by Roy at Theswamp.org
  2. (defun rhpl ( hpl / KGA_List_Divide_3 KGA_List_IndexSeqMakeLength KGA_Geom_PolylineReverse )
  3.  
  4.  
  5.   ; (KGA_List_Divide_3 '(0 1 2 3 4 5 6 7 8)) => ((0 1 2) (3 4 5) (6 7 8))
  6.   ; (KGA_List_Divide_3 '(0 1 2 3 4 5 6 7))   => ((0 1 2) (3 4 5))
  7.   (defun KGA_List_Divide_3 (lst / ret)
  8.     (repeat (/ (length lst) 3)
  9.       (setq ret (cons (list (car lst) (cadr lst) (caddr lst)) ret))
  10.       (setq lst (cdddr lst))
  11.     )
  12.     (reverse ret)
  13.   )
  14.    
  15.   ; Make a zero based list of integers.
  16.   ; With speed improvement based on Reini Urban's (std-%setnth).
  17.   ; (KGA_List_IndexSeqMakeLength 7) => (0 1 2 3 4 5 6)
  18.   (defun KGA_List_IndexSeqMakeLength (len / ret)
  19.     (repeat (rem len 4)
  20.       (setq ret (cons (setq len (1- len)) ret))
  21.     )
  22.     (repeat (/ len 4)
  23.       (setq ret
  24.         (vl-list*
  25.           (- len 4)
  26.           (- len 3)
  27.           (- len 2)
  28.           (- len 1)
  29.           ret
  30.         )
  31.       )
  32.       (setq len (- len 4))
  33.     )
  34.     ret
  35.   )
  36.    
  37.   ; Obj must be an "AcDb2dPolyline" of the acsimplepoly type or an "AcDbPolyline".
  38.   ; (KGA_Geom_PolylineReverse (vlax-ename->vla-object (car (entsel))))
  39.   (defun KGA_Geom_PolylineReverse (obj / typ bulgeLst idxLst ptLst widLst conWid v vx)
  40.     (setq typ (vla-get-type obj))
  41.     (vla-put-type obj acsimplepoly)
  42.     (setq ptLst (KGA_List_Divide_3 (vlax-get obj 'coordinates)))
  43.     (setq idxLst (KGA_List_IndexSeqMakeLength (1+ (length ptLst))))
  44.     (setq v (vlax-vla-object->ename obj))
  45.     (while (= (cdr (assoc 0 (setq vx (entget (setq v (entnext v)))))) "VERTEX")
  46.       (setq widLst (cons (list (cdr (assoc 40 vx)) (cdr (assoc 41 vx))) widLst))
  47.       (setq bulgeLst (cons (cdr (assoc 42 vx)) bulgeLst))
  48.     )
  49.     (if (vl-catch-all-error-p (setq conWid (vl-catch-all-apply 'vla-get-constantwidth (list obj))))
  50.       (mapcar
  51.        '(lambda (idx pt bulge widSub)
  52.           (vla-put-coordinate obj idx (vlax-3d-point pt))
  53.           (vla-setbulge obj idx (- bulge))
  54.           (vla-setwidth obj idx (cadr widSub) (car widSub))
  55.         )
  56.         idxLst
  57.         (reverse ptLst)
  58.         (append (cdr bulgeLst) (list (car bulgeLst)))
  59.         (append (cdr widLst) (list (car widLst)))
  60.       )
  61.       (progn
  62.         (mapcar
  63.          '(lambda (idx pt bulge widSub)
  64.             (vla-put-coordinate obj idx (vlax-3d-point pt))
  65.             (vla-setbulge obj idx (- bulge))
  66.           )
  67.           idxLst
  68.           (reverse ptLst)
  69.           (append (cdr bulgeLst) (list (car bulgeLst)))
  70.         )
  71.         (vla-put-constantwidth obj conWid)
  72.       )
  73.     )
  74.     (if typ (vla-put-type obj typ))
  75.   )
  76.  
  77.   (KGA_Geom_PolylineReverse (vlax-ename->vla-object hpl))
  78.   (entupd hpl)
  79. )
  80.  

M.R.
« Last Edit: April 28, 2017, 05:25:52 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: REVERSE curve
« Reply #5 on: April 26, 2017, 04:08:51 AM »
In my KGA_Geom_PolylineReverse tests I do not encounter any problems with polylines ('lw' and 'heavy') with a constant width. So please clarify the issue you have encountered.

Why don't you do something as simple as this?:
Code - Auto/Visual Lisp: [Select]
  1. (defun KGA_Geom_PolylineReverse2DPolyline (obj / typ)
  2.   (setq typ (vla-get-type obj))
  3.   (vla-put-type obj 0)
  4.   (KGA_Geom_PolylineReverse obj)
  5.   (vla-put-type obj typ)
  6. )

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: REVERSE curve
« Reply #6 on: April 26, 2017, 04:16:03 AM »
OK, I now see that there is an issue: KGA_Geom_PolylineReverse will cause lw polylines  to loose their constant width.
« Last Edit: April 26, 2017, 04:28:04 AM by roy_043 »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: REVERSE curve
« Reply #7 on: April 26, 2017, 04:47:38 AM »
New version of KGA_Geom_PolylineReverse incorporating Marko's constantwidth fix:
Code - Auto/Visual Lisp: [Select]
  1. ; Obj must be an "AcDb2dPolyline" or an "AcDbPolyline".
  2. ; (KGA_Geom_PolylineReverse (vlax-ename->vla-object (car (entsel))))
  3. (defun KGA_Geom_PolylineReverse (obj / bulgeLst idxLst ptLst typ widLst)
  4.   (if (= "AcDb2dPolyline" (vla-get-objectname obj))
  5.     (progn
  6.       (setq typ (vla-get-type obj))
  7.       (vla-put-type obj acsimplepoly)
  8.       (setq ptLst (KGA_List_Divide_3 (vlax-get obj 'coordinates)))
  9.     )
  10.     (setq ptLst (KGA_List_Divide_2 (vlax-get obj 'coordinates)))
  11.   )
  12.   (setq idxLst (KGA_List_IndexSeqMakeLength (length ptLst)))
  13.   (setq bulgeLst
  14.     (mapcar
  15.       '(lambda (idx) (vla-getbulge obj idx))
  16.       idxLst
  17.     )
  18.   )
  19.     (progn
  20.       (setq widLst
  21.         (mapcar
  22.           '(lambda (idx / widSta widEnd)
  23.             (vla-getwidth obj idx 'widSta 'widEnd)
  24.             (list widSta widEnd)
  25.           )
  26.           idxLst
  27.         )
  28.       )
  29.       (mapcar
  30.         '(lambda (idx pt bulge widSub)
  31.           (vlax-put obj 'coordinate idx pt)
  32.           (vla-setbulge obj idx (- bulge))
  33.           (vla-setwidth obj idx (cadr widSub) (car widSub))
  34.         )
  35.         idxLst
  36.         (reverse ptLst)
  37.         (append (cdr (reverse bulgeLst)) (list (car bulgeLst)))
  38.         (append (cdr (reverse widLst)) (list (car widLst)))
  39.       )
  40.     )
  41.     (mapcar
  42.       '(lambda (idx pt bulge)
  43.         (vlax-put obj 'coordinate idx pt)
  44.         (vla-setbulge obj idx (- bulge))
  45.       )
  46.       idxLst
  47.       (reverse ptLst)
  48.       (append (cdr (reverse bulgeLst)) (list (car bulgeLst)))
  49.     )
  50.   )
  51.   (if typ (vla-put-type obj typ))
  52. )
« Last Edit: April 26, 2017, 05:03:33 AM by roy_043 »

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: REVERSE curve
« Reply #8 on: April 27, 2017, 08:54:13 AM »
Roy, although this topic is over, I've found one small mistake in your examples...

This :
(append (cdr (reverse bulgeLst)) (list (car bulgeLst)))
and this :
(append (cdr (reverse widLst)) (list (car widLst)))

Should actually be :
(append (cdr (reverse bulgeLst)) (list (car (reverse bulgeLst))))
and :
(append (cdr (reverse widLst)) (list (car (reverse widLst))))

Or just :
(append (cdr (reverse bulgeLst)) (list (last bulgeLst)))
and :
(append (cdr (reverse widLst)) (list (last widLst)))

But nevertheless I also found that (rlw) by Evgeniy and (rhpl) and (r3dp) are also wrong for closed PLINE types, they both change position of starting vertex, but it seems that built-in command "REVERSE" is also wrong for this issue, check it and you'll see what I am talking about - it seems that implemented algorithms for "REVERSE" are based on our lisps that we posted... I don't know if this is such a big deal, nobody never ever noticed this and never complained - it seems that initial vertex isn't so important when closed POLYLINE is entity of interest...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: REVERSE curve
« Reply #9 on: April 27, 2017, 04:02:18 PM »
Good catch on the wrong list manipulations. Thanks.

You say 'this topic is over' and yet you continue the discussion.
I disagree with your last comment. For a reversed polyline I expect the last point to have become the first point.

So the function should looks like this:
Code - Auto/Visual Lisp: [Select]
  1. ; Obj must be an "AcDb2dPolyline" or an "AcDbPolyline".
  2. ; (KGA_Geom_PolylineReverse (vlax-ename->vla-object (car (entsel))))
  3. (defun KGA_Geom_PolylineReverse (obj / bulgeLst idxLst ptLst typ widLst)
  4.   (if (= "AcDb2dPolyline" (vla-get-objectname obj))
  5.     (progn
  6.       (setq typ (vla-get-type obj))
  7.       (vla-put-type obj acsimplepoly)
  8.       (setq ptLst (KGA_List_Divide_3 (vlax-get obj 'coordinates)))
  9.     )
  10.     (setq ptLst (KGA_List_Divide_2 (vlax-get obj 'coordinates)))
  11.   )
  12.   (setq idxLst (KGA_List_IndexSeqMakeLength (length ptLst)))
  13.   (setq bulgeLst
  14.     (mapcar
  15.       '(lambda (idx) (vla-getbulge obj idx))
  16.       idxLst
  17.     )
  18.   )
  19.   (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-get-constantwidth (list obj))) ; Vl-catch-all-apply is required.
  20.     (progn
  21.       (setq widLst
  22.         (mapcar
  23.           '(lambda (idx / widSta widEnd)
  24.             (vla-getwidth obj idx 'widSta 'widEnd)
  25.             (list widSta widEnd)
  26.           )
  27.           idxLst
  28.         )
  29.       )
  30.       (mapcar
  31.         '(lambda (idx pt bulge widSub)
  32.           (vlax-put obj 'coordinate idx pt)
  33.           (vla-setbulge obj idx (- bulge))
  34.           (vla-setwidth obj idx (cadr widSub) (car widSub))
  35.         )
  36.         (reverse idxLst)
  37.         ptLst
  38.         (cons (last bulgeLst) bulgeLst)
  39.         (cons (last widLst) widLst)
  40.       )
  41.     )
  42.     (mapcar
  43.       '(lambda (idx pt bulge)
  44.         (vlax-put obj 'coordinate idx pt)
  45.         (vla-setbulge obj idx (- bulge))
  46.       )
  47.       (reverse idxLst)
  48.       ptLst
  49.       (cons (last bulgeLst) bulgeLst)
  50.     )
  51.   )
  52.   (if typ (vla-put-type obj typ))
  53. )

EDIT: Updated the code: Reversing only the idxLst makes more sense.
« Last Edit: April 28, 2017, 04:16:36 AM by roy_043 »

thanhduan2407

  • Mosquito
  • Posts: 5
Re: REVERSE curve
« Reply #10 on: June 12, 2017, 09:57:15 PM »
I have search this:
Code: [Select]
(defun daochieu (ss / count lwp ent obj oname sss revlwpl revln)
  (vl-load-com)
  (defun revlwpl(/ eo el len)
(setq eo ent)
(setq el (list(assoc 210 ent)))
(while (member (assoc 10 ent) ent)
  (if (= 0.0 (assoc 42 ent))
   (setq el (cons (assoc 42 ent) el))
   (setq el (cons (cons 42 (- (cdr (assoc 42 ent)))) el))
  )
  (setq el (cons (assoc 41 ent) el))
  (setq el (cons (assoc 40 ent) el))
  (setq el (cons (assoc 10 ent) el))
  (setq ent (member (assoc 10 ent) ent))
  (setq ent (cdr ent))
)
(setq len(- (LENGTH eo) (LENGTH (member (assoc 10 eo) eo)) 1))
(while (>= len 0)
  (setq el (cons (nth len eo) el))
  (setq len (- len 1))
)
(setq ent el)
(entmod ent)
  )
  (defun revln (/ pt1 pt2)
(setq pt1 (cons 10 (cdr (assoc 11 ent))))
(setq pt2 (cons 11 (cdr (assoc 10 ent))))
(setq ent (subst pt1 (assoc 10 ent) ent))
(setq ent (subst pt2 (assoc 11 ent) ent))
(entmod ent)
  )

;;;  (princ "\nSelect Lines & Polylines to reverse direction of:   ")
;;;  (setq ss (ssget '((0 . "POLYLINE,LWPOLYLINE,LINE"))))
  (setvar "CMDECHO" 0)
  (command "._UNDO" "_BEgin")
  (if ss
(progn
  (setq count 0 lwp 0)
  (while (> (sslength ss) count)
(setq ent (ENTGET (ssname ss count))
  obj (vlax-ename->vla-object (ssname ss count))
  oname (vlax-get-property obj 'ObjectName)
)
(cond
  ((= oname "AcDb3dPolyline")(setq lwp(+ 1 lwp)))
  ((= (cdadr ent) "LWPOLYLINE")(revlwpl))
  ((= (cdadr ent) "POLYLINE")
(progn
  (setq sss (ssadd (ssname ss count)))
  (vl-cmdf "convertpoly" "Light" sss "")
  (setq ent (ENTGET (ssname sss 0)))
  (revlwpl)
)
  )
  ((= (cdadr ent) "LINE")(revln))
)
(setq count (+ count 1))
  )
)
  )
  (command "._UNDO" "_End")
  (if(> lwp 0)
(if(> lwp 1)
  (princ(strcat "\nCould not reverse " (itoa lwp) " 3dPolylines."))
  (princ"\nCould not reverse the 3dPolyline.")
)
  )
  (princ)
)
[code]

ahsattarian

  • Newt
  • Posts: 112
Re: REVERSE curve
« Reply #11 on: December 01, 2020, 01:59:30 AM »



setvar     "plinereversewidths"    to   1

then

command    :     "reverse"