change the last number to 33

change the last number to 33

alexandre_benekowski
Advocate Advocate
1,328 Views
10 Replies
Message 1 of 11

change the last number to 33

alexandre_benekowski
Advocate
Advocate

Hi people.

 

I have a autolisp that insert sequencial number for each point that I click, so how can I change the last number for 33? (see color blue)

 

anyway, thank you very much!!!

 

below my code:

 

(defun c:notasdeserviço ()

 

;information....
(setq valor 1)
(setq eixo_projetado (getpoint "\nClick on exis "))
(setq cota_baixa (getpoint "\nclick on below quota "))
(setq cota_baixa_y (getreal "\nType the value quota "))

 

;insert box....
(command "_insert" "C:/Users/alexa/Desktop/Alexandre/12.LISP'S PARA AUTOCAD/BLOCOS/CAIXA" eixo_projetado "1" "1" "0")

 

;insert another block.....
(repeat 1000

(setq ponto (getpoint "\nCLIck on the point...: "))
(setq valor1 (rtos valor 2 0))
(command "_insert" "C:/Users/alexa/Desktop/Alexandre/12.LISP'S PARA AUTOCAD/BLOCOS/PIRULITO" ponto "1" "1" "0" valor1)
(princ)

 

;INFORMATION POINT DIST AND QUOTA....
;IN X....
(setq p1x (car eixo_projetado))
(setq p2x (car ponto))
(setq soma_x (- p2x p1x))
(setq distancia_x (rtos soma_x 2 3))
;EM Y.....
(setq p1y (cadr cota_baixa))
(setq p2y (cadr ponto))
(setq soma_y (+ cota_baixa_y (- p2y p1y)))
(setq distancia_y (rtos soma_y 2 3))

;INSERÇÃO DOS VALORES...
(setq local (polar eixo_projetado (/ (* pi 3) 2) 14.9))
(setq local_final (polar local (* pi 1) 19.0))
(command "_insert" "C:/Users/alexa/Desktop/Alexandre/12.LISP'S PARA AUTOCAD/BLOCOS/ponto_dist_cota" local_final "1" "1" "0" valor1 distancia_x distancia_y)

 

;SEQUENCIAL NUMBER....
(setq valor2 (+ valor 1))
(setq valor valor2)

 

;POSITION OF NUMBER, DISTANCI AND QUOTA....
(setq local_final1 (polar eixo_projetado (* pi 0) 2))
(setq eixo_projetado local_final1)

;END...
)
)

0 Likes
Accepted solutions (1)
1,329 Views
10 Replies
Replies (10)
Message 2 of 11

Kent1Cooper
Consultant
Consultant
Accepted solution

I'm not quite sure what you are trying to do.  If you want 33 to be the last value it will use, that is, you want it to stop when it gets to 33, you should be able to just replace the 1000 in the (repeat) function with 33.  Or am I misunderstanding? 

 

A few other comments:

The angles in (polar) functions are peculiar calculations.  Is there some reason to use (* pi 1) instead of just pi?  Or (* pi 0) instead of just 0?  [Also, (/ (* pi 3) 2) can be reduced to simply (* pi 1.5).]

 

This is also a strange construction:

 

(setq valor2 (+ valor 1))
(setq valor valor2)

 

Just eliminate the valor2 variable entirely, and do this:

(setq valor (1+ valor))

 

And since valor will always be an integer, instead of this:

(setq valor1 (rtos valor 2 0))

 

just do this:

 

(setq valor1 (itoa valor))

Kent Cooper, AIA
Message 3 of 11

john.uhden
Mentor
Mentor

I am wondering why he wants to make 1000 inserts one by one.  Maybe an array instead and plug in the attribute values afterwards.

And the limit of 33 has me baffled unless the thousandth one is supposed to be 33.  <???>

John F. Uhden

0 Likes
Message 4 of 11

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:

I am wondering why he wants to make 1000 inserts one by one.  ....


My guess is that it's just a way of being able to do as many as they might ever want to, until they cancel with ESCape, equivalent [for all practical purposes] to:

 

(while T

  ....

Kent Cooper, AIA
0 Likes
Message 5 of 11

john.uhden
Mentor
Mentor

@Kent1Cooper wrote:

  (while T ...
 

That's funny.  I'm always using:

(while (not done) ...
 
Of course your way could be an endless loop.
Yes, I know, except for an Esc.
 
I also use:
(setvar "errno" 0)
(while (/= (getvar "errno") 52) ...
which allows for missing a pick and continuing until a return (or Esc obviously).

John F. Uhden

Message 6 of 11

alexandre_benekowski
Advocate
Advocate

Hi kent1,

 

I used repeat 1000, because I don´t know how to loop and just stop when I want, then when I want to stop I do "esc"

 

I´d like to click and put number 1, click number 2 and when I click in the last, instead of put the sequencial number it put the number "33".

 

thank you for the other information.

 

Att.

0 Likes
Message 7 of 11

Kent1Cooper
Consultant
Consultant

@alexandre_benekowski wrote:

.... 

I´d like to click and put number 1, click number 2 and when I click in the last, instead of put the sequencial number it put the number "33".

....


By what means would you want to indicate to the routine that a given click is the last one?

Kent Cooper, AIA
Message 8 of 11

Kent1Cooper
Consultant
Consultant

I will make the assumption that hitting ESCape is still the method for ending the routine.  If so, then you could include an *error* handler, and within that, delete the last Insertion and re-do it using the same insertion point and other Attribute contents, but building the "33" into the one Attribute, in place of the valor1 variable.  I think that might be easier than having it dig into that Block insertion and change the Attribute content to "33", but that's another possibility.

 

(defun c:notasdeserviço (/ *error*);; add other local variable names

  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg))
    ); if

    (command-s "_.erase" "_last" ""); [if in a new-enough version to need the -s suffix]   

    (command-s

      "_insert" "C:/Users/alexa/Desktop/Alexandre/12.LISP'S PARA AUTOCAD/BLOCOS/ponto_dist_cota"

      local_final "1" "1" "0" "33" distancia_x distancia_y

    ); command-s

;;  and other stuff if desired [reset System Variables?  Undo end? etc.]

    (princ)

  ); defun -- *error*

  ;information....

....

Kent Cooper, AIA
0 Likes
Message 9 of 11

alexandre_benekowski
Advocate
Advocate

this is what I want..

 

see my new post.

0 Likes
Message 10 of 11

alexandre_benekowski
Advocate
Advocate

Hi Kent,

 

I tryed but it  din´t work, maybe because I learning autolisp. anyway, thank you very much!!!!   Smiley Happy

0 Likes
Message 11 of 11

devitg
Advisor
Advisor

You say.

I tryed but it  din´t work, maybe because I learning autolisp. anyway, thank you very much!!!

 

A main factor to consider , is that you DID NOT show your DWG , so the user who want to help you , mus be a guess major. 

 

It is a good etiquete mood , to show What you have , and WHAT you need or want to do. both in DWG, and LISP  

0 Likes