Jump to content

Change the direction of multiple Polylines anti-clockwise and fill in numbers in ascending order


Recommended Posts

Posted

Hi guys: I'm new and don't know about autolisp. Sorry to bother you guys, any help is appreciated. And here is the attached drawingtest2.dwg

Posted

Some reason this is giving me an error.

 

(defun C:Set-poly (/ ss ent cords PtMinY)
  (if (setq SS (ssget ":L" '((0 . "*POLYLINE"))))
    (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
      (setq cords (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget ent))))
      (setq pMin (_LowYcoord cords))
    )
  )
)
;;https://www.cadtutor.net/forum/topic/31382-lowest-y-value-coordinate-for-a-polyline/?do=findComment&comment=289309
(defun _LowYcoord (pointList)
  (car (vl-sort (mapcar 'eval pointList) '(lambda (a b) (< (cadr a) (cadr b)))))
)

 

Posted

Have a look at this similar request for something I was doing. 


http://www.theswamp.org/index.php?topic=57938.0

 

And what I use for CW CCW.

; Checking if pline is CW or CCW and set to CCW
; Orignal idea  by Kent Cooper, 1 August 2018 Offsetinorout.lsp
; By Alan H July 2020

(defun AH:chkcwccw (ent / objnew area1 area2 obj minpoint maxpoint)

(setq obj (vlax-ename->vla-object ent))
(vla-GetBoundingBox obj 'minpoint 'maxpoint)
(setq pointmin (vlax-safearray->list minpoint))
(setq pointmax (vlax-safearray->list maxpoint))
(setq dist (/ (distance pointmin pointmax) 20.0))

(vla-offset obj dist)
(setq objnew (vlax-ename->vla-object (entlast)))
(setq area1  (vlax-get objnew 'Area))
(vla-delete objnew)

(vla-offset obj (- dist))
(setq objnew (vlax-ename->vla-object (entlast)))
(setq area2  (vlax-get objnew 'Area))
(vla-delete objnew)

(if (> area1 area2)
  (progn
  (command "Pedit" ent "reverse" "") ; note bricscad has no REVERSE 
  (setq y (+ y 1))
  )
)
)

 

  • Like 2
Posted (edited)

Offsetting weird shaped (blue) generates more then one entity when offsetting inside. The green is what would be deleted with (entlast) The white would be left over after running AH:chkcwccw

 

image.png.c29eaeb52e261642db20c8af5dc6246a.png

 

 This is what I came up with for Checking Direction. You should only feed this closed polylines because it wouldn't work with open polylines.

;;----------------------------------------------------------------------------;;
;; Checks direction of the pline
;; Orignal idea by Kent Cooper, Alan H
;; https://www.cadtutor.net/forum/topic/76312-change-the-direction-of-multiple-polylines-anti-clockwise-and-fill-in-numbers-in-ascending-order/#comment-603209
(defun CCW (ent / obj dist)
  (setq obj (vlax-ename->vla-object ent))
  (setq dist (vlax-get obj 'Length)) ;get a large distance so that offset inside would error
  (if (vl-catch-all-error-p (vl-catch-all-apply 'vlax-invoke (list obj 'offset dist))) ;if their is an error offset was to the inside
    (prompt "\nClockwise")
    (progn 
      (prompt "\nCounter Clockwise")
      (entdel (entlast))
    )
  )
  (princ)
)

 

Edited by mhupp

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