Father forgive me. It has been two weeks since my last blog post. I apologize everyone for the long interval but things have been crazy. In addition to some long nights at my day job, I am in the process of releasing a new version of InspectionXpert, the Quality Inspection Sheet generating software from my company Extensible CAD. It is a rewarding endeavor but also very demanding.
Anyways… not so long ago I posted a Macro & tutorial on how to register for SolidWorks events. One application of that technique that I mentioned was to automatically generate document numbers for your SolidWorks document and insert them into SolidWorks “auto-magically.” Well, not too long thereafter I was bombarded with emails asking me to post that little Macro and I promised to do so. This post is the fullfillment of that promise. I’m sorry it took so long but I think you guys will like it. I feel it is “auto-magically delicious” myself : )
You can download the database and the macro from here.
Keep reading to see a flash video of the macro in action…
The Macro In Full Effizact
Disclaimer: As I am pretty pressed for time, as usual, I have not added any error handling to this macro. You will have to do that yourselves. At some point in the future (here I go making promises again), I will add a post on error handling with VBA.
What this Macro does: If you didn’t understand the movie then (please check your home’s water for lead contamination) this macro registers with SolidWorks to receive notification (aka ‘callback’) when a new file is created in SolidWorks (i.e. File, New). The official Event is ‘FileNewNotify2′ and when fired, the macro will determine the type of file (e.g. SLDASM, SLDDRW or SLDPRT) and then use ActiveX Data Objects, ADO, to contact an MS Access database to find out the next available document number for that document type. The document number is then written to the new document title, in essence the filename, and then the number in the database is incremented by one so that next time the document will have a unique number.
How Do You Set It Up?
Getting the Conection String To The Database
Here is a link to a flash video showing how to get the connection string. I tried to add it to the post but I can only have one flash in the same post with the flash video player that I am using. FYI – I tried a few flash players but I’m not that happy with any of them. If anyone is aware of a stellar flash plugin for wordpress, then please suggest it.
That’s it. That wasn’t too bad now was it?
Note: If anyone wants to turn this into a SolidWorks Add-in then you can post it here for the masses. I will give you full credit. I am too busy right now to do that (unless it was for money : )
If you enjoyed this post, make sure you subscribe to my RSS feed!
If you use the Macro and like it or learn something from it, then please add a comment or drop me a line to let me know.
Thanks,
Jeff
Great info! I’ve been looking to add something similar to the custom property macro I made for my work. Instead of adding on a new part I’ll recode it to be a button press inside my current macro.
Very helpful tho. My IT guy eventually wants to change from an MS Access database to a full up SQL server. Any idea on the code differences on the Solidworks end for the same functionality? I’m sure my guy knows, but I’m curious so I know what to expect and how to change the code when that time comes. I’m pretty noobish as it comes to code like this from scratch, but I can get by pretty well with good examples.
Thanks,
James
Thanks for the kind words James. SQLServer Express is extremely easy to use, is very powerful and is free. There are a bunch of video tutorials on the asp.net homepage to help you get started.
http://www.asp.net/learn/sql-videos/
You should also consider switching your macro to visual basic.net express (also free). Good luck.
Jeff,
I downloaded your MS Access DB PN Generator Macro. Your work saved the day! I’m not a programmer, but was able to get your macro working just as you described. Your Flash video was very helpful in setting up the data source. This will allow me to focus on design not on how or what I should name my files. It also insures that every file is uniquely named, something any Solidworks user should never work without!
Keep up the great work!
Thanks Rodney. I am glad it helped you. That is the whole reason I do this so thanks for letting me know that my efforts helped.
Jeff
Hi Jeff,
Great work with this one. I have one question though which is –
I have a client that has a limited prefix code for his numbering system.
Would it be possible to create multiple part templates and link them to a query to get the next number sequence for that particular prefix?
eg DBA.slddot gives me a DBA-10022
GRA.slddot gives me a GRA-10014
etc
Thanks
Derek