Jump to content

Passing a (real number) quote to a variable


Grrr

Recommended Posts

Hi,

I am trying to pass a value of a real number to a variable:

    (setvar "tilemode" 0)
   (setq ssVP (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 (getvar 'ctab)))))
   (setq curScale (vla-get-CustomScale (vlax-ename->vla-object (ssname ssVP 0))))
   (setvar "tilemode" 1)
   (princ (strcat "\nCurScale "(rtos curScale 2)" "))

   (initget (+ 4))
   (setq newLTSCALE (getreal "\nInput LTSCALE value <" (rtos curScale ) ">: "))
   (if (not newLTSCALE) (setq newLTSCALE 1 ))

It returns this:

CurScale 0.004
Error: too many arguments

I don't get why it won't accept the value (in this case its 0.004) as a default answer?

Link to comment
Share on other sites

Hi,

 

You need to use strcat function to gather the message text with the curScale variable in getreal statement.

Have a look about the use of your initget function again

Link to comment
Share on other sites

Hi, Tharwat,

Yes, I forgot to add strcat! But I have no idea how to add the quote to initget.

I tried this:

    (setvar "tilemode" 0)
   (setq ssVP (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 (getvar 'ctab)))))
   (setq curScale (vla-get-CustomScale (vlax-ename->vla-object (ssname ssVP 0))))
   (setvar "tilemode" 1)
   (princ (strcat "\nCurScale "(rtos curScale 2)" "))

   [b](initget "(+ 4) CurScale" )[/b]
   (setq newLTSCALE (getreal (strcat "\nInput LTSCALE value <" (rtos curScale ) ">: ")))
   (if (not newLTSCALE) (setq newLTSCALE (rtos curScale ) ))

It returns:

Error: AutoCAD variable setting rejected: LTSCALE "0.004"

Can you give me any hints? I've never used quotes in initget function (and even less with "bit control values" (no negatives))"

Link to comment
Share on other sites

You have converted the value to 'STRing (rtos). The sysvar is expecting a 'REAL

 

You are using a symbol as both a name and a value. Try to segregate variables / strings / keywords etc as uniques. It is less confusing

Link to comment
Share on other sites

Hi David,

I tried without STRing (rtos), but still was getting an error. I wasn't sure about this but you comfirmed it with your comment:

You have converted the value to 'STRing (rtos). The sysvar is expecting a 'REAL

Tharwat,

I'm trying to read the value of an viewport's scale (from an layout tab) and put that same value on the LTSCALE variable.

For every layout tab I have only one viewport with the same custom scale (in this case the value is 0.004).

So either prompt to change LTSCALE and accept as default "CurScale", either apply directly the "CurScale" value to the LTSCALE variable.

I hope thats clear, thank you for answering! :)

EDIT:

Lee,

This is not necessary, as the default value is not a keyword.

I understand now, but as David mentioned the variable doesn't accept none of " CurScale " and " (rtos CurScale)" as its default answer.

Link to comment
Share on other sites

I understand now, but as David mentioned the variable doesn't accept none of " CurScale " and " (rtos CurScale)" as its default answer.

 

Yes, the variable should be converted to a string for use in the prompt message, but remain numerical when setting the system variable value.

Link to comment
Share on other sites

For consideration :

 

[b][color=BLACK]([/color][/b]defun c:test [b][color=FUCHSIA]([/color][/b]/ ssvp cs ns[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]setvar [color=#2f4f4f]"tilemode"[/color] 0[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq ssVP [b][color=NAVY]([/color][/b]ssget [color=#2f4f4f]"_X"[/color] [b][color=MAROON]([/color][/b]list '[b][color=GREEN]([/color][/b]0 . [color=#2f4f4f]"VIEWPORT"[/color][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 410 [b][color=BLUE]([/color][/b]getvar 'ctab[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq cs [b][color=NAVY]([/color][/b]vla-get-CustomScale [b][color=MAROON]([/color][/b]vlax-ename->vla-object [b][color=GREEN]([/color][/b]ssname ssVP 0[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setvar [color=#2f4f4f]"tilemode"[/color] 1[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]initget 6[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq ns [b][color=NAVY]([/color][/b]getreal [b][color=MAROON]([/color][/b]strcat [color=#2f4f4f]"\nInput LTSCALE value <"[/color] [b][color=GREEN]([/color][/b]rtos cs[b][color=GREEN])[/color][/b] [color=#2f4f4f]">: "[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]or ns [b][color=NAVY]([/color][/b]setq ns cs[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]setvar [color=#2f4f4f]"LTSCALE"[/color] ns[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

 

Autolisp can be elegant and simple at the same time

 

-David

Link to comment
Share on other sites

Thank you, David!

Well I might need to read more carefully about initget function,

I used (initget (+ 4)) to get real non-negative values, but I didn't know that (initget 4) does the same job. (I don't remember where I got that (initget (+ 4)) example from)

 

You guys are very skilled so it might be simple for you

and I'm happy that you support beginners like me (simple mistakes like this are very annoying for the unexperienced eye).

I'll keep up with my learning intention, thank you all ! :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...