Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

polinha with two parameters

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
Anonymous
785 Views, 8 Replies

polinha with two parameters

 

I'm trying to create a routine where my polyline gets two parameters:
the first is the consistency between the verticies
the second is the maximum total length

 

how to make my polyline close while maintaining the preview of its design?
why doesn't my overall length work?

 

(defun c:foo ( )
  (setq tot_ '())
  (setq maximum_limit_between_vertices 90.0)
  (setq total_maximum_limit 4000.0)
  (setq pnt (getpoint "\nSpecify first point: "))
  (while
    (setq pnt_2 (getpoint pnt "\nSpecify next point: "))
    (if (> (setq dis_ (distance  pnt pnt_2)) maximum_limit_between_vertices)
      (alert "total limit exceeded.")
      (progn
        (command "_.Pline" pnt pnt_2 "")
        ;**polylines not closing!
        (setq pnt pnt_2)
        (setq tot_ (append (list dis_) tot_))
        (if (> (apply '+ tot_) total_maximum_limit)
          (alert "total general limit exceeded.")          
        )
      )
    )
  )
)

 

8 REPLIES 8
Message 2 of 9
ВeekeeCZ
in reply to: Anonymous

ad 1, see below

ad 2, it does.

 

(defun c:foo ( )
  (setq tot_ '())
  (setq maximum_limit_between_vertices 90.0)
  (setq total_maximum_limit 200.0)
  (setq pnt_0 (getpoint "\nSpecify first point: ")
	pnt pnt_0)
  (while
    (setq pnt_2 (getpoint pnt "\nSpecify next point: "))
    (if (> (setq dis_ (distance  pnt pnt_2)) maximum_limit_between_vertices)
      (alert "total limit exceeded.")
      (progn
        (command "_.Pline" pnt pnt_2 "")
        ;**polylines not closing!
        (setq pnt pnt_2)
        (setq tot_ (append (list dis_) tot_))
        (if (> (apply '+ tot_) total_maximum_limit)
          (alert "total general limit exceeded.")          
        )
      )
    )
  )
  (command "_.pline" "" pnt_0 "")
)
Message 3 of 9
Anonymous
in reply to: ВeekeeCZ

This is almost like leaving a single "JOIN" polyline, as you did it remains separate.

Message 4 of 9
dbhunia
in reply to: Anonymous

Try like this

 

 

 

(defun c:foo ( )
;(setq tot_ '())
(setq tot_ 0.0)
(setq maximum_limit_between_vertices 90.0)
(setq total_maximum_limit 4000.0)
(setq pnt (getpoint "\nSpecify first point: ")
	  pnt_0 pnt)
  (while (<= tot_ total_maximum_limit)
    (setq pnt_2 (getpoint pnt "\nSpecify next point: "))
    (if (> (setq dis_ (distance  pnt pnt_2)) maximum_limit_between_vertices)
      (alert "total limit exceeded.")
      (progn
        (command "_.Pline" pnt pnt_2 "")
        ;**polylines not closing!
        (setq pnt pnt_2)
        ;(setq tot_ (append (list dis_) tot_))
		(setq tot_ (+ dis_ tot_))
        ;(if (> (apply '+ tot_) total_maximum_limit)
		(if (> tot_ total_maximum_limit)
          (alert "total general limit exceeded.")
        )
      )
    )
  )
  (command "_.pline" "" pnt_0 "")
)

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 5 of 9
Kent1Cooper
in reply to: Anonymous

I have a feeling, from Message 3, that you mean the single-segment Polylines are not joining  into one Polyline as you go, rather than that they are not closing.  If that's correct, try this [very lightly tested]:

 

(defun c:foo (/ pnt pnt_2 dis_ tot_ pltotal)
  (setq maximum_limit_between_vertices 90.0)
  (setq total_maximum_limit 4000.0)
  (setq pnt (getpoint "\nSpecify first point: "))
  (while (setq pnt_2 (getpoint pnt "\nSpecify next point or <end>: "))
    (if (> (setq dis_ (distance  pnt pnt_2)) maximum_limit_between_vertices)
      (alert "segment limit exceeded."); then
      (progn ; else
        (setq tot_ (append (list dis_) tot_))
        (if (> (apply '+ tot_) total_maximum_limit)
          (progn ; then
            (alert "total general limit exceeded.")
            (setq tot_ (cdr tot_)); take latest added distance off
          ); progn
          (progn ; else
            (command "_.Pline" pnt pnt_2 "")
            (if pltotal
              (command "_.pedit" pltotal "_join" (entlast) "" ""); then
              (setq pltotal (entlast)); else [first one]
            ); if
            (setq pnt pnt_2)
          ); progn
        ); if
      ); progn
    ); if
  ); while
  (princ)
)

 

If you want an option to Close the Polyline, that could be added, but it would have to account again, using the start point this time rather than a picked point, for whether the closing segment and  the closed total are too long.

Kent Cooper, AIA
Message 6 of 9
Anonymous
in reply to: Kent1Cooper

@Kent1Cooper  it works!!!
was trying to use ssadd select and then join.

very good thank you.

Message 7 of 9
ronjonp
in reply to: Anonymous

Here's another example removing all command calls:

 

(defun c:foo (/ d maxd maxv p1 p2 r vl)
  ;; RJP » 2020-10-28
  (setq d 0)
  (setq maxd 4000.)
  (setq maxv 90.)
  (while (and (or p1 (and (setq p1 (getpoint "\nSpecify start point: ")) (setq r (cons p1 r))))
	      (setq p2 (getpoint p1 "\nSpecify next point: "))
	 )
    (cond ((> (+ d (distance p1 p2)) maxd) (alert "MAX DISTANCE REACHED!"))
	  ((> (distance p1 p2) maxv) (alert "SEGMENT TOO LONG!"))
	  ((setq d (+ d (distance p1 p2)))
	   (grvecs (append (setq vl (append vl (list p1 p2))) '(1)))
	   (setq r (cons (setq p1 p2) r))
	   (princ (strcat "\rRunning total: " (rtos d)))
	  )
    )
  )
  (if r
    (entmakex (append (list '(0 . "LWPOLYLINE")
			    '(100 . "AcDbEntity")
			    ;; Create your layername here
			    '(8 . "MaxDistancePolyline")
			    '(100 . "AcDbPolyline")
			    (cons 90 (length r))
			    ;; Change this to 1 to close the polyline
			    '(70 . 0)
		      )
		      (mapcar (function (lambda (x) (list 10 (car x) (cadr x)))) (reverse r))
	      )
    )
  )
  (princ)
)

 

 

 

Message 8 of 9
Moshe-A
in reply to: Anonymous

@Anonymous  hi,

 

check this one. first it collects all points and only at end draw the pline.

 

enjoy

moshe

 

 

(defun c:foo (/ askpoint main_exe ; local functions
                MAX_VERTEX_LENGTH MAX_PLINE_LENGTH dis_ tot_ pnt_0 pnt_1 pnt_2 n flag points_)

 (defun askpoint ()
  (setq n (1+ n))
   
  (cond
   ((= n 0)
    (getpoint "\nSpecify first point: ")
   )
   ((= n 1)
    (getpoint pnt_1 "\nSpecify next point: ")
   )
   ( t
    (initget "Close")
    (getpoint pnt_1 "\nSpecify next point or [Close]: ")
   )
  ); cond
 ); askpoint


 (defun main_exe (p1 p2)
  (cond
   ((> (setq dis_ (distance p1 p2)) MAX_VERTEX_LENGTH)
    (alert "total limit exceeded.")
   ); case
   ( t
    (setq tot_ (append (list dis_) tot_))
    (if (> (apply '+ tot_) MAX_PLINE_LENGTH)
     (alert "total general limit exceeded.")
     (progn 
      (grdraw p1 p2 7) 
       p2 ; retun p2 to caller
     )
    )
   ); case 
  ); cond
 ); main_exe


 ; here start c:foo 
 (setvar "cmdecho" 0)
 (command "._undo" "_begin")
  
 (setq MAX_VERTEX_LENGTH  90.0)
 (setq MAX_PLINE_LENGTH  4000.0)

 (setq tot_ '() n -1 points '())
  
 (if (setq pnt_0 (setq pnt_1 (askpoint)))
  (progn 
   (while (and (not flag) (setq pnt_2 (askpoint)))
    (if (eq pnt_2 "Close")
     (progn
      (setq points_ (append points_ (list "_Close"))) 
      (setq flag (main_exe pnt_1 pnt_0))
     ); progn
     (if (setq tmp (main_exe pnt_1 pnt_2))
      (setq points_ (append points_ (list (setq pnt_1 tmp))))
     )
    ); if 
   ); while

   (if (> (length (cons pnt_0 points_)) 1)
    (progn 
     (command "._pline" pnt_0 "w" 0 0)
     (foreach pt (reverse (cdr (reverse points_)))
      (command pt)
     )

     (if (eq (last points_) "_Close")
      (command (last points_))
      (command (last points_) "") 
     )
    ); progn
   ); if
   
  ); progn
 ); if


 (command "._undo" "_end")
 (setvar "cmdecho" 1)
  
 (princ)
)

 

Message 9 of 9
Moshe-A
in reply to: Anonymous

Good Morning

 

had a small bug so here is the fix. note that it allows the Close option

 

Moshe

 

 

(defun c:foo (/ askpoint main_exe ; local functions
                MAX_VERTEX_LENGTH MAX_PLINE_LENGTH dis_ tot_ pnt_0 pnt_1 pnt_2 n flag points_)

 (defun askpoint ()
  (setq n (1+ n))
   
  (cond
   ((= n 0)
    (getpoint "\nSpecify first point: ")
   )
   ((= n 1)
    (getpoint pnt_1 "\nSpecify next point: ")
   )
   ( t
    (initget "Close")
    (getpoint pnt_1 "\nSpecify next point or [Close]: ")
   )
  ); cond
 ); askpoint


 (defun main_exe (p1 p2)
  (cond
   ((> (setq dis_ (distance p1 p2)) MAX_VERTEX_LENGTH)
    (alert "total limit exceeded.")
   ); case
   ( t
    (setq tot_ (append (list dis_) tot_))
    (if (> (apply '+ tot_) MAX_PLINE_LENGTH)
     (alert "total general limit exceeded.")
     (progn 
      (grdraw p1 p2 7) 
       p2 ; retun p2 to caller
     )
    )
   ); case 
  ); cond
 ); main_exe


 ; here start c:foo 
 (setvar "cmdecho" 0)
 (command "._undo" "_begin")
  
 (setq MAX_VERTEX_LENGTH  90.0)
 (setq MAX_PLINE_LENGTH  400.0)

 (setq tot_ '() n -1 points '())
  
 (if (setq pnt_0 (setq pnt_1 (askpoint)))
  (progn 
   (while (and (not flag) (setq pnt_2 (askpoint)))
    (cond
     ((eq pnt_2 "Close")
      (if (setq flag (main_exe pnt_1 pnt_0))
       (setq points_ (append points_ (list "_Close")))
      )
     ); case
     ( t
      (if (setq tmp (main_exe pnt_1 pnt_2))
       (setq points_ (append points_ (list (setq pnt_1 tmp))))
      )
     ); case
    ); cond 
   ); while

   (redraw)
   
   (if (> (length (cons pnt_0 points_)) 1)
    (progn 
     (command "._pline" pnt_0 "w" 0 0)
     (foreach pt (reverse (cdr (reverse points_)))
      (command pt)
     )

     (if (eq (last points_) "_Close")
      (command (last points_))
      (command (last points_) "") 
     )
    ); progn
   ); if
   
  ); progn
 ); if


 (command "._undo" "_end")
 (setvar "cmdecho" 1)
  
 (princ)
)

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


AutoCAD Beta