Jump to content

Returning last user variable


Andrew1979

Recommended Posts

I want to display in the command prompt the last variable a user inputted.

 

I want it like the Offset command. In the offset command, it asks the user for a distance, and the next time the user runs the command offset remembers the last distance.

 

I am using getint.

 

I have this so far:

[color=red]([/color][color=royalblue]setq[/color]    MDF-WDE    [color=red]([/color][color=royalblue]getint[/color]  "\nEnter MDF thickness <[color=magenta]???[/color]> << "[color=red]))[/color]

 

The bit in the code where I have ??? is where I want to display the users last entry. How do I do this?

 

I have no idea how to write a variable inside the getint command, when I do put a variable in there, it fails to work.

Link to comment
Share on other sites

some of the gurus advice me few months ago to explore INPUTHISTORYMODE sysvar. Maybe I will find a way to make it work , but nothing good. You can try , may be you will succeed

Link to comment
Share on other sites

thanks, haven't heard of that command before....I thought you made it up until i tried it haha. Not sure if that is what I am looking for though. Can't seem to work out how the AutoCAD offset command works with showing the last offset in the command prompt text. I have tried multiple ways but can't work it out.

Link to comment
Share on other sites

lots of variables can be read in your case offsetdist (getvar "offsetdist") same with circle circelrad & fillet filletrad another lastpoint.

 

(setq offdist (getvar "offsetdist"))
(setq MDF_WDE (getint (strcat "Enter thicknes <" (rtos offdist 2 0) ">")))
(if (= MDF_WDE nil) (setq MDF_WDE offdist))

Link to comment
Share on other sites

thanks BIGAL, you are to the rescue again. I didn't know you could strcat inside a get function. Thanks

Link to comment
Share on other sites

just for reference for others, here is the code I used:

 

[color=red]([/color][color=blue]initge[/color]t [color=seagreen]6[/color][color=red])
[color=black][color=red]([/color][color=royalblue]if [/color][color=red]([/color][color=royalblue]= [/color]offdist [color=royalblue]nil[/color][color=red])([/color][color=royalblue]setq [/color]offdist [color=seagreen]18[/color][color=red])[/color]
[color=red]  )  [/color][/color]

[/color] [color=red]([/color][color=blue]setq[/color] MDF-WDE [color=red]([/color][color=blue]getint[/color] [color=red]([/color][color=blue]strcat[/color] [color=magenta]"\nEnter MDF thickness <"[/color] [color=red]([/color][color=blue]rtos[/color] offdist [color=seagreen]2 0[/color][color=red])[/color][color=magenta] "mm> << "[/color][color=red])))[/color]
[color=red]([/color][color=blue]COND[/color] [color=red]([/color][color=blue][color=red]([/color]= [/color]MDF-WDE[color=blue] nil[/color][color=red])([/color][color=blue]setq[/color] offdist offdist[color=red])([/color][color=blue]setq[/color] MDF-WDE offdist[color=red]))[/color]
     [color=red](([/color][color=blue]/=[/color] MDF-WDE [color=blue]nil[/color][color=red])([/color][color=blue]setq[/color] offdist MDF-WDE[color=red])([/color][color=blue]setq[/color] MDF-WDE MDF-WDE[color=red]))[/color]
     [color=red])[/color]

This code returns the last value entered by a user and shows it in the command prompt. If the user then presses enter without typing anything, it will use the last number used.

Edited by Andrew1979
Link to comment
Share on other sites

Code redone applying a variable as its existing value is not needed.

 

(initget 6)
(if (= offdist nil)(setq offdist 18)
 )  

(setq MDF-WDE (getint (strcat "\nEnter MDF thickness <" (rtos offdist 2 0) "mm> << ")))
(if (= MDF-WDE nil)(setq MDF-WDE offdist)(setq offdist MDF-WDE)) ; updates value of offdist for next time

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