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

program loop to draw lines with rubberband

16 REPLIES 16
SOLVED
Reply
Message 1 of 17
m.deleurere
1964 Views, 16 Replies

program loop to draw lines with rubberband

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?

16 REPLIES 16
Message 2 of 17
markruys2
in reply to: m.deleurere

 

 

try this

 

(WHILE

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

Message 3 of 17
m.deleurere
in reply to: markruys2

brilliant-- that did it.  thanks.

Message 4 of 17
bobdobbs
in reply to: m.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.

 

 

Message 5 of 17
anim8er3
in reply to: bobdobbs

Is there something wrong with using the grdraw command?

Message 6 of 17
Kent1Cooper
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, AIA
Message 7 of 17
m.deleurere
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)

)

Message 8 of 17
bobdobbs
in reply to: anim8er3

Ethically, there is nothing wrong with grdraw  Smiley Happy

 

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

Message 9 of 17
Kent1Cooper
in reply to: m.deleurere


@Anonymous.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, AIA
Message 10 of 17
dbroad
in reply to: m.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.

Architect, Registered NC, VA, SC, & GA.
Message 11 of 17
Kent1Cooper
in reply to: Kent1Cooper


@Kent1Cooper wrote:
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

....


For that matter, you could forget the 'pt' variable, and replace the above with:

...

(command

  "-INSERT" "TAG" pause "1" "1" "0"

  "_.line" "@" (getpoint (getvar 'lastpoint) "\nSpecify Next Point of Leader Line: ") ""

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

  "_.line" "@"

)

....

 

bobdobbs said "I don't think that the "LASTPOINT" variable is set when using the GETxxx functions," but when one is used inside a (command) function in response to a point-type prompt, that does put the resulting point into the LASTPOINT System Variable.

 

But I agree with dbroad that a single entity could be better, whether that's a Polyline, Leader or Mleader [(M)Leader Styles can be defined without arrowheads, to be like your Line at the Block insertion point end].  But if you need the first segment to go behind things and subsequent segments not to, maybe you need something different.  Even then, though, you could use a Line for the first segment only, and a Polyline or Leader for the rest -- you could just change the last "_.line" in the above to a different command name.

Kent Cooper, AIA
Message 12 of 17
m.deleurere
in reply to: Kent1Cooper

tthanks for all the good suggestions here-- especially to simplify things as i still have a lot to learn when it comes to autolisp.  i do like the idea of using polylines for the leader, but would like to make the leader optional.   

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

(INITGET 1 "Yes No")
(SETQ LL (GETKWORD "\nINSERT LEADER? Yes or No <Yes>:"))
(IF (NOT LL) (SETQ LL "Yes"))

(IF = LL Yes )

 (PROGN
 

(command

  "-INSERT" "TAG" pause "1" "1" "0"

  "_.line" "@" (getpoint (getvar 'lastpoint) "\nSpecify Next Point of Leader Line: ") ""

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

  "_.Pline" "@"

)

 ); progn

); if

 

does not recognize the answer.  how do i translate the YES or NO into the IF statement?

Message 13 of 17
m.deleurere
in reply to: m.deleurere

nevermid... missing quotes.  (if = LL "Yes")...

Message 14 of 17
Kent1Cooper
in reply to: m.deleurere


@Anonymous.deleurere wrote:

....   

(INITGET 1 "Yes No")
(SETQ LL (GETKWORD "\nINSERT LEADER? Yes or No <Yes>:"))
(IF (NOT LL) (SETQ LL "Yes"))

(IF = LL Yes )

 (PROGN
....


That could be simplified, without the LL variable.  But you don't want that 1 in the (initget) function if you are offering a default value, because that prevents the User from hitting Enter. 

....

(INITGET "Yes No"); without the 1

(if (/= (GETKWORD "\nINSERT LEADER? Yes or No <Yes>:") "No")

  ;; that is, if they type either Y [or Yes] or just Enter to accept Yes as the default [which will return nil]
  (PROGN

....

Kent Cooper, AIA
Message 15 of 17
dbroad
in reply to: m.deleurere


@Anonymous.deleurere wrote:

 i do like the idea of using polylines for the leader, but would like to make the leader optional.   

 


Again, remember that any block can be used in a mleaderstyle.  Multileaders do not have to have leaders attached.  Using mleader styles could be a very friendly way to work for you.  Dragging each style to a palette gives you access to multiple mleader styles without creating them in each drawing.

Architect, Registered NC, VA, SC, & GA.
Message 16 of 17
m.deleurere
in reply to: dbroad

we do use multileaders for notes, but i have not looked into including blocks.  i have had issues with the leader including a landing when the style specifys no landing and the style does not exist in the drawing. 

Message 17 of 17
dbroad
in reply to: m.deleurere

Although I don't know your application specifics, I'm pretty sure that using multileaders with your own blocks will be more maintainable and satisfactory than inventing a command to create your own leaders.   If you do keep your method, you might want to group the separate related objects that form part of the leader assembly with a group or to wrap them in an anoymous block.  Moving the leader block and leaving the leader lines behind and the arrow pointing the wrong way increases editing overhead.

 

I have several of my own commands for creating leaders(with blocks) which I have used for many years and am still impressed by the multi-leader capabilities.  If multileaders had been around when I started, I doubt that I would have coded them.

 

Palettes work well for storing mleader styles as long as each mleader style has a unique name.

 

Architect, Registered NC, VA, SC, & GA.

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

Post to forums  

Autodesk Design & Make Report

”Boost