Jump to content

Error. Variable setting.


dilan

Recommended Posts

Hello.

In my program, I'm trying to assign a variable to a variable through a dialog:

:edit_box{label=Text Height;key=get_txtheight;edit_width=5;value=2;}

Then:

(setq TextHeight (atoi (get_tile "get_txtheight")))

Then I want to assign a system variable TEXTSIZE the value of its local variable TextHeight:

(setvar "TEXTSIZE" TextHeight)

But there are problems, if I enter through a dialog a value for example 2.3, for a variable TEXTSIZE is always assigned integer 2. Or I get an error that setting the system variable TEXTSIZE rejected.

I tried to use rtos, but nothing has changed ...

Help please advice.

Edited by dilan
Link to comment
Share on other sites

I think you should look at your action_tile calls.

(action_tile "accept" "(setq TextHeight (atoi (get_tile \"get_txtheight\"))) (done_dialog 1)")

Link to comment
Share on other sites

' DIMZIN also affects real-to-string conversions performed by the AutoLISP rtos and angtos functions' or maybe just units setting?

 

 

https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2019/ENU/AutoCAD-Core/files/GUID-A1860981-FE1C-4947-927B-7CD6B8CEF8EE-htm.html?st=DIMZIN

 

 

The atof command should work though.

 

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/atof-precision/td-p/836324

Link to comment
Share on other sites

Nothing helps.

If I enter a value of 2.6, then the variable is assigned to 3.

If I enter 2.2 then 2.

Numbers are always rounded up to integers.

Link to comment
Share on other sites

Nothing helps.

If I enter a value of 2.6, then the variable is assigned to 3.

If I enter 2.2 then 2.

Numbers are always rounded up to integers.

 

 

possible to post your code?

Edited by rlx
Link to comment
Share on other sites

or maybe :

 

 

http://www.cadtutor.net/forum/showthread.php?39358-Text-height-problem

 

 

I think it is a problem with the Precision setting of your Units. Check it out. You probably have it set to "0". Change it to "0.0000" and see what happens.

 

 

p.s. I assume you're not working with text styles that have a fixed height?

Edited by rlx
Link to comment
Share on other sites

What happens if you manually enter the following at the command-line:

(setvar 'textsize 2.5)

Then:

(getvar 'textsize)

 

I successfully assign variable 2.5

Then I also successfully get the value of the variable 2.5

 

I guess the problem is in the code of the program itself.

I will think ... look for this error

Link to comment
Share on other sites

I successfully assign variable 2.5

Then I also successfully get the value of the variable 2.5

 

I guess the problem is in the code of the program itself.

I will think ... look for this error

 

 

somewhere along the line your value is incorrectly converted , either by rtos with wrong precision (rtos textheight 2 2) or wrong use of fix / atoi or you somehow recycle your value by not localizing it whatever. Hard to tell without seeing the code.

Link to comment
Share on other sites

I understood all the comments.

I will correct the error myself. Thank you very much for your help and advice.

When I get it, I'll write here what the error was.

Link to comment
Share on other sites

As it seems to me I understood the error ..

(setq fp (vl-filename-mktemp "tempfile.dcl"))
(setq fdcl (open fp "w"))
(write-line
	"
	dcl_test 
	: dialog 
{label = \"Coordinates\";
spacer;
:spacer{height=0.5;}
:column{label = \"Options  \";
:edit_box {label = \"Rounding coordinates:\"; key = \"get_round\"; edit_width=5; value = \"3\";} 
:edit_box {label = \"Text Height:\"; key = \"get_txtheight\"; edit_width=5; value = \"2.5\";}
:spacer{height=0.5;}}
:spacer{height=0.5;}
spacer;
:button{key = \"acept\";label=\"Next\";is_default = true;height = 2;fixed_width = true;alignment = centered;}
:button{key = \"cancel\";label=\"Exit\";height = 1;fixed_width = true;alignment = centered;}
}
	"
	fdcl
)
(close fdcl)
(setq dcl_id (load_dialog fp))
 (if (new_dialog "dcl_test" dcl_id)
   (progn
     (setq Round_xy (atoi (get_tile "get_round")))
     (setq TextHeight_xy (atof (get_tile "get_txtheight")))
     (action_tile "acept" "(done_dialog 1)")
  (action_tile "cancel" "(done_dialog 0)")
     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;      
     (unload_dialog dcl_id) (and fp (vl-file-delete fp))
	)
   (progn (alert "Unable to load the dialog!") (and fp (vl-file-delete fp)))
)

In these lines of code my local variables Round_xy, TextHeight_xy get values from :edit_box - value =, if I enter another value in the dialog from :edit_box,

then they are not assigned to my variables. And values are always assigned by default (:edit_box - value = )

And I do not understand how to fix it ...

 

I understand that I'm starting with one problem and switching to another. I just try to figure it out myself. Sorry.

Link to comment
Share on other sites

then they are not assigned to my variables. And values are always assigned by default (:edit_box - value = )

And I do not understand how to fix it ...

Hi,

 

Move them into the 'acpt' action.

Link to comment
Share on other sites

Hi,

 

Move them into the 'acpt' action.

Thank you so much. And earlier I was given this advice in this topic, but I thought the problem was different.

(action_tile "acept" "(setq TextHeight_xy (atof (get_tile \"get_txtheight\"))) (setq Round_xy (atoi (get_tile \"get_round\"))) (done_dialog 1)")

Now everything works as it should.

Once again, thank you all.

Link to comment
Share on other sites

I think you should look at your action_tile calls.

(action_tile "accept" "(setq TextHeight (atoi (get_tile \"get_txtheight\"))) (done_dialog 1)")

 

Thank you. That helped.

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...