CADSharp Blog

Upcoming API Training Class In Los Angeles

Blog 12.1.2016 No Comments

CADSharp is offering a four-day live training class on advanced API applications (addins and stand-alones using .NET) in Los Angeles, CA, on Jan 31 – Feb 3, 2017. Here’s what others have said about our classes:

You’re the best programming teacher I’ve ever had. I took two programming classes in college and neither of the teachers broke the subject down and explained every single line of code like you do.

Alex B.,

Why You Should Attend

<> Highly rated. Last 25 survey respondents averaged 9.4 / 10 for the question, “Were you satisfied with how much you learned?”

<> Beginner-friendly. No previous experience with .NET programming experience is required. Experience writing SolidWorks macros with VBA is highly recommended.

<> Personal. Small class size allows for excellent teacher-student interaction.

<> Professional. Content is designed and taught by Keith Rice, a leading SolidWorks API expert and software developer.

<> Flexible. Lessons are tailored on-the-fly to student needs and interests.

<> Learning doesn’t end. Complimentary one-year premium membership included.

Course Description and Price

Download syllabus for Advanced Program Development

Ready to go to the next level? If you already have experience writing VBA macros for SolidWorks (prerequisites are stated in syllabus), then this course will cover all aspects of professional add-in and stand-alone development: program setup and architecture, object-oriented programming techniques, using Visual Studio, source code control and collaboration using GitHub, documentation, deployment, and administration. The contents of this course is borne out of years of real-world, customer-driven experience and has never been published in any form.

Price: 1199 USD per person

Date and Time

Jan 31 – Feb 3, 2017. Training is from 8:00 AM to 4:30 PM with an hour break for lunch.


Comfort Inn & Suites, 4922 W Century Blvd, Inglewood, CA 90304

Conveniently located just two miles from LAX airport. Includes complimentary airport shuttle and continental breakfast.

Registration and Payment

Registration is usually limited to five people. Email me to register.

I have one computer available for rent for 200 USD. First come, first serve. Otherwise, you will be expected to bring your own computer.

Invoices may be paid by check, wire transfer, or credit card. If by credit card, an additional 35 USD fee is included. Invoices will be sent out a week before the class starts.

I hope you can join me in Los Angeles for a great time of learning! Let me know if you have ANY questions.


Want to keep up with future content and training events? Sign up for our newsletter.

Leave Comment

Techniques for Obtaining Bounding Boxes

Blog 11.29.2016 No Comments

Bounding boxes are used constantly in engineering for a variety of reasons. Amongst SolidWorks users, I frequently see them used to optimize plant floor layouts, packaging sizes, and stock lengths. In this blog post, I want to cover the pros and cons of the various techniques available in the SolidWorks API for determining them.

GetBox / GetBodyBox / GetPartBox

The SolidWorks API comes with several API calls that return the coordinates of two of the bounding box corners. From these 6 double values, all of the bounding box coordinates can be obtained. These methods are:

  • IBody2::GetBodyBox
  • IComponent2::GetBox
  • IFace2::GetBox
  • IAssemblyDoc::GetBox
  • IPartDoc::GetPartBox

The obvious advantage to these methods are their ease of use. They have two notable downsides, however. First, these methods do not always return the true minimum boundary box, sometimes even being 5-10% off in some directions (in my personal experience). Second, they only return the bounding box in the primary coordinate system. If the body you wish to analyze is rotated, this could render these methods useless to you.

Our Macro Library contains an example of IBody2::GetBodyBox, available to any member.


According to the API Help, this method “gets the triangles that make up the shaded picture tessellation for [a] face”. Practically, this means that if we want a more accurate bounding box than the methods described earlier, we can traverse every face in a body and discover the largest and smallest X, Y, and Z values in that body. For each face, we can also transform the tessellation triangle coordinates into another coordinate system, if desired. That way we are not limited to finding the bounding box in just the primary coordinate system.

Even this approach, however, might be unsuitable for machining applications. The API Help remarks for this method state, “These triangles are intended for graphics display purposes and do not represent a tessellation that can be used, for example, by a machining application. If you need the kind of accuracy associated with a machining product, traverse the body faces and extract the topology and geometry data to create your own faceting.”

Our Macro Library contains an example of using IFace2::GetTessTriangles to obtain the bounding box of a body, available to any member.


This method, available as of SolidWorks 2013, creates a 3D sketch containing lines representing what SolidWorks considers to be the “ideal” bounding box for a cut list item. The sketch can be accessed via the API and the actual bounding box points retrieved (in the standard coordinate system). The bounding box created by this method is the same one used to calculate the built-in LENGTH custom property for a Structural Member feature in a weldment part.

Personally, I would hesitate to use this method for bodies not created from Structural Members, for two reasons. The first and less significant reason is that it requires generating a cut list for your model, which might be undesirable. Second, and more significantly: the “ideal” bounding box it returns might not actually be the one you need. For example, consider the following body created by a regular Extrude feature and then rotated at an odd angle with the Move/Copy Body feature:

This bounding box correctly identifies the diameter of the body and therefore returns a more accurate width than IBody2::GetBodyBox would, nevertheless the direction of the body is not recognized and therefore the height and length are still incorrect.

If you want to experiment with method on your own to see if it will meet your requirements, check out the example in our Macro Library, available to any member.


Technically, this method does not return bounding box coordinates, but it can be used to return the length of a bounding box in a specified direction. This is really useful for obtaining the length of a body that was not created with a Structural Member feature but might also be a strange angle. (Again, keep in mind that if it was created with a Structural Member feature then we could simply use the built-in length custom property, and if the desired length were aligned with one of the primary axes then we could obtain the length with one of the other bounding box techniques.)

Unfortunately, getting to that length value using this API call is not easy. First, this method requires a direction. Obtaining that direction programmatically could be a challenge. Second, once the extreme points in that direction and its reverse and obtained, you still will not have the extreme length because the line connecting the extreme points is not necessarily parallel to the direction you want. For example, consider the following body.

Using the normal of the large bottom face as the positive direction (represented by the red line) and its reverse for the negative direction will result in the two points connected by the blue line. Since this blue line is not parallel to the red line, the blue line does not represent the “extreme length” of the model for the chosen direction. Rather, the red line actually represents the desired “extreme length”.

We can get the length of the red line using some vector algebra. Since we know the red and blue lines form the hypotenuse and adjacent of a right triangle (the yellow line is the opposite), we know that if we get the angle between the red and blue line, we can calculate the length of the red line by multiplying the length of the blue by the cosine of that angle. That angle is equal to the arccosine of the dot product of the unit vectors of the red and blue lines.

Available to Power User members only is a very powerful macro in our Macro Library that uses IBody2::GetExtremePoint to calculate the “extreme length” of a input. To specify the direction, you can pass in a plane, planar face, cylindrical face, straight edge, or circular edge.

In conclusion, the SolidWorks API has many options for obtaining bounding boxes, depending on your needs. If you have another technique you have used in the past, please share it in the comments below.


Want to learn about new macros, videos, and upcoming training events? Sign up for our newsletter.

Leave Comment

What’s New In The SolidWorks 2017 API

Blog 10.1.2016 No Comments

It’s that time of year again, folks. Let’s look over some of the most notable enhancements to the SolidWorks API, as well as some tips for using the API Help most effectively.

  • Create and access selection sets. (ISelectionSet)
  • Traverse the Manager Pane and activate the FeatureManager design tree, PropertyManager, ConfigurationManager, DimXpertManager, DisplayManager, or custom tab. (IModelViewManager::ActiveFeatureManagerTabIndex)
  • Fire a pre-notification and notification when activating a tab in the Manager Pane. (See swPartCommandManagerTabActivatedPreNotify and swPartActiveDisplayStateChangePostNotify in swPartNotify_e, swAssemblyNotify_e, swwDrawingNotify_e)
  • Get whether an axis is a temporary axis and get its reference face. (IRefAxis::IsTempAxis, IRefAxis::GetTempAxisReferenceFace)
  • Get or set the state of a check box on a PropertyManager page. (IPropertyManagerPageCheckBox::State)
  • Offset selected edges to create a 3D sketch on a face or surface. (IModelDocExtension::SketchOffsetOnSurface)
  • Make a selected component independent. (IAssemblyDoc::MakeIndependent)
  • Control the isolation state of components. (IAssemblyDoc::Isolate, ExitIsolate, SetIsolateVisibility, SaveIsolate)
  • Get the names of the exploded views for a specific configuration, get the number of exploded views in a specific configuration, and get the name of the configuration for a specific exploded view in an assembly.
  • Get the name of the exploded view in a specified configuration. (IAssemblyDoc::GetExplodedViewNames2)
  • Get the name of the configuration for the specified exploded view. (IAssemblyDoc::GetExplodedViewConfigurationName)
  • Get the collapsed or exploded transform of a component when the assembly is exploded. (IComponent2::GetSpecificTransform)
  • Delete either the selected components of a subassembly or the subassembly of the selected component. (IAssemblyDoc::DeleteSelections)
  • Get or set whether to disable an equation and get the number of disabled equations in a model. (IEquationMgr::Disabled, GetDisabledEquationCount)
  • Specify a sketch plane, surface/face/plane, vertex, or offset as a start condition when creating an extruded surface. (IFeatureManager::FeatureExtruRefSurface3)
  • Specify multiple drawing sheets whose setups to modify. (IDrawingDoc::SetSheetsSelected)
  • Create SpeedPak configurations for subassemblies in an assembly. (IAssemblyDoc::SetSpeedPakConfigurations)
  • Rebuild all features or rebuild only those features that need to be rebuilt in all configurations without activating each configuration in a model. (IModelDocExtension::ForceRebuildAll)

You can see all new API calls and interfaces in the Release Notes article in the API Help. You can find it in the local API Help by searching for “Release Notes” in the category tab. Note that the local API Help Release Notes will only be as up-to-date as the service pack you have downloaded.

Tips and tricks for using the SolidWorks API most effectively:

  • Use the local SolidWorks API Help. Besides being easier to navigate than the online help and not requiring SolidWorks to be open, it is also updated each service pack, whereas the online help is only updated for SP0, SP1, and SP5.
  • If you reference the local SolidWorks API Help as often as I do, it’s more convenient to create a start menu, task bar, or desktop shortcut directly to the latest SolidWorks API Help rather than accessing it only through the SolidWorks Help menu. What I do, therefore, is create a shortcut for <SolidWorks installation folder>\api\apihelp.chm and drag this shortcut onto my start menu icon, task bar, or desktop. I’d recommend that you rename the shortcut something like “SolidWorks 2017 API Help” so you know what version it refers to.
  • If you discover an area where the API is lacking, don’t be afraid to submit it to the SolidWorks API support team. On every local API help page is a “Send comments” link at the top and on every online API help page is a “Feedback on this topic” link.


Keep up with future content, training events, and special offers via our newsletter:

Leave Comment