avscorey Posted February 10, 2010 Share Posted February 10, 2010 Hello all. Thanks in advance for any help you can provide. I'm new to the forums here as well as to VBA. I've been teaching myself over the past couple of months and have come across a problem that I can't seem to figure out on my own. Here's the situation. I have set up a userform in which I am asking the user for various inputs, namely a start point and an endpoint to the path that the form will create. I have set up buttons for the user to pick these points on screen and then the point is displayed in text boxes afterward. That part works fine. I then used the savesetting and getsetting commands so that if the user runs the form again the old values show up as the default. (The same way that say the offset command remembers the last distance used.) This also works fine. Here is my issue. When I open a new drawing and run the userform the textboxes still show the values from the other drawing. How do I clear the setting values to show a default (say 0,0) when a new drawing is started as well as when a drawing is opened. (Again, a la offset where it defaults to zero everytime you open or do a new drawing) I've tried all kinds of searches but can't seem to find what I need. I believe that I have to do something with the BeginOpen event but I haven't tried programming with events yet and am not quite sure how to handle those. Any help is appreciated. ~Corey Architectural Veneer Systems, Inc. EDIT: I also need help in another area. I'm also trying to simulate the preview portion of the hatch command where you can left click to accept it or right click to return to the dialog box. What's the code to register mouse clicks and then do stuff? Quote Link to comment Share on other sites More sharing options...
Pablo Ferral Posted February 10, 2010 Share Posted February 10, 2010 Maybe you need to save your settings in the drawing? Quote Link to comment Share on other sites More sharing options...
avscorey Posted February 10, 2010 Author Share Posted February 10, 2010 how would I go about doing that? Quote Link to comment Share on other sites More sharing options...
Pablo Ferral Posted February 10, 2010 Share Posted February 10, 2010 OK, I'm really hoping that someone who knows a bit about VBA could step in here. With Autolisp all variables are stored in the drawing, all the time (Unless you specifically declare them locally). This would keep your default settings, for also long as the user keeps the document open. If you wanted these settings to persist outside the current document I'm guessing that with VBA you could use the 'On close' event to write your settings out... Quote Link to comment Share on other sites More sharing options...
dbroada Posted February 10, 2010 Share Posted February 10, 2010 With Autolisp all variables are stored in the drawing, all the time (Unless you specifically declare them locally). not entirely true. I don't write LISP very often these days so will probably get this wrong but in LISP there are a number (4 or 6?) INTEGER, REAL & STRING variables available for use. Some of these are stored in the current drawing but some die on exiting - and I can't remember which are which. I think - but I have never tried - these variables can be exposed through VBA. Try using the VBA GETVAR & SAVEVAR on the USERS1 variable to see if it works or if it has persistance. I'm away from AutoCAD for a few days so I can't give explicit help but hopefully I have given a useful nudge. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 10, 2010 Share Posted February 10, 2010 OK, I'm really hoping that someone who knows a bit about VBA could step in here. With Autolisp all variables are stored in the drawing, all the time (Unless you specifically declare them locally). This would keep your default settings, for also long as the user keeps the document open. If you wanted these settings to persist outside the current document I'm guessing that with VBA you could use the 'On close' event to write your settings out... Not sure about VBA as the original poster wanted, but to store the settings as I have done in this, you could write to a config file. Quote Link to comment Share on other sites More sharing options...
Joro-- Posted February 11, 2010 Share Posted February 11, 2010 This can be done using the registry where you can store the valuees of the variables and for the OnInitialize event of the user form load the last ones saved. Saving the values you can put in the OnTerminate event of the user form, or in the code for the Close button of the userform. I've done something similar about 2 years before.... Quote Link to comment Share on other sites More sharing options...
SEANT Posted February 11, 2010 Share Posted February 11, 2010 Another option is to set up a custom Dictionary (Help – ActiveX and VBA Reference –Objects – Dictionary object) system that can store the appropriate info as xrecords, which are saved with each DWG file. When your form is activated it can search the current drawing (ThisDrawing) for the appropriate xrecord, if it finds – one retrieve the xrecord’s values, if it doesn’t find one – create the Dictionary to store and return the default xrecord values. Quote Link to comment Share on other sites More sharing options...
Pablo Ferral Posted February 11, 2010 Share Posted February 11, 2010 With Autolisp all variables are stored in the drawing, all the time (Unless you specifically declare them locally). This would keep your default settings, for also long as the user keeps the document open. If you wanted these settings to persist outside the current document I'm guessing that with VBA you could use the 'On close' event to write your settings out... not entirely true. I don't write LISP very often these days so will probably get this wrong but in LISP there are a number (4 or 6?) INTEGER, REAL & STRING variables available for use. Some of these are stored in the current drawing but some die on exiting - and I can't remember which are which. I think - but I have never tried - these variables can be exposed through VBA. Try using the VBA GETVAR & SAVEVAR on the USERS1 variable to see if it works or if it has persistance. Thanks for the clarification, I didn't explain myself too well there, but that's what I was getting at! Quote Link to comment Share on other sites More sharing options...
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.