Get points along zigzag polyline?

Get points along zigzag polyline?

DC-MWA
Collaborator Collaborator
2,210 Views
17 Replies
Message 1 of 18

Get points along zigzag polyline?

DC-MWA
Collaborator
Collaborator

Good morning all,

I'm trying to get points along a zigzag polyline. This is hard to explain... See image beow...

Capture.JPG

I've found ways to select all verticies of polyline but to get these points only seems to be more difficult.

Thanks in advance for any input.

0 Likes
2,211 Views
17 Replies
Replies (17)
Message 2 of 18

Kent1Cooper
Consultant
Consultant

Would it always be every other vertex through the entire length  of a Polyline, or might you sometimes want a limited range, such as the even-numbered ones from the 6th through 12th vertices of a 20-vertex Polyline?  And would it always be the even-numbered ones as in your image, or might you sometimes want the odd-numbered ones from the 11th through 19th vertices?

Kent Cooper, AIA
0 Likes
Message 3 of 18

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

…. every other vertex through the entire length  of a Polyline...?  ….


If that's the idea, here is one way to get two lists from a [lightweight only] Polyline, one of all the odd-numbered vertices (1st, 3rd, 5th, etc.) in a variable called "odds," and another of all the even-numbered ones in a variable called [as you might expect] "evens":

(defun C:PVEO ; = Polyline Vertices Every Other
  (/ pl verts n which)
  (setq
    pl (car (entsel "\nPolyline to get alternate-vertices list: "))
    verts (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget pl)))
    n 0 ; counter
  ); setq
  (while verts
    (setq which (read (if (= (rem (setq n (1+ n)) 2) 1) "odds" "evens")))
    (set which (cons (car verts) (eval which)))
    (setq verts (cdr verts)); remove point
  ); while
  (setq odds (reverse odds)); if direction-order matters
  (setq evens (reverse evens)); if direction-order matters
  (princ)
); defun

You can then apply whatever you want to do to whichever of those lists is appropriate, using (foreach).

Kent Cooper, AIA
0 Likes
Message 4 of 18

DC-MWA
Collaborator
Collaborator

Hi Kent,

Thanks as always. 

It seems that it is always the "evens" that I require. Maybe this would be easier to just show you what I'm trying to do.

DC-MWA_0-1589656328164.png

 

0 Likes
Message 5 of 18

devitg
Advisor
Advisor

@DC-MWA  as i can see , it is a stair . so all desired points shall be in line. 

 

0 Likes
Message 6 of 18

devitg
Advisor
Advisor

@DC-MWA  As I suppose, it is a stair profile , why not copy it and get down 1" 1/2 , I do in mm 38.1

(DEFUN MOVE-DOWN  (/ (acMagenta NEW POLY POLY-OBJ PT-1 PT-3 STEP))

  (VL-LOAD-COM)

  (SETQ POLY (SSNAME (SSGET ":s" '((0 . "*line"))) 0))
  (SETQ POLY-OBJ (VLAX-ENAME->VLA-OBJECT POLY))

  (SETQ NEW (VLA-COPY POLY-OBJ))
  (SETQ PT-1 (GETPOINT "\nPICK THE FIRST point  "))
  (SETQ STEP 38.1) ; 1 and half inch
  (SETQ PT-3 (POLAR PT-1 (/ PI -2.0) STEP))
  (VLA-MOVE NEW (VLAX-3D-POINT PT-1) (VLAX-3D-POINT PT-3))
  (VLA-PUT-COLOR NEW ACMAGENTA)

  )  

devitg_0-1589661162247.png

 

 

 

 

 

0 Likes
Message 7 of 18

DC-MWA
Collaborator
Collaborator

hhhmmm. Interesting. I like the simplicity of it. How do I get rid of the bottom leg that is too long?

0 Likes
Message 8 of 18

devitg
Advisor
Advisor

@DC-MWA , as not to work in a "suppose" dwg , please upload your sample dwg . 

Anyway , when you select the poly , it's start point , can be use to trim the new magenta poly 

 

0 Likes
Message 9 of 18

devitg
Advisor
Advisor

@DC-MWA test it , it "SUPPOSE" that the estair start at the base floor , and goes upward. 

if not it can change to pick  "SUPPOSE" start downward stair point 

 

 

;; Design by Gabo CALOS DE VIT from CORDOBA ARGENTINA
;;;    Copyleft 1995-2020 by Gabriel Calos De Vit ; [email protected]    
;;

 ; Hecho por  Gabo CALOS DE VIT de CORDOBA ARGENTINA
;;;    Copyleft 1995-2020 por Gabriel Calos De Vit 
;; [email protected] 

(DEFUN MOVE-DOWN  (/ (ACMAGENTA NEW POLY POLY-OBJ-START POLY-OBJ PT-1 PT-3 STEP))

  (VL-LOAD-COM)

  (SETQ POLY (SSNAME (SSGET ":s" '((0 . "*line"))) 0))
  (SETQ POLY-OBJ (VLAX-ENAME->VLA-OBJECT POLY))
  (SETQ POLY-OBJ-START (VLAX-CURVE-GETSTARTPOINT POLY-OBJ)); new line 
  (SETQ NEW (VLA-COPY POLY-OBJ))
  (SETQ PT-1 (GETPOINT "\nPICK THE FIRST point  "))
  (SETQ STEP 38.1) ; 1 and half inch
  (SETQ PT-3 (POLAR PT-1 (/ PI -2.0) STEP))
  (VLA-MOVE NEW (VLAX-3D-POINT PT-1) (VLAX-3D-POINT PT-3))
  (VLA-PUT-COLOR NEW ACMAGENTA)
  (COMMAND-S "trim" (ENTLAST) "" POLY-OBJ-START ""); new line 
  )

 

0 Likes
Message 10 of 18

DC-MWA
Collaborator
Collaborator

I got an error:

ActiveX Server returned an error: Parameter not optional

 

But using the same thinking I think I came up with something similar that seems to work.

 

;;copy down and trim first leg of poly
(defun C:test1 (/ oldcmd oldos ename pt1 pt2 get_pl)
(defun DTR (d) (* pi (/ d 180.0)));deg2rad
(setq oldcmd (getvar "cmdecho")
oldos (getvar "osmode"))
(setvar "cmdecho" 0)
(setvar "osmode" 1)
(setq ename (entsel "\nSelect Polyline:"))
(setq ename (car ename))
(setq pt1 (getpoint "\nPick 1st nosing: ")
pt2 (polar pt1 (DTR 270.0) 1.5))
(setvar "osmode" 0)
(command ".copy" ename "" pt1 pt2)
(setq get_pl (entlast))
(command ".pedit" get_pl "e" "n" "b" "g" "x" "")
(entdel get_pl)
(setvar "osmode" oldos)
(setvar "cmdecho" oldcmd)
(princ)
)

0 Likes
Message 11 of 18

devitg
Advisor
Advisor

@DC-MWA Please upload or send the sample.dwg 

 

0 Likes
Message 12 of 18

Sea-Haven
Mentor
Mentor

You can get pline vertice by a number as well as get all the co-ords, so another approach bit like even odd would be to draw only a 2 part line/pline of the tread thickness. So for a stair it would  be 2 -> last depending on how last connection to landing.

0 Likes
Message 13 of 18

pbejse
Mentor
Mentor

@DC-MWA wrote:

Capture.JPG

 

 


Points in between 1st and 2nd pick

(Defun c:STW (/ fp sp pl verts thistwopoints n) ; Show These points
;;		pBe May 2020			;;;
(defun xy (p)(list (Car p)(cadr p)))
  (if
	(and
	  (setq fp (getpoint "\nPick first reference point"))
	  (setq sp (getpoint fp "\nPick next point"))
	  (setq	pl (car (nentselp fp)))
	  )
		
	(progn
	  (setq verts (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget pl))))
	  (setq thistwopoints (vl-sort (mapcar '(lambda (w)
					(vl-position (xy w) verts))(list  fp sp)) '<))
	  ((lambda (n)
	  	(repeat (1- (/ (abs (apply '- thistwopoints)) 2))
		   ;;	repeated function here
			(entmake (list (cons 0 "POINT") (cons 10 (nth (setq n (+ 2 n)) verts))))
		  )
	     )
	    (car thistwopoints)
	    )
	)
	  )
	(princ)
  )

If you want to include  all points including 1st and second pick

((lambda (n)
	  	(repeat (1+ (/ (abs (apply '- thistwopoints)) 2))
		  ;;	repeated function here
			(entmake (list (cons 0 "POINT") (cons 10 (nth n verts))))
		  (setq n (+ 2 n))
		  )
	     )
	    (car thistwopoints)
	    )

If you only want to include ONLY the first pick [ the direction of the polyline plays a role here, you can add check for polylline direction ]

((lambda (n)
	  	(repeat (/ (abs (apply '- thistwopoints)) 2)
		   ;;	repeated function here
			(entmake (list (cons 0 "POINT") (cons 10 (nth (setq n (+ 2 n)) verts))))
		  )
	     )
	    (car thistwopoints)
	    )

 

HTH

 

0 Likes
Message 14 of 18

Sea-Haven
Mentor
Mentor

My check for direction is compare pick point distance to end & start and as its a pline can use either Reverse command or in lisp (reverse list)

 

If going to draw tread why not the kicker as well that's what I will call it I have been working on a stair lsp has built in "how many" to meet building code nice idea add treads. Pick two points top & bottom rest is auto.

0 Likes
Message 15 of 18

Kent1Cooper
Consultant
Consultant

@devitg wrote:

…. it is a stair .... 


You may be interested in STAIRS.lsp, with its StairSec command, available >here<.  The topic is mis-named -- it also does Stairs in Section.  It doesn't do the underside of treads as in your image, but you may find aspects of it that you can use, and such a thing could probably be added.  It's built for Imperial units and US standards, but could easily be modified for other base options.  Read the comments/instructions at the top of the file, and follow the prompts in the command.

 

If you're really permitted by applicable codes or regulations to do a stair with a straight plain vertical riser [not allowed under the most common Building Code around here], you can do that by choosing the Steel-pan stair option and calling for 0 nosing projection.  But it's built to do either a canted riser that is typical of Steel-pan stairs or a projecting-tread-board rounded nosing that is typical of Wood stairs.

 

Change this line near the top:
  (command ".undo" "e")

to this:

  (command-s ".undo" "e")

[it was written before plain (command) in an *error* handler was problematic].

Kent Cooper, AIA
0 Likes
Message 16 of 18

dlanorh
Advisor
Advisor

My 0.02$. Does left to right or right to left irrespective of polyline direction. Created polyline is on current layer color 6 (magenta).

 

(defun c:treads (/ ent vlst r p1 p2 p3 p4)

(vl-load-com)

  (defun rh:em_lwp (lst c oc)
    (if (not c) (setq c 256))
    (entmakex (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") (cons 62 c) (cons 90 (length lst)) (cons 70 oc))
                      (mapcar '(lambda ( x ) (cons 10 x)) lst)
              );end_append
    );end_entmakex
  );end_defun

  (cond ( (not *thk*) (initget 7) (setq *thk* (getreal "\nEnter tread depth : "))))

  (setq ent (ssname (ssget "_+.:E:S:L" '((0 . "LWPOLYLINE"))) 0)
        vlst (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget ent)))
  );end_setq

  (if (< (cadr (last vlst)) (cadr (car vlst))) (setq vlst (cdr (reverse vlst)) r '+) (setq vlst (cdr vlst) r '-))

  (while vlst
    (setq p1 (car vlst)
          p2 (cadr vlst)
          p3 (vlax-curve-getpointatdist ent ((eval r) (vlax-curve-getdistatpoint ent p1) *thk*))
          p4 (polar p3 (angle p1 p2) (distance p1 p2))
          vlst (cddr vlst)
    )
    (rh:em_lwp (list p3 p4 p2) 6 0)
  );end_while
  (princ)
);end_defun

 

I am not one of the robots you're looking for

0 Likes
Message 17 of 18

DC-MWA
Collaborator
Collaborator

Love this. Thank you.

0 Likes
Message 18 of 18

DC-MWA
Collaborator
Collaborator

Thank you. I'mplaying with this now.

0 Likes