Author Topic: Adding a Direction-of-Poly tool to Lee Mac's Trim Outside Points tool..  (Read 1543 times)

0 Members and 2 Guests are viewing this topic.

ScottMC

  • Newt
  • Posts: 193
Having acquired so much from y'all, thinkin this should be an easy tweek. Did try today but don't have it to put the two together. The desire is to see the Polyline rotation [CW vs CCW] as the "sdd" sub does before picking the breaking points. Any helps are again, greatly appreciated.

Code: [Select]
;;                                                                                                            ;;
;;   -------------=={ Trim Outside Points LWPolyline Section }==--------------;;
;;  https://www.theswamp.org/index.php?topic=57031.msg606331#msg606331  ;;
;;         removes segment(s) from End to Start ->                                     ;;
;;       This altered program prompts the user to pick points and TRIM      ;;
;;     selected LWPolyline. The user is then  prompted to specify two       ;;
;;     POINTS on the LWPolyline enclosing the section to be kept.  The   ;;
;;     program will proceed to erase all segments outside, after *ES* the   ;;
;;     two given points to BOTH sides by the specified distance.                ;;
;;                                                                                                            ;;
;;     The program is compatible with LWPolylines of constant or varying  ;;
;;     width, with straight and/or arc segments, and defined in any UCS     ;;
;;     construction plane.                                                                          ;;
;;----------------------------------------------------------------------------------------------;;
;;     Author:  Lee Mac, Copyright © 2013  -  www.lee-mac.com                ;;
;;-----------------------------------------------------------------------------------------------;;

(defun c:top ( / *error* d e h l m n o p q w x z lup)
 ;(setq lup (getvar "luprec"))
(princ "\n Direction of Trim/Remove..\n [CCW: north or west.. CW: south or east] < - / = to change>")
  (princ "\n Trim/Remove Segments from Points..<SD>")

(defun *error* (msg)
   (if
     (not
       (member msg '("console break" "Function canceled" "quit / exit abort")))
     (princ (strcat "\nError: " msg))
     ); if
         (setvar 'osmode cosm)
   (princ)
   )
(setq cosm (getvar 'osmode))
    (setvar 'osmode 7039)
 ;;--------------------------------------------------------------------------------------------

  ;;  direction arrow tool
 
(defun selfinters (o / a)
(or
(vl-catch-all-error-p
(setq a (vl-catch-all-apply 'vlax-invoke (list ms 'addregion (list o))))
)
(vla-delete (car a))
)
)
(defun clockwise-p (e / p1 p2 p a b d f1 f2)
(vla-getBoundingBox (vlax-ename->vla-object e) 'p1 'p2)
      (setq p
                    (vlax-curve-getparamatpoint e
                       (vlax-curve-getclosestpointtoprojection e
                          (mapcar '- (vlax-safearray->list p1) '(1 1 0))
                          '(1 0 0)
                       )
                    )
a  (vlax-curve-getstartparam e)
b  (vlax-curve-getendparam e)
d  (if
(eq (cdr (assoc 0 (entget e))) "SPLINE")
(* 0.01 (- b a))
0.1
)
f1 (vlax-curve-getfirstderiv e (+ a (rem (+ p d) (- b a))))
f2 (vlax-curve-getfirstderiv e (+ a (rem (+ (- p d) (- b a)) (- b a))))
)
(minusp (caddr (VxV f2 f1)))
)
  (defun VxV (a b)
(list (- (* (cadr a) (caddr b)) (* (caddr a) (cadr b)))
(- (* (caddr a) (car b)) (* (car a) (caddr b)))
(- (* (car a) (cadr b)) (* (cadr a) (car b)))
)
)
 
  (defun sdd ()


(if
 (setq ss (ssget "_:L" '((0 . "*POLYLINE,SPLINE,LINE"))))
(progn
(setq h (* 0.03 (getvar 'viewsize)))
(repeat (setq i (sslength ss))
(setq e (ssname ss (setq i (1- i)))
c (cond ((and                         ;arrows color
(vlax-curve-isplanar e)
(vlax-curve-isclosed e)
(not (selfinters (vlax-ename->vla-object e)))
)
(if (clockwise-p e) 1 3)   ;    ;green if was clockwise, red if not
)
((if (< (car (vlax-curve-getstartpoint e)) (car (vlax-curve-getendpoint e))) 1 3))
)
)
       )
     )
)
  ;)

         
  (if
(eq (cdr (assoc 0 (entget e))) "SPLINE")
(setq s (vlax-curve-getstartparam e)      ;start curve
f (vlax-curve-getendparam e)
j 10                     ;10 arrows on a single spline
d (/ (- f s) j)                     ;segment "length" (in paramter units)
)
(setq s 0.0
j (fix (vlax-curve-getendparam e))  ;1 arrow per segment for polylines
d 1.0
)
)
(repeat j
(setq j (1- j)
r (+ s (* j d) (* 0.5 d))           ;current parameter
p (vlax-curve-getpointatparam e r)
a ((lambda (d) (atan (cadr d) (car d))) (vlax-curve-getfirstderiv e r))
)
(grdraw p (polar p (+ a (* pi 0.9)) h) c)
(grdraw p (polar p (- a (* pi 0.9)) h) c)
)

   
;;-----------------------------------------------------------------------------
    ;; main pgm
  (while

        (progn
        (setvar 'errno 0)
        (setq e (car (entsel "\nSelect LWPolyline: ")))
           ;(sdd)  ;;;-------------------------------------- how to include?????
             (cond
                (   (= 7 (getvar 'errno))
                    (princ "\nMissed, try again.")
                )
                (   (null e) nil)
                (   (/= "LWPOLYLINE" (cdr (assoc 0 (entget e))))
                    (princ "\nObject is Not a LWPolyline.")
                )
                (   (setq p (getpoint "\nSpecify 1st Point: "))
                    (setq p (vlax-curve-getclosestpointto e (trans p 1 0)))
                    (while
                        (and
                            (setq  q (getpoint (trans p 0 1) "\nSpecify 2nd Point: "))
                            (equal p (setq q (vlax-curve-getclosestpointto e (trans q 1 0))) 1e-8)
                        )
                        (princ "\nPoints Must be Distinct.")
                    )
                    (if q
                        (progn
                            (if (> (setq m (vlax-curve-getparamatpoint e p))
                                   (setq n (vlax-curve-getparamatpoint e q))
                                )
                                (mapcar 'set '(m n p q) (list n m q p))
                            )
                            (setq e (entget e)
                                  h (reverse (member (assoc 39 e) (reverse e)))
                                  h (subst (cons 70 (logand (cdr (assoc 70 h)) (~ 1))) (assoc 70 h) h)
                                  l (LM:LWVertices e)
                                  z (assoc 210 e)
                            )
                            (repeat (fix m)
                                (setq l (cdr l))
                            )
                            (if (not (equal m (fix m) 1e-8))
                                (setq x (car l)
                                      w (cdr (assoc 40 x))
                                      l
                                    (cons
                                        (list
                                            (cons  10 (trans p 0 (cdr z)))
                                            (cons  40 (+ w (* (- m (fix m)) (- (cdr (assoc 41 x)) w))))
                                            (assoc 41 x)
                                            (cons  42
                                                (tan
                                                    (*  (- (min n (1+ (fix m))) m)
                                                        (atan (cdr (assoc 42 x)))
                                                    )
                                                )
                                            )
                                        )
                                        (cdr l)
                                    )
                                )
                            )
                            (setq l (reverse l))
                            (repeat (+ (length l) (fix m) (- (fix n)) -1)
                                (setq l (cdr l))
                            )
                            (if (not (equal n (fix n) 1e-8))
                                (setq x (car l)
                                      w (cdr (assoc 40 x))
                                      l
                                    (vl-list*
                                        (list
                                            (cons 10 (trans q 0 (cdr z)))
                                           '(40 . 0.0)
                                           '(41 . 0.0)
                                           '(42 . 0.0)
                                        )
                                        (list
                                            (assoc 10 x)
                                            (assoc 40 x)
                                            (cons  41
                                                (+ w
                                                    (*  (/ (- n (max m (fix n))) (- (1+ (fix n)) (max m (fix n))))
                                                        (- (cdr (assoc 41 x)) w)
                                                    )
                                                )
                                            )
                                            (cons  42
                                                (tan
                                                    (*  (if (< (fix n) m) 1.0 (- n (fix n)))
                                                        (atan (cdr (assoc 42 x)))
                                                    )
                                                )
                                            )
                                        )
                                        (cdr l)
                                    )
                                )
                            )
                            (setq o
                                (vlax-ename->vla-object
                                    (entmakex (append h (apply 'append (reverse l)) (list z)))
                                                )
                                                )
                                           (entdel (cdr (assoc -1 e)))     
                                                ; (vl-catch-all-apply 'vla-offset (list o d))
                                                ;(vl-catch-all-apply 'vla-offset (list o (- d)))
                                                ;(vla-delete o)
                        )
                    )
                )
            )
        )
    )
(setvar 'osmode cosm)    ;(setvar "luprec" lup)
    (princ)
)

;; Tangent  -  Lee Mac
;; Args: x - real
 
(defun tan ( x )
    (if (not (equal 0.0 (cos x) 1e-8))
        (/ (sin x) (cos x))
    )
)
 
;; LW Vertices  -  Lee Mac
;; Returns a list of lists in which each sublist describes the position,
;; starting width, ending width and bulge of a vertex of an LWPolyline
 
(defun LM:LWVertices ( e )
    (if (setq e (member (assoc 10 e) e))
        (cons
            (list
                (assoc 10 e)
                (assoc 40 e)
                (assoc 41 e)
                (assoc 42 e)
            )
            (LM:LWVertices (cdr e))
        )
    )
)

;;----------------------------------------------------------------------;;

(vl-load-com)
(princ
    (strcat
        "\n:: TrimOutside.lsp | Version 1.1 | © Lee Mac "
        (menucmd "m=$(edtime,0,yyyy)")
        " www.lee-mac.com ::"
        "\n:: Type \"top\" to Invoke ::"
    )
)
(princ)

;;----------------------------------------------------------------------;;
;;                             End of File                              ;;
;;----------------------------------------------------------------------;;


ribarm

  • Gator
  • Posts: 3297
  • Marko Ribar, architect
I don't know is it working, but at least I've sorted and cleaned up the code not to look like you wrote it with legs, but with typing with hands...

Code: [Select]
;;                                                                                                            ;;
;;   -------------=={ Trim Outside Points LWPolyline Section }==--------------;;
;;  https://www.theswamp.org/index.php?topic=57031.msg606331#msg606331  ;;
;;         removes segment(s) from End to Start ->                                     ;;
;;       This altered program prompts the user to pick points and TRIM      ;;
;;     selected LWPolyline. The user is then  prompted to specify two       ;;
;;     POINTS on the LWPolyline enclosing the section to be kept.  The   ;;
;;     program will proceed to erase all segments outside, after *ES* the   ;;
;;     two given points to BOTH sides by the specified distance.                ;;
;;                                                                                                            ;;
;;     The program is compatible with LWPolylines of constant or varying  ;;
;;     width, with straight and/or arc segments, and defined in any UCS     ;;
;;     construction plane.                                                                          ;;
;;----------------------------------------------------------------------------------------------;;
;;     Author:  Lee Mac, Copyright © 2013  -  www.lee-mac.com                ;;
;;-----------------------------------------------------------------------------------------------;;

(defun c:top ( / *error* selfinters clockwise-p v^v tan LM:lwvertices sdd cosm ss d e h l m n o p q w x z )

  ;;(princ "\n Direction of Trim/Remove..\n [CCW: north or west.. CW: south or east] < - / = to change>")
  ;;(princ "\n Trim/Remove Segments from Points..<SD>")

  (vl-load-com)

  (defun *error* ( m )
    (if cosm
      (setvar 'osmode cosm)
    )
    (if m
      (prompt m)
    )
    (princ)
  )
  (setq cosm (getvar 'osmode))
  (setvar 'osmode 7039)
  ;;--------------------------------------------------------------------------------------------
  ;;  direction arrow tool

  (defun selfinters ( o / a )
    (or
      (vl-catch-all-error-p
        (setq a (vl-catch-all-apply 'vlax-invoke (list ms 'addregion (list o))))
      )
      (vla-delete (car a))
    )
  )

  (defun clockwise-p ( e / p1 p2 p a b d f1 f2 )
    (vla-getBoundingBox (vlax-ename->vla-object e) 'p1 'p2)
    (setq p
      (vlax-curve-getparamatpoint e
         (vlax-curve-getclosestpointtoprojection e
            (mapcar '- (vlax-safearray->list p1) '(1 1 0))
            '(1 0 0)
         )
      )
      a  (vlax-curve-getstartparam e)
      b  (vlax-curve-getendparam e)
      d  (if
           (eq (cdr (assoc 0 (entget e))) "SPLINE")
             (* 0.01 (- b a))
             0.1
         )
      f1 (vlax-curve-getfirstderiv e (+ a (rem (+ p d) (- b a))))
      f2 (vlax-curve-getfirstderiv e (+ a (rem (+ (- p d) (- b a)) (- b a))))
    )
    (minusp (caddr (v^v f2 f1)))
  )

  (defun v^v ( a b )
    (list
      (- (* (cadr a) (caddr b)) (* (caddr a) (cadr b)))
      (- (* (caddr a) (car b)) (* (car a) (caddr b)))
      (- (* (car a) (cadr b)) (* (cadr a) (car b)))
    )
  )

  ;; Tangent  -  Lee Mac
  ;; Args: x - real

  (defun tan ( x )
    (if (not (equal 0.0 (cos x) 1e-8))
      (/ (sin x) (cos x))
    )
  )

  ;; LW Vertices  -  Lee Mac
  ;; Returns a list of lists in which each sublist describes the position,
  ;; starting width, ending width and bulge of a vertex of an LWPolyline

  (defun LM:lwvertices ( e )
    (if (setq e (member (assoc 10 e) e))
      (cons
        (list
          (assoc 10 e)
          (assoc 40 e)
          (assoc 41 e)
          (assoc 42 e)
        )
        (LM:lwvertices (cdr e))
      )
    )
  )

  (defun sdd ( ss / h i e c s f j d r p a )
    (if ss
      (progn
        (setq h (* 0.03 (getvar 'viewsize)))
        (repeat (setq i (sslength ss))
          (setq e (ssname ss (setq i (1- i)))
               c (cond ( (and                         ;arrows color
                           (vlax-curve-isplanar e)
                           (vlax-curve-isclosed e)
                           (not (selfinters (vlax-ename->vla-object e)))
                         )
                         (if (clockwise-p e) 1 3)   ;    ;green if was clockwise, red if not
                       )
                       ( (if (< (car (vlax-curve-getstartpoint e)) (car (vlax-curve-getendpoint e))) 1 3)
                       )
                 )
          )
          (cond
            ( (and e (wcmatch (cdr (assoc 0 (entget e))) "LINE,SPLINE,ARC,ELLIPSE,CIRCLE,HELIX"))
              (setq s (vlax-curve-getstartparam e)      ;start curve
                    f (vlax-curve-getendparam e)
                    j 10                     ;10 arrows on a single spline
                    d (/ (- f s) j)                     ;segment "length" (in paramter units)
              )
            )
            ( (and e (wcmatch (cdr (assoc 0 (entget e))) "*POLYLINE"))
              (setq s 0.0
                    j (fix (vlax-curve-getendparam e))  ;1 arrow per segment for polylines
                    d 1.0
              )
            )
          )
          (if e
            (repeat j
               (setq j (1- j)
                     r (+ s (* j d) (* 0.5 d))           ;current parameter
                     p (vlax-curve-getpointatparam e r)
                     a ( (lambda ( d ) (atan (cadr d) (car d))) (vlax-curve-getfirstderiv e r) )
               )
               (grdraw p (polar p (+ a (* pi 0.9)) h) c)
               (grdraw p (polar p (- a (* pi 0.9)) h) c)
            )
          )
        )
      )
    )
  )

  ;;-----------------------------------------------------------------------------
  ;; main program
  (prompt "\nESC to FINISH...")
  (while (not (vl-catch-all-error-p (vl-catch-all-apply 'grread (list t 15 0))))
    (if (setq ss (ssget "_A" '((0 . "*POLYLINE,SPLINE,LINE,ARC,ELLIPSE,CIRCLE,HELIX"))))
      (sdd ss)
    )
    (setvar 'errno 0)
    (setq e (car (entsel "\nSelect LWPolyline: ")))
    (cond
      ( (= 7 (getvar 'errno))
        (princ "\nMissed, try again.")
      )
      ( (null e) nil)
      ( (/= "LWPOLYLINE" (cdr (assoc 0 (entget e))))
        (princ "\nObject is Not a LWPolyline.")
      )
      ( (setq p (getpoint "\nSpecify 1st Point: "))
        (setq p (vlax-curve-getclosestpointto e (trans p 1 0)))
        (while
          (and
            (setq  q (getpoint (trans p 0 1) "\nSpecify 2nd Point: "))
            (equal p (setq q (vlax-curve-getclosestpointto e (trans q 1 0))) 1e-8)
          )
          (princ "\nPoints Must be Distinct.")
        )
        (if q
          (progn
            (if (> (setq m (vlax-curve-getparamatpoint e p))
                   (setq n (vlax-curve-getparamatpoint e q))
                )
                (mapcar 'set '(m n p q) (list n m q p))
            )
            (setq e (entget e)
                  h (cond ( (reverse (member (assoc 39 e) (reverse e))) ) ( (reverse (member (assoc 38 e) (reverse e))) ))
                  h (subst (cons 70 (logand (cdr (assoc 70 h)) (~ 1))) (assoc 70 h) h)
                  l (LM:lwvertices e)
                  z (assoc 210 e)
            )
            (repeat (fix m)
              (setq l (cdr l))
            )
            (if (not (equal m (fix m) 1e-8))
              (setq x (car l)
                    w (cdr (assoc 40 x))
                    l
                (cons
                  (list
                    (cons  10 (trans p 0 (cdr z)))
                    (cons  40 (+ w (* (- m (fix m)) (- (cdr (assoc 41 x)) w))))
                    (assoc 41 x)
                    (cons  42
                      (tan
                        (* (- (min n (1+ (fix m))) m)
                          (atan (cdr (assoc 42 x)))
                        )
                      )
                    )
                  )
                  (cdr l)
                )
              )
            )
            (setq l (reverse l))
            (repeat (+ (length l) (fix m) (- (fix n)) -1)
              (setq l (cdr l))
            )
            (if (not (equal n (fix n) 1e-8))
              (setq x (car l)
                    w (cdr (assoc 40 x))
                    l
                (vl-list*
                  (list
                    (cons 10 (trans q 0 (cdr z)))
                   '(40 . 0.0)
                   '(41 . 0.0)
                   '(42 . 0.0)
                  )
                  (list
                    (assoc 10 x)
                    (assoc 40 x)
                    (cons  41
                      (+ w
                        (* (/ (- n (max m (fix n))) (- (1+ (fix n)) (max m (fix n))))
                          (- (cdr (assoc 41 x)) w)
                        )
                      )
                    )
                    (cons  42
                      (tan
                        (* (if (< (fix n) m) 1.0 (- n (fix n)))
                          (atan (cdr (assoc 42 x)))
                        )
                      )
                    )
                  )
                  (cdr l)
                )
              )
            )
            (setq o
              (vlax-ename->vla-object
                (entmakex (append h (apply 'append (reverse l)) (list z)))
              )
            )
            (entdel (cdr (assoc -1 e)))     
          )
        )
      )
    )
    (redraw)
  )
  (*error* nil)
)

M.R.
« Last Edit: May 08, 2023, 10:15:11 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ScottMC

  • Newt
  • Posts: 193
Thanks to Lee.Mac for most. Thanks ribarm. Thanks PM too. Did a re-working and decided ssget "_X" as shown, will do OK. Here's the working file:
.. Fixed to: "v^v"
Code: [Select]
;;                                                                                                            ;;
;;   -------------=={ Trim Outside Points LWPolyline Section }==--------------;;
;;  https://www.theswamp.org/index.php?topic=57031.msg606331#msg606331  ;;
;;         removes segment(s) from End to Start ->                                     ;;
;;       This altered program prompts the user to pick points and TRIM      ;;
;;     selected LWPolyline. The user is then  prompted to specify two       ;;
;;     POINTS on the LWPolyline enclosing the section to be kept.  The   ;;
;;     program will proceed to erase all segments outside, after *ES* the   ;;
;;     two given points to BOTH sides by the specified distance.                ;;
;;                                                                                                            ;;
;;     The program is compatible with LWPolylines of constant or varying  ;;
;;     width, with straight and/or arc segments, and defined in any UCS     ;;
;;     construction plane.                                                                          ;;
;;----------------------------------------------------------------------------------------------;;
;;     Author:  Lee Mac, Copyright © 2013  -  www.lee-mac.com                ;;
;;-----------------------------------------------------------------------------------------------;;

(defun c:top (/ *error* d e h l m n o p q w x z lup)
                                                  ;(setq lup (getvar "luprec"))
  (princ
    "\n Direction of Trim/Remove..\n [CCW: north or west.. CW: south or east] < - / = to change>") ;_ end of princ
 ;;                                                                               -/= cmd to change direction before when needed..
;;                                                                                                                      from: ElpanovEvgeniy
  (princ "\n Trim/Remove Segments from Points Selected..")

  (defun *error* (msg)
    (if
      (not
        (member
          msg
          '("console break" "Function canceled" "quit / exit abort")
        ) ;_ end of member
      ) ;_ end of not
       (princ (strcat "\nError: " msg))
    )                                             ; if
    (setvar 'osmode cosm)
    (princ)
  ) ;_ end of defun
  (setq cosm (getvar 'osmode))
  (setvar 'osmode 7039)
  ;;--------------------------------------------------------------------------------------------

  ;;  direction arrow tool - < g is selection >

  (defun cvc (/     *error*     v^v   acDoc s2    vl    ms    ss
              i     g     j     p     a     c     h     s     f
              r     d     clockwisee-p
             )
    ;; ;; http://www.theswamp.org/index.php?topic=57221.msg607439#msg607439
    (vl-load-com)
    (setq acDoc (vla-get-activedocument (vlax-get-acad-object))
          ms    (if
                  (eq (getvar 'cvport) 1)
                   (vla-get-paperspace acDoc)
                   (vla-get-modelspace acDoc)
                ) ;_ end of if
    ) ;_ end of setq
    (vla-startundomark acDoc)

    (defun *error* (m)
      (and m
           (not (wcmatch (strcase m) "*CANCEL*,*EXIT*,*QUIT*"))
           (princ (strcat "\nError: " m))
      ) ;_ end of and
      (vla-endundomark acDoc)
      (princ)
    ) ;_ end of defun

    (defun v^v (a b)
      (list (- (* (cadr a) (caddr b)) (* (caddr a) (cadr b)))
            (- (* (caddr a) (car b)) (* (car a) (caddr b)))
            (- (* (car a) (cadr b)) (* (cadr a) (car b)))
      ) ;_ end of list
    )                                             ;
                                                  ;Stefan M. 11.11.2013                        ;
    (defun clockwisee-p (e / p1 p2 p a b d f1 f2)
     
      (vla-getBoundingBox (vlax-ename->vla-object g) 'p1 'p2)
      (setq p  (vlax-curve-getparamatpoint
                 g
                 (vlax-curve-getClosestPointToProjection
                   g
                   (mapcar '- (vlax-safearray->list p1) '(1 1 0))
                   '(1 0 0)
                 ) ;_ end of vlax-curve-getClosestPointToProjection
               ) ;_ end of vlax-curve-getparamatpoint
            a  (vlax-curve-getstartparam g)
            b  (vlax-curve-getendparam g)
            d  (if
                 (eq (cdr (assoc 0 (entget g))) "SPLINE")
                  (* 0.01 (- b a))
                  0.1
               ) ;_ end of if
            f1 (vlax-curve-getFirstDeriv g (+ a (rem (+ p d) (- b a))))
            f2 (vlax-curve-getFirstDeriv
                 g
                 (+ a (rem (+ (- p d) (- b a)) (- b a)))
               ) ;_ end of vlax-curve-getFirstDeriv
      ) ;_ end of setq
      (minusp (caddr (v^v f2 f1)))
    ) ;_ end of defun
                                                  ;self-inters[ecting object]                   ;
                                                  ;argument:                                   ;
                                                  ;   o - vla-object                           ;
                                                  ;       CLOSED 2D curve in WCS               ;
                                                  ;return: T for self-intersecting curve        ;
                                                  ;Stefan M. 11.11.2013                        ;
    (defun selfinters (o / a)
      (or
        (vl-catch-all-error-p
          (setq a (vl-catch-all-apply
                    'vlax-invoke
                    (list ms 'addregion (list o))
                  ) ;_ end of vl-catch-all-apply
          ) ;_ end of setq
        ) ;_ end of vl-catch-all-error-p
        (vla-delete (car a))
      ) ;_ end of or
    ) ;_ end of defun

    (if
      (setq ss (ssget "_X" '((0 . "*POLYLINE,LINE"))))
       ;; auto select last
       (progn
         (setq h (* 0.03 (getvar 'viewsize)))
         (repeat (setq i (sslength ss))
           (setq g (ssname ss (setq i (1- i)))
                 c (cond ((and                    ;arrows color
                            (vlax-curve-isPlanar g)
                            (vlax-curve-isClosed g)
                            (not (selfinters (vlax-ename->vla-object g)))
                          ) ;_ end of and
                          (if (clockwisee-p g)
                            1
                            3
                          )                       ;    ;re-named var, green if clocwise, red if not
                         )
                         ;; end of and
                         ((if (< (car (vlax-curve-getstartpoint g))
                                 (car (vlax-curve-getendpoint g))
                              ) ;_ end of <
                            1
                            3
                          ) ;_ end of if
                         )
                   ) ;_ end of cond
           ) ;_ end of setq
           (if
             (eq (cdr (assoc 0 (entget g))) "SPLINE")
              (setq s (vlax-curve-getstartparam g) ;start curve
                    f (vlax-curve-getendparam g)
                    j 10                          ;10 arrows on a single spline
                    d (/ (- f s) j)               ;segment "length" (in paramter units)
              ) ;_ end of setq
              (setq s 0.0
                    j (fix (vlax-curve-getendparam g))
                                                  ;1 arrow per segment for polylines
                    d 1.0
              ) ;_ end of setq
           ) ;_ end of if
           (repeat j
             (setq j (1- j)
                   r (+ s (* j d) (* 0.5 d))      ;current parameter
                   p (vlax-curve-getpointatparam g r)
                   a ((lambda (d) (atan (cadr d) (car d)))
                       (vlax-curve-getFirstDeriv g r)
                     )
             ) ;_ end of setq
             (grdraw p (polar p (+ a (* pi 0.9)) h) c)
             (grdraw p (polar p (- a (* pi 0.9)) h) c)
           ) ;_ end of repeat
                                                  ;(if (< c 3) (c:,,)) ;; small selection redirection
         ) ;_ end of repeat
       ) ;_ end of progn
    ) ;_ end of if

    (vla-endundomark acDoc)
    (princ)
  ) ;_ end of defun

  ;;-----------------------------------------------------------------------------
  ;; main pgm
  (while

    (progn
      (setvar 'errno 0)
      (setq e (car (entsel "\nSelect LWPolyline: ")))
                                     
      (cvc)

      (cond
        ((= 7 (getvar 'errno))
         (princ "\nMissed, try again.")
        )
        ((null e) nil)
        ((/= "LWPOLYLINE" (cdr (assoc 0 (entget e))))
         (princ "\nObject is Not a LWPolyline.")
        )
        ((setq p (getpoint "\nSpecify 1st Point: "))
         (setq p (vlax-curve-getclosestpointto e (trans p 1 0)))
         (while
           (and
             (setq q (getpoint (trans p 0 1) "\nSpecify 2nd Point: "))
             (equal
               p
               (setq q (vlax-curve-getclosestpointto e (trans q 1 0)))
               1e-8
             ) ;_ end of equal
           ) ;_ end of and
            (princ "\nPoints Must be Distinct.")
         ) ;_ end of while
         (if q
           (progn
             (if (> (setq m (vlax-curve-getparamatpoint e p))
                    (setq n (vlax-curve-getparamatpoint e q))
                 ) ;_ end of >
               (mapcar 'set '(m n p q) (list n m q p))
             ) ;_ end of if
             (setq e (entget e)
                   h (reverse (member (assoc 39 e) (reverse e)))
                   h (subst (cons 70 (logand (cdr (assoc 70 h)) (~ 1)))
                            (assoc 70 h)
                            h
                     ) ;_ end of subst
                   l (LM:LWVertices e)
                   z (assoc 210 e)
             ) ;_ end of setq
             (repeat (fix m)
               (setq l (cdr l))
             ) ;_ end of repeat
             (if (not (equal m (fix m) 1e-8))
               (setq x (car l)
                     w (cdr (assoc 40 x))
                     l
                       (cons
                         (list
                           (cons 10 (trans p 0 (cdr z)))
                           (cons
                             40
                             (+ w (* (- m (fix m)) (- (cdr (assoc 41 x)) w)))
                           ) ;_ end of cons
                           (assoc 41 x)
                           (cons 42
                                 (tan
                                   (* (- (min n (1+ (fix m))) m)
                                      (atan (cdr (assoc 42 x)))
                                   ) ;_ end of *
                                 ) ;_ end of tan
                           ) ;_ end of cons
                         ) ;_ end of list
                         (cdr l)
                       ) ;_ end of cons
               ) ;_ end of setq
             ) ;_ end of if
             (setq l (reverse l))
             (repeat (+ (length l) (fix m) (- (fix n)) -1)
               (setq l (cdr l))
             ) ;_ end of repeat
             (if (not (equal n (fix n) 1e-8))
               (setq x (car l)
                     w (cdr (assoc 40 x))
                     l
                       (vl-list*
                         (list
                           (cons 10 (trans q 0 (cdr z)))
                           '(40 . 0.0)
                           '(41 . 0.0)
                           '(42 . 0.0)
                         ) ;_ end of list
                         (list
                           (assoc 10 x)
                           (assoc 40 x)
                           (cons 41
                                 (+ w
                                    (* (/ (- n (max m (fix n)))
                                          (- (1+ (fix n)) (max m (fix n)))
                                       ) ;_ end of /
                                       (- (cdr (assoc 41 x)) w)
                                    ) ;_ end of *
                                 ) ;_ end of +
                           ) ;_ end of cons
                           (cons 42
                                 (tan
                                   (* (if (< (fix n) m)
                                        1.0
                                        (- n (fix n))
                                      ) ;_ end of if
                                      (atan (cdr (assoc 42 x)))
                                   ) ;_ end of *
                                 ) ;_ end of tan
                           ) ;_ end of cons
                         ) ;_ end of list
                         (cdr l)
                       ) ;_ end of vl-list*
               ) ;_ end of setq
             ) ;_ end of if
             (setq o
                    (vlax-ename->vla-object
                      (entmakex (append h (apply 'append (reverse l)) (list z))
                      ) ;_ end of entmakex
                    ) ;_ end of vlax-ename->vla-object
             ) ;_ end of setq
             (entdel (cdr (assoc -1 e)))
                                                  ; (vl-catch-all-apply 'vla-offset (list o d))
                                                  ;(vl-catch-all-apply 'vla-offset (list o (- d)))
                                                  ;(vla-delete o)
           ) ;_ end of progn
         ) ;_ end of if
        )
      ) ;_ end of cond
    ) ;_ end of progn
  ) ;_ end of while
  (setvar 'osmode cosm)                           ;(setvar "luprec" lup)
  (princ)
) ;_ end of defun

;; Tangent  -  Lee Mac
;; Args: x - real

(defun tan (x)
  (if (not (equal 0.0 (cos x) 1e-8))
    (/ (sin x) (cos x))
  ) ;_ end of if
) ;_ end of defun

;; LW Vertices  -  Lee Mac
;; Returns a list of lists in which each sublist describes the position,
;; starting width, ending width and bulge of a vertex of an LWPolyline

(defun LM:LWVertices (e)
  (if (setq e (member (assoc 10 e) e))
    (cons
      (list
        (assoc 10 e)
        (assoc 40 e)
        (assoc 41 e)
        (assoc 42 e)
      ) ;_ end of list
      (LM:LWVertices (cdr e))
    ) ;_ end of cons
  ) ;_ end of if
) ;_ end of defun

;;----------------------------------------------------------------------;;

(vl-load-com)
(princ
  (strcat
    "\n:: TrimOutside.lsp | Version 1.1 | © Lee Mac "
    (menucmd "m=$(edtime,0,yyyy)")
    " www.lee-mac.com ::"
    "\n:: Type \"top\" to Invoke ::"
  ) ;_ end of strcat
) ;_ end of princ
(princ)

;;----------------------------------------------------------------------;;
;;                             End of File                              ;;
;;----------------------------------------------------------------------;;
;|«Visual LISP© Format Options»
(72 2 50 2 T "end of " 60 9 0 1 0 nil T nil T)
;*** DO NOT add text below the comment! ***|;

« Last Edit: May 07, 2023, 11:49:24 AM by ScottMC »

ribarm

  • Gator
  • Posts: 3297
  • Marko Ribar, architect
Please correct sub function name for cross product... :
VxV , should be v^v
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ScottMC

  • Newt
  • Posts: 193
All this shows me is I've got alot to learn about putting multiple cmd's together.

ribarm

  • Gator
  • Posts: 3297
  • Marko Ribar, architect
Look at my version...
I think that you should put (cvc), or (sdd) before main (while...) loop... My version is good for me, so it's just a suggestion which I mean is constructive...

Bye,
M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ScottMC

  • Newt
  • Posts: 193
Can you include the selected for direction in the modify? The benefit having the cvc after is it allows pan/wheel zoom to re-get directions within..
« Last Edit: May 07, 2023, 05:25:42 PM by ScottMC »

ribarm

  • Gator
  • Posts: 3297
  • Marko Ribar, architect
OK... With GrSnap it's very unstable, so I've just put it like you wished inside (while ... ) loop...
If you need to regenerate when zoomed or panned, just click with mouse, but not on the lwpolyline you wish to cut... You'll finally get choice - do you want to continue with cutting or not...

Code: [Select]
;;                                                                                                            ;;
;;   -------------=={ Trim Outside Points LWPolyline Section }==--------------;;
;;  https://www.theswamp.org/index.php?topic=57031.msg606331#msg606331  ;;
;;         removes segment(s) from End to Start ->                                     ;;
;;       This altered program prompts the user to pick points and TRIM      ;;
;;     selected LWPolyline. The user is then  prompted to specify two       ;;
;;     POINTS on the LWPolyline enclosing the section to be kept.  The   ;;
;;     program will proceed to erase all segments outside, after *ES* the   ;;
;;     two given points to BOTH sides by the specified distance.                ;;
;;                                                                                                            ;;
;;     The program is compatible with LWPolylines of constant or varying  ;;
;;     width, with straight and/or arc segments, and defined in any UCS     ;;
;;     construction plane.                                                                          ;;
;;----------------------------------------------------------------------------------------------;;
;;     Author:  Lee Mac, Copyright © 2013  -  www.lee-mac.com                ;;
;;-----------------------------------------------------------------------------------------------;;

(defun c:top ( / *error* LM:acapp selfinters clockwise-p v^v tan LM:lwvertices sdd osf osm cmd ss d e h l m n o p q w x z done )

  ;;(princ "\n Direction of Trim/Remove..\n [CCW: north or west.. CW: south or east] < - / = to change>")
  ;;(princ "\n Trim/Remove Segments from Points..<SD>")

  (defun *error* ( m )
    (if (= 8 (logand 8 (getvar 'undoctl)))
      (if command-s
        (command-s "_.UNDO" "_E")
        (vl-cmdf "_.UNDO" "_E")
      )
    )
    (if osm (setvar 'osmode osm))
    (if cmd (setvar 'cmdecho cmd))
    (if m (prompt m))
    (princ)
  )

  (setq osm (getvar 'osmode))
  (setvar 'osmode 547)
  (setq cmd (getvar 'cmdecho))
  (setvar 'cmdecho 0)
  ;;--------------------------------------------------------------------------------------------
  ;;  direction arrow tool

  ;; Application Object  -  Lee Mac
  ;; Returns the VLA Application Object
  ;; Mod. by M.R.

  (defun LM:acapp nil
    (eval
      (list 'defun 'LM:acapp '( / cad )
        (if (vl-catch-all-error-p (setq cad (vl-catch-all-apply (function vlax-get-acad-object) nil)))
          (progn (vl-load-com) (vlax-get-acad-object))
          cad
        )
      )
    )
    (LM:acapp)
  )

  (defun selfinters ( o / a )
    (or
      (vl-catch-all-error-p
        (setq a (vl-catch-all-apply 'vlax-invoke (list ms 'addregion (list o))))
      )
      (vla-delete (car a))
    )
  )

  (defun clockwise-p ( e / p1 p2 p a b d f1 f2 )
    (vla-getBoundingBox (vlax-ename->vla-object e) 'p1 'p2)
    (setq p
      (vlax-curve-getparamatpoint e
         (vlax-curve-getclosestpointtoprojection e
            (mapcar '- (vlax-safearray->list p1) '(1 1 0))
            '(1 0 0)
         )
      )
      a  (vlax-curve-getstartparam e)
      b  (vlax-curve-getendparam e)
      d  (if
           (eq (cdr (assoc 0 (entget e))) "SPLINE")
             (* 0.01 (- b a))
             0.1
         )
      f1 (vlax-curve-getfirstderiv e (+ a (rem (+ p d) (- b a))))
      f2 (vlax-curve-getfirstderiv e (+ a (rem (+ (- p d) (- b a)) (- b a))))
    )
    (minusp (caddr (v^v f2 f1)))
  )

  (defun v^v ( a b )
    (list
      (- (* (cadr a) (caddr b)) (* (caddr a) (cadr b)))
      (- (* (caddr a) (car b)) (* (car a) (caddr b)))
      (- (* (car a) (cadr b)) (* (cadr a) (car b)))
    )
  )

  ;; Tangent  -  Lee Mac
  ;; Args: x - real

  (defun tan ( x )
    (if (not (equal 0.0 (cos x) 1e-8))
      (/ (sin x) (cos x))
    )
  )

  ;; LW Vertices  -  Lee Mac
  ;; Returns a list of lists in which each sublist describes the position,
  ;; starting width, ending width and bulge of a vertex of an LWPolyline

  (defun LM:lwvertices ( e )
    (if (setq e (member (assoc 10 e) e))
      (cons
        (list
          (assoc 10 e)
          (assoc 40 e)
          (assoc 41 e)
          (assoc 42 e)
        )
        (LM:lwvertices (cdr e))
      )
    )
  )

  (defun sdd ( ss / h i e c s f j d r p a )
    (if ss
      (progn
        (setq h (* 0.03 (getvar 'viewsize)))
        (repeat (setq i (sslength ss))
          (setq e (ssname ss (setq i (1- i)))
               c (cond ( (and                         ;arrows color
                           (vlax-curve-isplanar e)
                           (vlax-curve-isclosed e)
                           (not (selfinters (vlax-ename->vla-object e)))
                         )
                         (if (clockwise-p e) 1 3)   ;    ;green if was clockwise, red if not
                       )
                       ( (if (< (car (vlax-curve-getstartpoint e)) (car (vlax-curve-getendpoint e))) 1 3)
                       )
                 )
          )
          (cond
            ( (and e (wcmatch (cdr (assoc 0 (entget e))) "LINE,SPLINE,ARC,ELLIPSE,CIRCLE,HELIX"))
              (setq s (vlax-curve-getstartparam e)      ;start curve
                    f (vlax-curve-getendparam e)
                    j 10                     ;10 arrows on a single spline
                    d (/ (- f s) j)                     ;segment "length" (in paramter units)
              )
            )
            ( (and e (wcmatch (cdr (assoc 0 (entget e))) "*POLYLINE"))
              (setq s 0.0
                    j (fix (vlax-curve-getendparam e))  ;1 arrow per segment for polylines
                    d 1.0
              )
            )
          )
          (if e
            (repeat j
               (setq j (1- j)
                     r (+ s (* j d) (* 0.5 d))           ;current parameter
                     p (vlax-curve-getpointatparam e r)
                     a ( (lambda ( d ) (atan (cadr d) (car d))) (vlax-curve-getfirstderiv e r) )
               )
               (grdraw p (polar p (+ a (* pi 0.9)) h) c)
               (grdraw p (polar p (- a (* pi 0.9)) h) c)
            )
          )
        )
      )
    )
  )

  ;;-----------------------------------------------------------------------------
  ;; main program
  (prompt "\nESC to FINISH...")
  (while (not done)
    (sdd (setq ss (ssget "_A" (list (cons 0 "*POLYLINE,SPLINE,LINE,ARC,ELLIPSE,CIRCLE,HELIX")))))
    (if
      (and
        (setq p (getpoint "\nPick or specify 1st point : "))
        (setq e (car (nentselp p)))
        (setq q (getpoint p "\nPick or specify 2nd point : "))
      )
      (progn
        (if (> (setq m (vlax-curve-getparamatpoint e p))
               (setq n (vlax-curve-getparamatpoint e q))
            )
            (mapcar 'set '(m n p q) (list n m q p))
        )
        (setq e (entget e)
              h (cond ( (reverse (member (assoc 39 e) (reverse e))) ) ( (reverse (member (assoc 38 e) (reverse e))) ))
              h (subst (cons 70 (logand (cdr (assoc 70 h)) (~ 1))) (assoc 70 h) h)
              l (LM:lwvertices e)
              z (assoc 210 e)
        )
        (repeat (fix m)
          (setq l (cdr l))
        )
        (if (not (equal m (fix m) 1e-8))
          (setq x (car l)
                w (cdr (assoc 40 x))
                l
            (cons
              (list
                (cons  10 (trans p 0 (cdr z)))
                (cons  40 (+ w (* (- m (fix m)) (- (cdr (assoc 41 x)) w))))
                (assoc 41 x)
                (cons  42
                  (tan
                    (* (- (min n (1+ (fix m))) m)
                      (atan (cdr (assoc 42 x)))
                    )
                  )
                )
              )
              (cdr l)
            )
          )
        )
        (setq l (reverse l))
        (repeat (+ (length l) (fix m) (- (fix n)) -1)
          (setq l (cdr l))
        )
        (if (not (equal n (fix n) 1e-8))
          (setq x (car l)
                w (cdr (assoc 40 x))
                l
            (vl-list*
              (list
                (cons 10 (trans q 0 (cdr z)))
               '(40 . 0.0)
               '(41 . 0.0)
               '(42 . 0.0)
              )
              (list
                (assoc 10 x)
                (assoc 40 x)
                (cons  41
                  (+ w
                    (* (/ (- n (max m (fix n))) (- (1+ (fix n)) (max m (fix n))))
                      (- (cdr (assoc 41 x)) w)
                    )
                  )
                )
                (cons  42
                  (tan
                    (* (if (< (fix n) m) 1.0 (- n (fix n)))
                      (atan (cdr (assoc 42 x)))
                    )
                  )
                )
              )
              (cdr l)
            )
          )
        )
        (setq o
          (vlax-ename->vla-object
            (entmakex (append h (apply 'append (reverse l)) (list z)))
          )
        )
        (entdel (cdr (assoc -1 e)))     
      )
    )
    (if (and p q e)
      (setq p nil q nil e nil)
    )
    ;|
    (initget "Yes No")
    (if (= "Yes" (cond ( (getkword "\nDo you want to continue with picking points [Yes / No] <Yes> : ") ) ( "Yes" )))
      (setq done nil)
      (setq done t)
    )
    |;
    (redraw)
  )
  (*error* nil)
)

HTH.
M.R.
« Last Edit: May 10, 2023, 08:54:20 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ScottMC

  • Newt
  • Posts: 193
Q: wonder how [not needed] to allow just polyline selection. Only thing I could imagine, is, the polyline/cut point might be at the intersection of such and...
Otherwise, Seems your altercations are working! { the 'continue' prompt is fine } Thanks

ScottMC

  • Newt
  • Posts: 193
Marco.. the more I pick at this, seems it's got other conflicts. Certainly not so common but existing is where I do change polyline rotation. The rotation changing isn't recognized or causes crash makes further effort into this really wasting your skill for naught. Please don't see this in any way a pernicious responce period. You are a large part of my lisp library and further inspires me to find more of what you've done so I can better understand lisp. BTW this is my first [and really only] gander at programming yet I really do like the smaller challenges. [got a friend who wants to learn solid modeling but he seems to be '3D.phobic' - hope he overcomes it] Again: Thanks

-- hmmm.. breaking news: seems it's the larger side that's removed and really nothing to do with direction. Might just have to ask Mr. Lee Mac bout this thought.

NOPE.. Still iffy trimmin.. just not secure.
;;// -----------------------------------------------------------------------------------------------------------
     In thinking the bout the hmm, now that sets us a challange. Is there a way to intigrate in the point of selection to also have it set the side to trim off... BTW, Do like your changes.
« Last Edit: May 11, 2023, 06:16:27 PM by ScottMC »