nparse function

nparse function

Moshe-A
Mentor Mentor
793 Views
5 Replies
Message 1 of 6

nparse function

Moshe-A
Mentor
Mentor

hi guys,

 

it's been a while since i visit here to give my help (soon i'll be back) but now i have one of my own  😀

i need a function to parse the value (coming from sysvar cannoscalevalue) and i like it to be recursive.

 

it's now getting 2 args:

1.  n (which is cannoscalevalue can be 0.1 0.01 0.001 etc and each iteration is multiplied by 10) 

2.  s (each iteration it also multiplied by 10)

 

so here is what i have:

 

 

(defun nparse (n s)
 (cond
  ((>= n 1) s)
  ((nparse (setq n (* n 10)) (setq s (* s 10))))
 )
)

 

 

uses: (nparse 0.01 1)

 

but i do not like the 1 arg for s to reset, wonder if someone can come up to a version to drop the 1.

 

thanks in advanced

Moshe

 

 

0 Likes
Accepted solutions (2)
794 Views
5 Replies
Replies (5)
Message 2 of 6

cadffm
Consultant
Consultant
Accepted solution

I don't understand this limited function, what do you expect with this?

I am talking about your cannoscale sample ONLY.

cannoscalevalue is a factor, so you can have all floats reals and floats a value,

your functions works only for scalefactor less 1 and all greater one reverts 1 as value.

I can't understand what you want to do with this result / with this function?

I would understand a function like this:

(defun nparse (n / s)
 (/ 1.0 n)
)

 

Please take a minute to explain me, what you want to do with your function and

why you want a 1 if the scalefactor is greater than 1

and why you want 100 as result if the scalefactor is 0.02 for example.*

 

Sebastian

0 Likes
Message 3 of 6

Moshe-A
Mentor
Mentor
Accepted solution

wow, in 3 words @cadffm : YOU ARE BRILIANT 👋

 

(/ 1 n) just covers everything.

 

what i wanted to know is the actual running linetype scale as in my understanding when msltscale in on...in model space the actual ltscale is the annotation scale e.g :

(* (1 / (getvar 'cannoscalevalue)) (getvar 'ltscale))

 

Am i right?!

 

thank you very much

Moshe

 

 

 

 

 

0 Likes
Message 4 of 6

dbroad
Mentor
Mentor

Like @cadffm , I'm puzzled.

(getvar "cannoscale") will get you the name for the current annotation scale.

(/ 1.0 (getvar "cannoscalevalue")) will get you the denominator of 1:n ratio of the current scale.

 

Example:

Command: (getvar "cannoscale")
"1-1/2\" = 1'-0\""

Command: (getvar "cannoscalevalue")
0.125

Command: (/ 1.0 (getvar "cannoscalevalue"))
8.0

So that is the same as a ratio of 1:8.0

 

 

 

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 5 of 6

Moshe-A
Mentor
Mentor

@dbroad  hi,

 

(getvar "cannoscale") 

(/ 1.0 (getvar "cannoscalevalue"))

 

it is not exactly the same,  (getvar "cannoscale") returns a string the name of the scale list defines in SCALELISTEDIT and you can not relay on that, users often make mistakes. 

 

 

 

0 Likes
Message 6 of 6

dbroad
Mentor
Mentor

I think I made it clear that they were different but related.  See the command return values.  All you needed was (/ 1 n) where n was the annoscalevalue.

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