Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Looping DIESEL Macro with user input menu

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
jmkras
1395 Views, 9 Replies

Looping DIESEL Macro with user input menu

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

9 REPLIES 9
Message 2 of 10
pendean
in reply to: jmkras

Your macro doesn't seem to do anything here in LT2017 Is something else missing?
Message 3 of 10
steven-g
in reply to: jmkras

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.

Message 4 of 10
steven-g
in reply to: jmkras

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.

 

Message 5 of 10
steven-g
in reply to: jmkras

Still haven't fully worked out the idea behind the macro, but deleting the ^C and the ^Z at the end, looks as though it allows the macro to repeat which will allow your block to be inserted the number updates and cycles again.

Message 6 of 10
jmkras
in reply to: steven-g

So the idea for the macro is that it will give the user the option of what type of block it will insert to number doors, windows, rooms.  I've only started writing the macro and encountered a problem.  The macro prompts the user for the type of numbering that will be used, right now door or room.  You enter 1 or 2 which should change the variable 'u'.  This variable will tell the macro which if statement to follow.  Then the user is prompted for the starting number of the door, window,  or room.  I get the macro to run, but it doesn't appear to change the variable u.  I have to run the macro and then run the macro again for it to work.  It won't loop on its own.  It seems to read the initial variable 'u' as zero, which is correct, but does not update it on the user input until after the macro has completed the first pass.  It still thinks 'u' is zero and so doesn't go any further.  I have to execute the macro again for it to follow the if statement that I want and even then it only goes through it once.  It won't keep looping and inserting blocks with consecutive numbers.  
Message 7 of 10
steven-g
in reply to: jmkras

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.

Message 8 of 10
steven-g
in reply to: jmkras

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.

Message 9 of 10
steven-g
in reply to: steven-g

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.

Message 10 of 10
jmkras
in reply to: steven-g

Thanks for taking the time with this. I've gone around and around for a
few weeks trying to get this to work. I agree that it seems to be the user
input that makes it difficult. I have other macros where the macro ups the
value of "u" and it works fine. I'll continue to refine it and see if I
end up with something that works.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report