Autolisp continue commands after draw polyline

Autolisp continue commands after draw polyline

Anonymous
Not applicable
3,503 Views
5 Replies
Message 1 of 6

Autolisp continue commands after draw polyline

Anonymous
Not applicable

Hello I want to create Autolisp drawing a polyline with a hyperlink

I try to do this but command can not continue after drawing polyline

 

 

(defun C:Test ()
(while
(setq count 1))
(setq Text1 (getint "\nEnter Text1 :"))
(setq Text2 (getint "\nEnter Text2 :"))
(command "Pline")
(command "-HYPERLINK" "I" "O" "Last" "" count Text1 Text2 "")
setq count (+ Count 1)))

 

 

Please help

0 Likes
Accepted solutions (2)
3,504 Views
5 Replies
Replies (5)
Message 2 of 6

ВeekeeCZ
Consultant
Consultant
Accepted solution
(command-s "Pline")
0 Likes
Message 3 of 6

Ranjit_Singh
Advisor
Advisor
Accepted solution

You do not have any condition to exit the while loop. Also, initialize the count variable outside the while loop.

(setq coutn 1)
(while (<= count 25) ....do something........) ;I am using 25 just as an example
0 Likes
Message 4 of 6

Kent1Cooper
Consultant
Consultant

@ВeekeeCZ wrote:
(command-s "Pline")

I don't think so.  I have only used (command-s) inside *error* handlers, but according to Help for it:

 

   The command that is being executed must be started and completed in the same command-s function.

 

and

 

   Token streams fed in a single command-s expression must represent a full command and its input. .... The following is not valid with the command-s function:

(command-s "._line")

[followed by another one supplying points, etc.]  I suspect what you want for this part [in addition to some way of stopping the (while) loop that this is within, as @Ranjit_Singh pointed out] is:

 

(command "_.pline")

(while (> (getvar 'cmdactive") 0) (command pause)); for User input until Pline command is ended, then:

(command "-HYPERLINK" ;... etc.

Kent Cooper, AIA
0 Likes
Message 5 of 6

Kent1Cooper
Consultant
Consultant

@Ranjit_Singh wrote:

You do not have any condition to exit the while loop. Also, initialize the count variable outside the while loop.

(setq coutn 1)
(while (<= count 25) ....do something........) ;I am using 25 just as an example

There's no need to limit it to any arbitrary number, which may be beyond however many you would ever do, but does still limit you to that many.  Also, doing it that way requires ESCape to get out of it if you don't get as far as that many, and that means if you want the code to continue on to anything else after you've done all the Pline/Hyperlinking you want, that will be impossible, because the ESCape will cancel the whole routine.  You can have it be contingent on the User supplying the numbers, and they can do as many as they like, and get out of it with Enter/space, which will allow the routine to continue on to other stuff if desired:

 

(defun C:Test (/ count Text1 Text2)
  (setq count 1)

  (while

    (and
      (setq Text1 (getint "\nEnter integer Text1 [<exit>]:")); returns nil on Enter and stops the (while) loop
      (setq Text2 (getint "\nEnter integer Text2 :")); could also add the [<exit>] option in this line

    ); and

    (command "_.pline")

    (while (> (getvar 'cmdactive") 0) (command pause)); for User input until Pline command is ended, then:

    (command "-HYPERLINK" "I" "O" "Last" "" count Text1 Text2 "")
    (setq count (1+ count))

  ); while

  ;;;... do something else now, if you want, such as: (prompt (strcat "\n" (itoa count) Polylines Hyperlinked.")) ...

); defun

 

I added the word integer into the prompts to suit the (getint) function, but you could just as well word them differently, without the "Text" part in the prompt, so a User won't think they can enter "Marilyn Monroe" or something, e.g.:
....

    (setq Text1 (getint "\nFirst number [<exit>]: ")); returns nil on Enter and stops the (while) loop

    (setq Text2 (getint "\nSecond number: ")); could also add the [<exit>] option in this line

....

Kent Cooper, AIA
0 Likes
Message 6 of 6

ВeekeeCZ
Consultant
Consultant

@Kent1Cooper wrote:

@ВeekeeCZ wrote:
(command-s "Pline")

I don't think so.  I have only used (command-s) inside *error* handlers, but according to Help...

 

(command "_.pline")

(while (> (getvar 'cmdactive") 0) (command pause));.


 

I was to lazy too type the whole sentence. But it works, try it (on my 2016). And don't ask me why - I read the help to find out too, but it did not help me either... But let's ask @Anonymous, the author of the post HERE ... what's the clue...

 

BTW. To the OP. Besides Kent's minor typo (omit red "), -HYPERLINK probably does not need the last ""...

0 Likes