Grrr Posted March 10, 2016 Share Posted March 10, 2016 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? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 10, 2016 Share Posted March 10, 2016 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 Quote Link to comment Share on other sites More sharing options...
Grrr Posted March 10, 2016 Author Share Posted March 10, 2016 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))" Quote Link to comment Share on other sites More sharing options...
David Bethel Posted March 10, 2016 Share Posted March 10, 2016 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 Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 10, 2016 Share Posted March 10, 2016 David , I don't think the OP is talking about any System Variable. @OP , what are you trying to do with initget in your example? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 10, 2016 Share Posted March 10, 2016 Yes, I forgot to add strcat! But I have no idea how to add the quote to initget. This is not necessary, as the default value is not a keyword. Quote Link to comment Share on other sites More sharing options...
Grrr Posted March 10, 2016 Author Share Posted March 10, 2016 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 10, 2016 Share Posted March 10, 2016 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. Quote Link to comment Share on other sites More sharing options...
David Bethel Posted March 10, 2016 Share Posted March 10, 2016 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 Quote Link to comment Share on other sites More sharing options...
Grrr Posted March 10, 2016 Author Share Posted March 10, 2016 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 ! Quote Link to comment Share on other sites More sharing options...
David Bethel Posted March 10, 2016 Share Posted March 10, 2016 (edited) Since LTSCALE cannot accept 0 for the value then + 4 2 (initget 6) http://docs.autodesk.com/ACD/2013/ENU/index.html?url=files/GUID-9ED8841B-5C1D-4B3F-9F3B-84A4408A6BBF.htm,topicNumber=d30e618800 Edited March 10, 2016 by David Bethel Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.