I'm trying to create a macro that will present the user with a couple of options which they will select by entering a number. Based on their entry the macro will execute specific tasks. So far I get the menu to work but I cannot get the macro to loop even when I include an asterisk in front of it. Below is the macro that I've written.
*^C^C$M=$(if,$(=,$(getenv,u),0),osmode;0;attreq;1;attdia;0;modemacro;$(getenv,ns);setenv;u;\modemacro;$(getenv,sn);setenv;number;\modemacro;.;)$(if,$(=,$(getenv,u),1),-i;n_tag;\$M=$(/,1,$(getvar,cannoscalevalue));$M=$(/,1,$(getvar,cannoscalevalue));0;$M=$(getenv,number);setenv;number;$(+,1,$(getenv,number));^C)^Z
ns = Type of numbering: [1] Door, [2] Room
sn = Enter the starting number:
u = 0
Solved! Go to Solution.
Solved by steven-g. Go to Solution.
We will need a bit more info here, without spending hours trying to decipher what your intentions are in this macro, it would help if you explain what the thought process is.
As it stands it appears to run correctly but there is no way of knowing what the expected input is for the macro to work unless you tell us.
There are a couple of things you could try, that might help you find the problem
1: If you don't already use it - set macrotrace=1 this is a variable that when active will show you the output from the diesel expressions at the command line and can be useful in debugging. (macrotrace has to be set each time you need it it isn't saved with the drawing
2: Place a couple of fields in your drawing that populate with the enviromental variables you are using - create fields with a diesel expressions as $(getenv,ns) for each variable, you need to run regen before they update but it will show you how things are running in the macro. see the attached dwg
I can get as far as inserting the block, but trying to follow the sequence is difficult, it really would help if you spelt out the the logic behind the input you are expecting.
It would really help if you gave an explanation of the sequence of the user input and what options you expect to be used. Diesel isn't designed as a programming language and it's quite difficult to follow the logic. I have got as far as inserting a block, but not 100% through the whole thing.
Just a couple of points that might help you figure out where it stops.
1) if you don't know of it there is an undocumented variable "macrotrace" setting that to a value of 1 will show you the steps diesel is doing if you look at the command history, it's not always easy to follow but often gives clues if there are problems. It's a variable that always defaults to 0 on startup so you need to set it each time you need it.
2) place some fields that report your environmental variable values, that way after you have run the macro you can at least see that everything updated as you expected or at least up to which point correct values where updated (see the attached it uses a diesel expression in a field - fields need to have the regen command operated before they update)
I will take a look later see if I can fully understand what you are trying to do with the macro , it would be nice if you could explain the logic of what it is supposed to be doing. It could be a misplaced character somewhere, there is also supposed to be limit to the number of characters allowed in a diesel macro which could be the case here.
That sheds more light on the problem, unfortunately thats how macro's work, the values don't get updated untill the macro has exited, there is no way around that. I'm pretty sure I had a working macro that allowed a multiple choice if statement, but that was years ago, I'll see if I can find it and figure out how it might help in your situation, it might take me a while to find it I need to dig through some old hard drives.
Found the example macro, I'd posted it here many moons ago choose an option, it shows the layout for a multiple choice input, similar to what you appear to be trying, I'm still struggling with your macro, it's got to be something so simple but I can't see it yet and the macrotrace output isn't helping a right lot, I'm going to break it down into manageable chuncks see what falls out.
I'm going batty here, but I think I figured it out, the logic of your macro looks fine, there are a couple of places it would fail missing comma's and parenthesis in wrong places, and I tried all sorts to get that ordered correctly.........
But that isn't the problem - the idea behind diesel "Dumb Interpretively Evaluated String Expression Language" is to manipulate strings and it does that just fine, the example I linked to above returns for each case a single letter but it is a string and Autocad can understand that and uses it to start a command.
Your diesel returns the correct string as well, but you want your string to be used as a macro which pauses and accepts user input, but Autocad see's it as a string which could in theory be used to dump a string of commands at the command line, but that is a script and a script can't pause and wait for user input, and a script uses a different syntax to a macro.
I could be wrong on this, but when you look at the output from the command line with this in mind then it starts to make sense
Changing your 1st output results in the case of u=0 to script format (spaces in place of ";" and drop it into the command line and it works up to the point where it needs user input. I just kept getting stuck with the fact that if you changed U=1 then the insert block worked just fine, set u=0 and the whole thing failed, and the results from macrotrace just didn't add up, but because of a missing comma in your macro when you set u=1 then the macro actually still fails, but it carries on and performs the remaining commands as they were designed and goes back and repeats them just as if it was working, when u=0 the macro again fails but in this case it stops.
So long story short the diesel expression returns a string and not a variable macro, but I do hope I can be proven wrong, because the idea is great, but bearing that in mind there is still probably a way of getting it to do what you want, you just need to rethink the logic, and approach it from a different angle.
Can't find what you're looking for? Ask the community or share your knowledge.