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.

Setting up and using SolidWorks Revision Tables faster

I am sometimes surprized by the limited the adoption of the SolidWorks Revision Table.  This is a powerful tool for drawings within SolidWorks.  The Revision Table allows the user to create a drawing template with an easily updateable revision block already included.  The user doesn’t have to use a potentially unstable Excel inserted OLE.  They also do not need a drawn revision block that requires significant labor in order to update and maintain.

The SolidWorks Revision Table is easy to insert in SolidWorks 2008.  With a drawing open, just go to Insert pulldown>Tables>Revision Table.  Within the Revision Table Pane, pick the appropriate revision template.  Choose any desired options for the table. Choose OK.  The Revision Table will automatically appear in upper right corner.  Save the drawing template for future use.  (See Help for instructions to place the Revision Table at other locations on the drawing.  Also, more steps are required in 2007 and prior; but, they are intuitive to follow and provide more on-screen control over the table’s location.)

Custom Revision Tables can be created to suit the companies specific needs.  Right click on the table to use the RMB menu to access functions that provide methods to modify the table.  When modifications are complete, use the RMB menu Save As option to save the new table as a table template for future use.

To add a revision, simply right click on the Revision Table.  Choose Revisions>Add Revision.  A new revision row will appear with the next revision inserted.  Simply double click any field to add or modify its value.  LMB click outside of the table to set the edits.

Of course, there is a simpler way to add revisions to the Revision Table!  I’ve created a macro that provides a form which allows the quick addition of revisions to the Revision Table.  It’s called RevBlockControl.  It is much faster than directly creating and entering all the rows and values.  It has been recently updated, so if you already use this macro, please consider using the latest version.

RevBlockControl Form

Sample image of the macro form

To use the macro, place it in the macros folder under the SolidWorks folder.  If it doesn’t exist, create it.  Within SolidWorks, assign a custom key stroke to the macro and/or create a toolbar icon location for it.

It can be used for a variety of revision table set-ups, including standard recommended ASME types.  It is limited to 5 columns, though it is customizable without editing the code or a complex .ini file.  If editing the code is desired, everything is spelled out with descriptions for easy of use.  In fact, the code can be quickly edited to allow the macro to drive the drawing’s “Revision” custom property.  Additionally, there is a small .ini included in this current version.  It is simply a list of initials used by the Rev By field.  Edit it with NOTEPAD to add and delete names that will automatically appear within the Rev By field.

Even without the RevBlockControl macro, the easy of use of the SolidWorks Revision Table is well worth the few minutes of effort to set it up on a template.  With the RevBlockControl macro, adding revisions to a Revision Table is so fast that it is almost effortless when compared to other type of revision blocks.

How to use a Model’s Material directly on the Drawing

I should start out by saying that I personally advise against using the model’s Material value directly on a drawing (edit: for SolidWorks version 2008 and older; SW 2009 appears to have addressed some of the issues).  However, below is the instructions to do just this.

First, let me bring up three problems when it comes to materials and the SolidWorks Material Database naming convention.  One, the material names used in SolidWorks library are not correct.  In fact, in many cases they are not even the common names for those materials.  Two, for those of us who need accurate specification, the standards that define the materials are not mentioned of the library at all, making references to material incomplete.  Three, the names of the materials are not capitalized, so they are not formatted correctly to be used directly on a drawing in the first place.

A solution to these issues is to change your library to add this info and correct formatting or create a new library to do the same.   Another more common solution is to enter the information manually in a custom property within the model, then have that value pulled into the drawing via normal custom property linking, such as an annotation note with the following text: $PRPSHEET:”Material” or similar.  Make sure to identify which view you wish the data to be pulled from, within the Sheet Property window.

If you still wish to use the actual model’s material value (despite all of the above reasoning), there’s a couple extra steps (also involving the use of custom properties):

1.  In the model, create a custom property called something like Material at File>Properties>Custom tab.

2.   For the value of Material property, just click on the down arrow of the entry field and select Material.

3.  On the associated drawing, create similar custom property with the same name.  (Again, make sure to identify which view you wish the data to be pulled from, within the Sheet Property window.)

4.  For the value of the drawing’s Material custom property, type $PRP:”Material”

5.  Create an annotation note that links to the drawing’s Material custom property.  This will display the value of the model’s material directly on the drawing.

Correction on Rib/Draft on Curved Surface Article

I stand corrected on a previous article.  I originally made a misstatement regarding the capabilities of SolidWorks to create drafts on ribs based on curved surfaces with controlled root widths.  As far as an explanation for this oversight, I can only say what didn’t work for me last week worked this week, and that my VAR has some new inexperienced people on their phone support.  Here’s the basics that didn’t work before but work today.

SolidWorks does allow one to control the root width of a rib feature on a curved surface with the draft feature.  This means that draft will diminish from the ribs base, even if it is from a curved surface.  To apply a draft to such a rib, simply use the parting line option and pick a perpendicular plane or a parallel line/entity for the direction of draft.  For the parting line, choose each of the edges where the rib intersects its curved surface base.  If necessary, toggle the direction of draft.  That’s it. 

Of course, this method is still imperfect.  The question is, why doesn’t the draft feature just know that I want to pull it from the root?  It seems illogical to require a neutral plane at all since each rib has only two ends.  Why not just ask the user for the end to draft from?  I guess if someone wants to use draft to add angle to a rib long its left to right/up to down, then making this assumption wouldn’t work.  I doubt that would be much of an issue however, since that is not what a rib nor a draft is supposed to be.

The alternative method I posted last weekend should be referenced as a case of bad practice that works and should only be used if nothing else does.  Edit: however, it is a good demonstration of how to get a line along a curved surface into a sketch.

Control Root Size of Drafted Rib on Curved Surface

*This article makes some inaccurate statements regarding the capability of SolidWorks.  Please see the correction article for details.  Inaccurate statements have been crossed out.  The methodology described in this article should be referenced as an example of bad practice that should only be employed if traditional methods fail.  Edits to this article appear in this color.*
*Additional comment: this article does demonstration a good method for getting a line along a curved surface into a sketch. *

Good mold design means that one must take care to control the root width of a rib.  How does one do this if the rib is based on a curved (non-prismatic) surface? 

SolidWorks has many powerful features for making injection molding parts.  It has both rib and draft features.  Unfortunately, these two features together have one important limitation.  When applying a draft to a rib based on a curved surface, SolidWorks does not allow the user to hold the root width of that rib.  SolidWorks requires a prismatic surface to use as a neutral plane from which to start a draft.  This means in this case, the draft can only be started from the top of the rib, not its root.  If one wishes to hold the rib root constant along a curved surface, one cannot use the rib or the draft features.

SolidWorks does have an arsenal of other features and tools to allow one to build an alternative strategy to workaround this limitation.  

Basic shelled part with curved surface

This first figure shows a fairly simply shelled injection molded part with a complex curved surface.  To make drafted ribs using this method, first create an axis that can be used as an directional guide. You can choose to use features on the part itself for this purpose, instead. I prefer to create a special sketch at the location where I plan to add a boss.  Regardless of the method used, the directional guide should be parallel to the direction planned for the ribs.

 Setup Sketch for Directional Guide

The second step is to start a new sketch above the curved surface.  In that sketch, draw the outline of the rib.

Sketch outline of ribs

If there is a series of ribs needed in one direction, try creating a sketch pattern the other instances.  Make sure to turn sketch entities of the other instances into construction lines.

Project outline using Split Line

Use Split Line to project that outline onto the curved surface.  Split Line will only project one contour per sketch.  This is why it is important to turn all other instances of the rib into construction lines.  Having those other instances pre-drawn will save time when making the other ribs (covered in Part 2 of this article). 

Next, start a 3DSketch.  Use Convert Entitles to bring the Split Line curves into the sketch.  Drag the end points of the curves so they are coincident (on the surface) of the outside surface of the outer walls, or some othe appropriate location.  Then, close the contour by drawing lines to connect the curves at each end. 

Convert split line edges in 3DSketch

Extrude this sketch.  Use the previously drawn axis from the first sketch as the direction.  Use the top surface of the cavity (or whatever is appropriate) as up-to-surface entity.  Turn on Draft and specify the desired angle.  Here’s the funny part.  Be sure to extrude a small amount (smaller than the wall thickness of the part) in the other direction without draft.   If this isn’t done, a zero-point error will pop up preventing the completion of this step.

Use previous setup to set extrude of 3DSketch

The end result will be a drafted rib with a controlled root width.

Final result

Part 2 of this article will detail how to create repeated and crossing ribs using this same technique.  Again, please note this is not a best practice method.  See the correction article for details.

Workaround to edit Macros that are locked on network drive

Question:  I have macros on a network drive and need to edit them.  Unfortunately, someone has them locked (open).  How do I unlock them without going to that computer to manually unload the macros?

Answer: There is a live workaround.  While you cannot edit the files while locked, you can change their folder name! This allows for a sneaky little trick that doesn’t require going to the offending computer.

Simply rename the folder on the network drive where the macros are located. Then copy that folder (files and all) to the same drive. Rename the new folder to be the same name as before the original folder was renamed.

The macros in the old folder with the changed name will still be locked out, but the macros in the new folder with the original name will be free to edit!

In a day or so, the files in the old folder will be unlocked again.  Simply delete the old folder at that time.

Addendum: It should be noted that this method will not always work.  However, it is worth a try before taking any other action.