HOW TO CHANGE/SWAP TEMPLATE/SYSTEM OPTIONS IN SOLIDWORKS

I have heard this request many times so putting it up over here. The whole credit for this should go to Stefan Berlitz of http://solidworks.cad.de/ http://swtools.cad.de . Without his wonderful macro, this option might not have been possible.

Before starting the process I will strongly advise you to make a backup of the files.

  1. Open you part, drawing or assembly file from which you want to copy the Tool, Options> System Options /Document Properties Settings.
  2. Open the Excel based macro and choose the tab based on type of you file.
  3. In the Excel sheet, click on Get Options. This will copy the Document Properties Settings for that particular file. Repeat same for System Options.
  4. Close the SW file.
  5. Now open you part, drawing or assembly file to which you want to copy these setting or overwrite their setting with these one.
  6. Go back to Excel sheet and click on Set Options for both System Options and Document Properties Settings.

Cool, enjoy with your new part, drawing or assembly file template.

Get the macro here: mac_copydoc.zip

Lot of thanks to Stefan Berlitz for sharing his macro. He has also explained how to use this macro in a much efficient way in the same excel file.

New type of SaveAsPDF macro

SolidWorks is able to save drawings and current model views as a PDF format file.  SaveAsPDF with Folder SelectionThere’s been a lot of macros written over the years that cut the process of saving as PDF down to as few steps as possible. One of the long standing requests for this type of macro (and many similar types of macros) is to allow the user to pick the save location. Just uploaded is a macro (SaveAsPDF with Folder Selection) that does just this, and simplifies the location selection process for default folders. This new macro also uses more modern API techniques to save the file (using modelext::saveas instead of model::saveas4).

This macro does many things that previous macros haven’t.  While allowing the user to establish a default save location folder, it also provides automatic alternative choices when the default is not available.  Yet, even with all of these, the user can still override automated selection and pick a new location.  It does all of this without the use of VB6 forms.

As with other macros that do similar tasks, this will work best when assigned to a keyboard shortcut or a toolbar icon.   Also, as with all SolidWorks macros, there is a chance it will not work “out-of-the-box”.  This is normally due to the fact that SolidWorks updates core reference libraries with each release.  If errors are encountered, simply re-reference to the libraries that are available to allow the macro to function.  More information about that is available in this previous article.

3DConnexion SpacePilot PRO (Tinkering with buttons and views)

I’ve been tinkering with the SpacePilot PRO.  I love customization.  The SpacePilot PRO offers a high level of customization.  I will discuss different facets of the device in future articles.  This time I am writing about the programmable buttons.

SpacePilot PROThe SpacePilot PRO has 21 programmable buttons.  Additionally, 10 of those buttons have dual mappings for a total of 31 mapped commands.  That is a lot!  On top of that, each of the buttons are mapped differently for each program or mode supported by the device.  Within SolidWorks itself, there are three different mappings: Drawing, Part and Assembly modes.  (There is no mapping just for sketches, but there should be.)

Many of the buttons are directly related to functionality of the device or specific commands that are defined by intuitive icons.  Ultimately, I only recommend changing the mapping for the five buttons.  These are the dual mapped buttons labelled 1/6, 2/7, 3/8, 4/9, and 5/10.  When holding the left hand over the navigation knob, these buttons fall under the pinky finger. Giving the dual mapped button a single quick press initiates the first command.  To choose the second command instead, press and hold the button down for a second.  These buttons are a little awkward at first (being under the pinky), but I got used to it pretty quickly.

The 5 dual mapped buttons to the right of the knob (accessed with the thumb or index finger) provide quick access to standard model views.  For example, one button jumps to the front or back views of the model.  Most of the standard model views are covered by this set of buttons.  However, one thing that is missing is the ability to save a named view and to return to it at any time.  Given the level of detail that has gone into the SpacePilot PRO, it surprizes me that this ability is missing.  I think this is one of the points I mentioned to 3Dconnexion back in February.

So, you know what I did?  I made up for this missing functionality by writing a pair of macros that do just that.  One saves the current model view as a named view.  The other returns to that named view.  I then programmed these two functions to button 1/6.  (I’ve already uploaded these to my resources site here: Quick View Save and Restore.  These macros can actually be used with any device with programmable functions, or even just as icons on a toolbar.) Let’s hope that 3Dconnexion covers this basic function in future iterations of their 3D mice.

Hint: for users of SolidWorks 2008 and 2009, I would recommend programming one of the buttons to the letter “S” for the shortcut toolbar.  This would practically eliminate the need to touch the keyboard except for typing notes and numbers.

Overall, I have found that the plentiful number of buttons is a big plus for the SpacePilot PRO.  These buttons extend the functionality of the device beyond just being a 3D mouse.

Getting Errors when using downloaded Macros?

Errors when running downloaded SolidWorks macros (Visual Basic 6) can be caused by many different issues, depending on the macro and which version of SolidWorks being used.  Here are some general points that may help.

Reference Libraries
Check reference libraries associated with the macro. These can be accessed by opening the macro through SolidWorks API editor (edit macro function), then going to pulldown Tools>Reference Libraries. If any of the listed libraries have the word MISSING in front of them, remove their check mark. You may need to replace it with a similarly named reference library that is included on your system. For example, if “SolidWorks 2008 Object Library” is missing and you are running SolidWorks 2007, then look for and activate the library named something like “SolidWorks 2007 Object Library”. SolidWorks may be able to do this automatically, but on many computer systems, you will need to manually make this edit, particularly if using a macro made on a version of SolidWorks newer than you are using.

Conversely, errors can be caused by having conflicting libraries loaded at the same time (i.e., having too many libraries).  No errors will appear in the reference library list.  If you are certain the correct library is loaded already, trying removing other SolidWorks related libraries one by one until the issue is resolved.

Also, the correct reference library may not be loaded at all. Research the line of code causing the error to make sure the correct reference library is loaded to support those instructions.

Additionally, if a macro was made on a newer version of SolidWorks than what you are currently using, its instructions may not be supported at all on the system running the older version of SolidWorks. In this case, you will need to find an equivalent API method for the older SolidWorks version, if one exists.

If the macro does not use Forms, a quick way to make sure you are using current reference libraries is to simply cut and paste the complete code from the existing macro file to a new one created fresh on your system. Often, this will fix any mismatched reference libraries, but it might still require research to make sure all the necessary reference libraries are loaded for that macro.

Sub-Modules
When executing the macro, make sure you specify the “Main” sub-module as the starting point. This is the section of code following the line “Sub Main ()”. Most macros are set up with Main as their starting sub-module. This is usually a fix if you are having issues associating your macro with an icon on a Toolbar, assigning a shortcut key, or trying to execute the macro from within another macro.

If the macro does not have a Main sub-module, then you may need to study the macro to discover which sub-module is meant as the starting point.

Copying code from online or plain text source
Sometimes when code appears in plain text, such as in a .txt file or from a forum online, it may not be formatted properly. Some of the lines may be too long for the plain text source, so they are line broken. This will disrupt the code, as SolidWorks API will misunderstand the instructions. When copy and pasting code from a plain text source, make sure to go over the code to insure all the lines are properly reconstructed by removing erroneous line breaks.

Sources for help
If issues are still occuring, contact the author(s), if available. Also, make sure to read over the material and examples provided in the SolidWorks API Help file included with SolidWorks. If those do not completely solve the issue, then search over various online forums dedicated to SolidWorks and SolidWorks API support. Many of these forums are listed under Forum Links.  If the search doesn’t resolve the issue, then post a question on those forums detailing the issue and requesting help from other SolidWorks users. You may also contact your VAR, as the issue you are having may actually be a bug or known issue in the SolidWorks API system itself.

Book Review: SolidWorks 2008 API

SolidWorks 2008 API Programming & Automation is recent self-published book by Luke Malpass, founder of AngelSix.  (You will not find his book on Amazon.)  Mr. Malpass wrote this book to fill an apparent gap in guide books about SolidWorks API.  The last book that I know of written specifically on this topic was Automating SolidWorks 2006 using Macros by Mike Spens, published way back in 2005.  Like that book, Mr. Malpass’ new book is spiral bound.

Mr. Malpass states in his introduction that he wrote his book to share his “ways of thinking and programming and hopefully to enlighten at least one other person’s day.”  Much of the book is written in this same friendly manner.  At times, the book is not written in a way that some would consider professional.  Yet, he gets his points across clearly.  The book is accessibly readable by experienced and novice programmers alike. 

The first chapter is correctly labelled “The Basics”.  The first section gets right into the task at hand. The lesson teaches how to make and use recorded macros.  The book next jumps right into writing macros from scratch.  It takes a step by step approach that reveals what code is necessary.  It explains each line in Mr. Malpass’ ever present friendly style. 

As one reads through the book, they will find code examples being built and explained piece by piece in both C# and VBA.  These macros are real world examples that the reader may find immediately useful.  Instructions are so clear that many will be able to apply the demonstrated code in their own macros.

One good example of this is found in the first chapter.  Right near the beginning of the book, Mr. Malpass provides instructions on how to make a macro that save each drawing sheet as an individual DXF File automatically.  This example is great because this question actually comes up a lot in the online message forums.

Many more important topics are extensively covered.  These include working with selected objects, implementation of Property Manager Pages, traversing through each type of document, Custom Property Manager, working with drawings, use of forms, and how to create and use Add-ins (something of special interest to many).  Additionally, all macro examples within the book are included in completed form on a CD. 

Of course, the book covers both C# and VBA code examples.  However, it also often talks extensively about VB.NET.  I found the instructions regarding VB.NET to be distracting, especially since few VB.NET examples appear in the book except for one section written specifically for it.  Granted, VB.NET and VBA are very similar.  However, in my opinion, differences are enough to warrant specific examples for each language.  It should be noted that some VB.NET examples are provided on the CD.  It seems to me that this book may have been better served if it focused on VB.NET and VBA instead of C# and VBA.  C# may have been better handled within its own book.  This would’ve allowed for more room in the book for more specific examples on even more topics, such as more information on how to read and utilize data from external files or methods specifically addressing the handling of BOM’s. 

One minor point of concern I found is within statement of ownership by the author.  It’s a boiler plate “all rights reserved” statement that limits reproduction or distribution without written permission of the publisher.   As this applies to the book itself, I stand by such statements.  However, in my view, it is not practical to place such limitations on code examples.  Doing so kind of defeats the purpose of the book.  That is not to say an author should not hold control over their works, but that if an author chooses to provide examples on how to do something, limitations should not be placed on the examples themselves.   (SolidWorks Corp makes a statement in their API Help that grants permission for the unlimited use of their examples.)

That aside, my opinion is that this book is great for anyone with programming exposure and who wishes to learn how to apply that experience directly to SolidWorks.  It is not meant for the person that has never attempted to program, unless that person is a brave soul willing to dive right in to the process.  I believe this book will be useful for people from novices to those of advanced programming skill.  It may also be a good reference guide to professionally trained expert programmers for SolidWorks specific programming possibilities and requirements.  I recommend this book.

Disclaimer:  This review is unsolicited by the book’s author.  It is based on use of product that I purchased at full price.  I receive no compensation for referrals.

If you are interested in SolidWorks 2008 API Programming & Automation, it may be purchased here: AngelSix.com.

Order of Business: Possibly Rename Resources Site

I am considering renaming Lorono’s SolidWorks Resources website.  I’ve not made up my mind if I want to or should.  So, let me ask others.  What do you think of the name?  Does it represent that website?  Should I associate it more closely with SolidWorks Legion (Legion SolidWorks Resources; SolidWorks Legion SolidWorks Resources) or modify and enhance its identity in some other way?  Do you have any thoughts about this?  In fact, what are your thoughts about Lorono’s SolidWorks Resource website in general?