Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Active Contributor
michael.deleurere
Posts: 42
Registered: ‎09-19-2011
Message 1 of 17 (685 Views)
Accepted Solution

program loop to draw lines with rubberband

685 Views, 16 Replies
10-04-2012 08:05 AM

i am writing something that will draw consecutive lines with a rubberband to be used as a leader from a block's insertion point.  this:

 

(WHILE
 (SETQ LN (GETPOINT "\nSelect Next Point (ENTER to Finish) : "))
 (COMMAND "LINE" (GETVAR "LASTPOINT") LN "")
)   

 

works, but does not include the rubber band.  i tried:

 

(WHILE

 (SETQ LP (GETVAR "LASTPOINT"))
 (SETQ LN (GETPOINT LP "\nSelect Next Point (ENTER to Finish) : "))
 (COMMAND "LINE" LP LN "")
)   

 

which includes the rubberband, but will not exit the loop. The last break source in VLIDE shows that  

 

(GETPOINT LP "\nSelect Next Point (ENTER to Finish) : ") is casuing an error.  Placing

 

 (SETQ LP (GETVAR "LASTPOINT"))

 

 outside the loop causes all lines to be drawn from the same point rather than the endpoint of the previous line.  any ideas?

 

 

try this

 

(WHILE

 (SETQ LP (GETVAR "LASTPOINT")
            LN (GETPOINT LP "\nSelect Next Point (ENTER to Finish) : "))
 (COMMAND "LINE" LP LN "")
)   

Distinguished Contributor
markruys
Posts: 108
Registered: ‎10-02-2007
Message 2 of 17 (677 Views)

Re: program loop to draw lines with rubberband

10-04-2012 08:31 AM in reply to: michael.deleurere

 

 

try this

 

(WHILE

 (SETQ LP (GETVAR "LASTPOINT")
            LN (GETPOINT LP "\nSelect Next Point (ENTER to Finish) : "))
 (COMMAND "LINE" LP LN "")
)   

Active Contributor
michael.deleurere
Posts: 42
Registered: ‎09-19-2011
Message 3 of 17 (670 Views)

Re: program loop to draw lines with rubberband

10-04-2012 08:43 AM in reply to: markruys

brilliant-- that did it.  thanks.

Contributor
bobdobbs
Posts: 15
Registered: ‎09-27-2012
Message 4 of 17 (668 Views)

Re: program loop to draw lines with rubberband

10-04-2012 08:50 AM in reply to: michael.deleurere

It looks like it will loop until  (SETQ LP (GETVAR "LASTPOINT")) is not true and I don't think that the "LASTPOINT" variable is set when using the GETxxx functions.

 

I'm probably missing something here, I don't know what you are trying to do but, maybe you don't need the WHILE. Could you just use ...

 

 (command "line" (getpoint "LINE Specify first point:"))

 

That'll keep drawing line segments till you hit enter, has a rubberband, and if you do need the "LASTPOINT" var later, it will have been set.

 

 

Contributor
anim8er3
Posts: 20
Registered: ‎08-30-2012
Message 5 of 17 (648 Views)

Re: program loop to draw lines with rubberband

10-04-2012 11:09 AM in reply to: bobdobbs

Is there something wrong with using the grdraw command?

*Expert Elite*
Kent1Cooper
Posts: 5,871
Registered: ‎09-13-2004
Message 6 of 17 (642 Views)

Re: program loop to draw lines with rubberband

10-04-2012 11:38 AM in reply to: bobdobbs

bobdobbs wrote:

.... 

I'm probably missing something here, I don't know what you are trying to do but, maybe you don't need the WHILE. Could you just use ...

 

 (command "line" (getpoint "LINE Specify first point:"))

...


I had the same reaction -- in what way is what the OP is trying to do different from just the basic Line command?  You could forget any routine, and just type L or pick a menu item or toolbar icon or however you normally draw Lines.  But maybe I'm missing something....

Kent Cooper
Active Contributor
michael.deleurere
Posts: 42
Registered: ‎09-19-2011
Message 7 of 17 (632 Views)

Re: program loop to draw lines with rubberband

10-04-2012 12:08 PM in reply to: Kent1Cooper

the purpose was to add this into a program that would place an attributed block, followed by a series of lines - at least one- to be used as a leader.  the first line is inserted in the middle of the tag, then moved to back behind a wipeout.  since mulitple block definitions are saved in the "SYMBOLS" drawing, it was necessary to insert this file to bring in all blocks first.  i could not think of how to run the line command in the normal way and still be able to reset the original variables at the end.  here is the full code:

 

(defun C:TGL (/ OM CL A B C D SBL LN LP)

(SETQ OM (GETVAR "OSMODE"))
(SETQ CL (GETVAR "CLAYER"))
(SETVAR "CMDECHO" 0)
(SETVAR "OSMODE" 0)
(SETVAR "ATTREQ" 1)
(SETVAR "ATTDIA" 1)

(SETVAR "CLAYER" "NOTES")

 

(IF (= (TBLSEARCH "BLOCK" "TAG") NIL)    
 (PROGN

 (COMMAND "-INSERT" "SYMBOLS.DWG" "0,0" "1" "1" "0")
 (SETQ SBL (SSGET "X" '((2 . "SYMBOLS"))))
 (COMMAND "ERASE" SBL"")
 (COMMAND "-PURGE" "BLOCK" "SYMBOLS" "N")
 )
)

(COMMAND "-INSERT" "TAG" (GETPOINT "\nSELECT INSERTION POINT :") "1" "1" "0")

(SETQ A (ENTGET (ENTLAST)))
(SETQ B (NTH 0 (CDR (ASSOC 10 A))))
(SETQ C (NTH 1 (CDR (ASSOC 10 A))))
(SETQ D (LIST B C))

(COMMAND "LINE" D (GETPOINT D "\nSpecify First Point of Leader Line :") "")
(COMMAND "DRAWORDER" "LAST" "" "BACK")

 

(WHILE (SETQ LP (GETVAR "LASTPOINT") LN
 (GETPOINT LP "\nSpecify Next Point of Leader Line (ENTER to Finish) : "))
 (COMMAND "LINE" LP LN "")
)
  

(SETVAR "OSMODE" OM)
(SETVAR "CLAYER" CL)
(SETVAR "CMDECHO" 1)

(PROMPT "\nFINISHED")

(PRINC)

)

Contributor
bobdobbs
Posts: 15
Registered: ‎09-27-2012
Message 8 of 17 (626 Views)

Re: program loop to draw lines with rubberband

10-04-2012 01:26 PM in reply to: anim8er3

Ethically, there is nothing wrong with grdraw  :smileyhappy:

 

In fact, just for fun ...

 

_gile wrote this message on 07-02-2010 02:04 PM in reply to: REID7800

 .../Visual-LISP-AutoLISP-and-General/Grread/td-p/2706707

 

** BTW How do you link to another thread? Anyone? **

 

 

;;replace this
;;(defun grsel (mode fltr / *error* pt ptlst gr loop)
;;with this
(defun c:grline (/ *error* pt ptlst gr loop)
;;
  (defun *error* (msg)
    (or	(= msg "Function cancelled")
	(princ (strcat "\nError: " msg))
    )
    (redraw)
    (princ)
  )
  (setq	pt    (getpoint
		"\nSpecify the first point: "
	      )
	ptlst (list pt)
	loop  T
  )
  (princ "\nSpecify the next point or <valid>: ")
  (while (and (setq gr (grread T 12 0)) loop)
    (redraw)
    (grvecs
      (cons -8 (apply 'append (mapcar 'list ptlst (cdr ptlst))))
    )
    (cond
      ((= (car gr) 5) (grdraw (car ptlst) (cadr gr) 8 1))
      ((= (car gr) 3)
       (setq ptlst (cons (cadr gr) ptlst))
       (princ "\nSpecify the next point or <valid>: ")
      )
      (T (redraw) (setq loop nil))
    )
  )
 ;;replace this
 ;; (ssget mode ptlst fltr)
 ;;with this
  (command "pline")
  (foreach xx ptlst (command xx))
  (command "")
;;
  
)

 

I use this or parts of it all the time.

 

Change just a few lines (already done here) and it draws very cool rubberband lines and then replaces them with a pline. Just like the OP is trying to do, I think.

Type c:grline

*Expert Elite*
Kent1Cooper
Posts: 5,871
Registered: ‎09-13-2004
Message 9 of 17 (620 Views)

Re: program loop to draw lines with rubberband

10-04-2012 01:45 PM in reply to: michael.deleurere

michael.deleurere wrote:

the purpose was to add this into a program that would place an attributed block, followed by a series of lines - at least one- to be used as a leader.  the first line is inserted in the middle of the tag, then moved to back behind a wipeout.  ....  i could not think of how to run the line command in the normal way and still be able to reset the original variables at the end.  here is the full code:

 

....

(COMMAND "-INSERT" "TAG" (GETPOINT "\nSELECT INSERTION POINT :") "1" "1" "0")

(SETQ A (ENTGET (ENTLAST)))
(SETQ B (NTH 0 (CDR (ASSOC 10 A))))
(SETQ C (NTH 1 (CDR (ASSOC 10 A))))
(SETQ D (LIST B C))

(COMMAND "LINE" D (GETPOINT D "\nSpecify First Point of Leader Line :") "")
(COMMAND "DRAWORDER" "LAST" "" "BACK")

 

(WHILE (SETQ LP (GETVAR "LASTPOINT") LN
 (GETPOINT LP "\nSpecify Next Point of Leader Line (ENTER to Finish) : "))
 (COMMAND "LINE" LP LN "")
)

 

(SETVAR "OSMODE" OM)
....


Try replacing the above-quoted portion with:

...

(command "-INSERT" "TAG" pause "1" "1" "0")

    ; Insert will supply its own insertion-point prompt, and this will set "@"

(setq pt (getpoint (getvar 'lastpoint) "\nSpecify Next Point of Leader Line: "))

(command

  "_.line" "@" pt ""

  "_.draworder" "_last" "" "_back"

  "_.line" pt

); will leave you in Line command

(while (> (getvar 'cmdactive) 0) (command pause))

  ; will keep waiting for further User input as long as Line command is still going

 

(SETVAR "OSMODE" OM)
....

Kent Cooper
*Expert Elite*
dbroad
Posts: 1,647
Registered: ‎08-16-2007
Message 10 of 17 (606 Views)

Re: program loop to draw lines with rubberband

10-04-2012 03:28 PM in reply to: michael.deleurere

michael.deleurere

 

Might multileader's serve your purpose rather than a program?  You can set up multiple mleader styles.

 

In your program, wouldn't plines suit your purpose better.  After the initial "PLINE" command, feed subsequent command functions with the points alone.  The leader ends up as one object rather than another.

 

You could also add a leader object and attach it to your block  That has the leader capabilities built-in.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.