nila_joy Posted June 5, 2012 Posted June 5, 2012 Hi, I am using Change / Ok / Cancel button .. if I press Change , the change will be done, if press OK, the dialog box will close with the changes done. .. but if I press cancel button, it will undo the all operations done by "change" button .. any idea how to handle Undo in autolisp. .. Subho India Quote
BlackBox Posted June 5, 2012 Posted June 5, 2012 I'm not sure I understand the question fully... Rather than giving the user option to Change, OK (which also makes changes), and Cancel, simply provide OK and Cancel. If OK is selected, make changes. If Cancel is selected do not make changes. Separately, setting undo marks depends on the code being executed; if using Command calls, use the Undo Command. If using the ActiveDocument Object, consider the StartUndoMark and EndUndoMark Methods. HTH Quote
MSasu Posted June 5, 2012 Posted June 5, 2012 The Windows standard naming for said Change button is Apply – you may consider using this caption for consistency. Also don’t forget that there are some limitations regarding accessing drawing while the dialog box is active - worst scenario is that it may crash your AutoCAD; may be better to consider RenderMan’s suggestion and keep only OK and Cancel buttons. Quote
nila_joy Posted June 5, 2012 Author Posted June 5, 2012 actually I have to do 5 changes one by one. after setting for 1 change, user will press "Change" button , and the change will be done .. now if I press "OK" button, the changes will be reflect .. and if I press "CANCEL" button.. all changes will be terminate , but if I alredy hit the button "Change" before "Cancel" , so the changes are already done, and I have to undo all those changes. Quote
BlackBox Posted June 5, 2012 Posted June 5, 2012 This makes my point... You're complicating the task by allowing changes prior to OK/Apply. Simply gather the input from the user (via the form controls, buttons, etc.) _then_ make the changes, only if the user selects OK/Apply, etc. Quote
irneb Posted June 6, 2012 Posted June 6, 2012 Actually if you want to have your "Change" button work the same as all normal "Apply" buttons, then all it does is the exact same thing as the OK button - just not also closing the dialog. So to stick with the normal way all programs work in Windows, you need not worry about undoing changes if Cancel is pressed. If you do want to be able to keep track of "Change" button presses, you might consider saving the values of the tiles into a list each time Change is pressed. Don't do anything else. Then only when OK is pressed step through that list and perform the actions as if each time change was pressed. That way you get this "Cancel" means "Undo" effect you're referring to without needing an actual Undo. Quote
wishbonesr Posted August 30, 2012 Posted August 30, 2012 You never know what angle another programmer is coming from... Assuming you know is making an a... See if this method works for you The below is more of an order of events rather than exact code to be plug and played. (vl-load-com) ;be sure to call before executing visual lisp functions - recommended at the beginning of your program (setq dwgobj (vla-get-activedocument (vlax-get-acad-object))) ;obtain the activeX docuement object ;somewhere before your dialog or at dialog load (vla-endundomark dwgobj) ;end it, just in case you or some other code left it open (vla-startundomark dwgobj) ;start a new one <other prep work> ;start your dialog <your modify code or action tiles> (action_tile "cancel" (vla-sendcommand dwgobj "u ")(done_dialog) ;there is a space after the u ; u is actually a command, not an alias, however a user could redefine it with an alias or other means ; then you'd be left to send "_undo " <- that is a double space But here I go at it myself -> I believe it's better to track what your doing, so that the work can be reversed, in leiu of undo. Ex. Store old values, and new values in a list or on the object themselves wiht xdata. If deleting objects, then consider turning the visibility of the object off, and hitting it with xdata, or track in a list, and then when 'committing' the deletion, iterate the delete list, or if stored in xdata, iterate the objects in the drawing (or ssget filter -3) and erase objects that have your xdata delete signature. It's more elegant, if you track on the object with xdata or your own dictionary xrecords, thus can be recoverable if your program crashes. Quote
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.