• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

lisp per misurare

  • Thread starter Thread starter mobile
  • Start date Start date

mobile

Guest
Goddamn everyone!
This is the code I wrote, it would take to calculate the length in meters of a distance given on the screen, I know that it is possible to do this even with quotas, but since I recently started I wanted to do something simple.
My problem is that I cannot allow the measured length (distmis), to be added m (which indicates the length meters) as suffix, that is after the number, and detached with a space.

(setq distmis (getdist "draws the length: ")

(setq length (+ distmis m))

(command "_text" breaks "0.15"" length)

Thank you so much in advance! !
 
m, indeed "m" is a string.
then to add a string to the measure you must also transform the measurement into string:
(setq length (strcat (rtos distmis 2 2) "m")
 
Thank you so much dieva, now it works perfectly! !

I have another question, if for example if I have 3 different lengths, always taken on my design and want to sum them as I can do? doing so that in the result are separated by a "+" moon on the other? es: 34+56+82m you can make a code that goes well even if the lengths become 5 or even are 2?
 
becomes a slightly more complex code, due to the variability of the number of operations.

you could add each dist measured to a list (setq list)
after you should "measure" how many items there are in the list (sslength list)
you should assign this number to a cycle and make a strcat of the text obtained by taking the new item of the list until the end of the items.
a thing of the type (setq text (strcat text "+" (nth n list)))
where n must vary from 0 to the total number of items of the list -1

It becomes a bit more complicated, but if you don't get hurt, you'll never be able to:)
 
Thanks for the tip! I think it's complex, I've already downloaded a good guide, and for those things I wanted to do before, I'll only start after I understand the basics well:)

I still have a question... If for example I want to put as a prefix, to a data that I go to give in the autocad command bar, for example 2x 3 m, with this code lisp:

(setq distmis (getdist "draws the length: ")

(setq length (strcat (rtos distmis 2 2) "m")

(setq nx (getstring "put how many times the length multiplies, es 2x, 3x, etc.)

(setq length2 (strcat (rtos nx 2 2) (rtos length 2 2))

(command "_text" breaks "0.13" breaks length2)

I am working to the point where I enter the value of 2x, then I close the programme :

Can someone help me?
 
Code:
(seq n 0 l2 nil)
(sing)
(if (setq distmis (getdist (strcat "\nindicates the length (" (rtos (setq n (1+ n) 2 0)")): ")
(setq l2 (if l2 (strcat l2 "+" (rtos distmis 2 2)) (rtos distmis 2 2))
(setq l2 (strcat l2 " m") nl)
)
)
(princ "\specify insertion point and rotation of text")
(command "_text" breaks "0.13" breaks l2)
 
Thank you so much for your help!! it works 10%% :)
a last thing only....if I want to wean the measured length (/2), where I can apply the dividing in the code placed above e.g. (/ 15 2) --> where 15 sata for 15m ... this because I want to optimize the change of scale ... I tried but I continually knead :(
Thank you so much!!
 
you must first understand what type data go to a variable and/or which type of a given count.

getstring lets you enter a string (text) regardless of which it is. even a number, given away getstring is a text.
getreal makes you enter real numbers (tenmal numbers, to understand, positive or negative)
getint makes you enter only whole numbers (without decimals)

If you can't multiply a string (when would 2xabc? )
goes by if coe can't concatenate two reals (how much would 1,234 attack to 3,456? )
then if you have a variable that contains a string (nx) you can't turn it into string (rects nx 2 2). It is already.

you must first clarify which types return certain commands and/or operations
for example we assimilate that aa is an int val.3 and bb is a real val.3 and cc is a string val.3
Is an int 10 divided aa possible? If yes, what result will you give?
Is an int 10 divided bb possible? If yes, what result will you give?
Is an int 10 divided cc possible? If yes, what result will you give?
 
so.... as it rightly observed crystal, the arithmetic operation must take place when the variable has a numerical value:

(rtos distmis 2 2) --> "3.80"

(rtos (/ distmis 2.0) 2 (2) --> "1.90"
 
Crystal, the first is possible while the other two did not judge? thanks for the explanation! !

gp that you had given me a tip on the variables before, I tried to put in place, but in the third line there is a problem, that is, it is not possible to divide by zero ...

(seq n 0 l2 nil)
(sing)
(if (setq distmis (getdist (strcat "\nindicates the length (" (rtos)/ (setq n (1+ n)) 2 0) 2) " ")
(setq l2 (if l2 (strcat l2 "+" (rtos distmis 2 2)) (rtos distmis 2 2))
(setq l2 (strcat l2 " m") nl)
)
)
(princ "\specify insertion point and rotation of text")
(command "_text" breaks "0.13" breaks l2)

thanks again and good continuation of the day to all!!
 
that instruction you have modified is related to the progressive number that is displayed at each length indication call (1), (2), (3), etc., and above all you have wronged the bracket position.

if you need to divide the distance you need to change the next line, i.e. the distmis variable, exactly as in my example above.
 
Crystal, the first is possible while the other two did not judge? thanks for the explanation! !
just in part:

int 10 divided real 3.0 = real 3.333
int 10 divided into 3 = int 3
int 10 diviso string 3= ; error: bad argument type
 
Thanks for the help dieva, gp and crystal! !
...but also to this forum:)
Now my lsp works great:))
good continuation of the day to all!
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top