Jump to content

Recommended Posts

Posted

Hi all, long time i faced problem with polylines. One app create bunch of polylines with not 90 deg corners between near parts if i use custom method inside that APP, but nevermind. I am looking for app that can adjust verterxes of polyine in way when polyline become fully orthogonal in current UCS, but keeps the first and last verters untoched (that can break further calculations). Example before/after below:
image.png.8973e69396fc141f34537a9c4a018c72.pngimage.png.07f1cf1595c82eb95d613c391cfc08a4.png

Honestly i am tired of manally adjusted them every time, by moving each verterx far away then back with orho turned ON to make in 90 deg to previous vertex. 
Thanks for every help

 

Posted

chat made this, 

(defun orthogonalize-points (pts / dx-in dx-out dy-in dy-out i in-is-h new-x new-y out-is-h p0 p1 p2 result)
  ;; If fewer than 3 points, nothing to do
  (if (< (length pts) 3)
    pts
    (progn
      (setq result pts)

      ;; Iterate interior vertices
      (setq i 1)
      (while (< i (- (length pts) 1))
        (setq p0 (nth (- i 1) result))
        (setq p1 (nth i result))
        (setq p2 (nth (+ i 1) result))
        ;; Incoming vector p0 -> p1
        (setq dx-in (- (car p1) (car p0)))
        (setq dy-in (- (cadr p1) (cadr p0)))

        ;; Outgoing vector p1 -> p2
        (setq dx-out (- (car p2) (car p1)))
        (setq dy-out (- (cadr p2) (cadr p1)))

        ;; Dominant direction tests
        (setq in-is-h  (>= (abs dx-in)  (abs dy-in)))
        (setq out-is-h (>= (abs dx-out) (abs dy-out)))

        ;; Case 1: Proper corner (one horizontal, one vertical)
        (cond
          ((/= in-is-h out-is-h)
           (if in-is-h
             (progn
               ;; incoming horizontal, outgoing vertical
               (setq new-x (car p2))
               (setq new-y (cadr p0))
             )
             (progn
               ;; incoming vertical, outgoing horizontal
               (setq new-x (car p0))
               (setq new-y (cadr p2))
             )
           )
          )

          ;; Case 2: both horizontal
          (in-is-h
           (setq new-x (car p1))
           (setq new-y (cadr p0))
          )

          ;; Case 3: both vertical
          (t
           (setq new-x (car p0))
           (setq new-y (cadr p1))
          )
        )

        ;; Replace interior point
        (setq result
              (subst (list new-x new-y) p1 result))

        (setq i (1+ i))
      )

      result
    )
  )
)

(defun c:ORTHO_PLINE ( / edata ent newpts p pl pts x)

  (setq ent (car (entsel "\nSelect a polyline: ")))
  (if (not ent)
    (progn
      (princ "\nNothing selected.")
      (exit)
    )
  )

  (setq edata (entget ent))

  ;; Ensure LWPOLYLINE
  (if (/= (cdr (assoc 0 edata)) "LWPOLYLINE")
    (progn
      (princ "\nEntity is not a lightweight polyline.")
      (exit)
    )
  )

  ;; Extract vertices (group code 10)
  (setq pts
        (mapcar 'cdr
                (vl-remove-if-not
                  '(lambda (x) (= (car x) 10))
                  edata)))

  ;; Orthogonalize
  (setq newpts (orthogonalize-points pts))

  ;; Create new polyline
  (setq pl
        (entmakex
          (append
            (list
              '(0 . "LWPOLYLINE")
              '(100 . "AcDbEntity")
              '(100 . "AcDbPolyline")
              (cons 90 (length newpts))
              '(70 . 0)
            )
            (mapcar '(lambda (p) (cons 10 p)) newpts)
          )
        )
  )

  (if pl
    (princ "\nOrthogonal polyline created.")
    (princ "\nFailed to create polyline.")
  )

  (princ)
)

 

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