I am pleased to announce the second CADSharp.com SolidWorks API programming contest! (See results of first contest here.) In this edition, we’re going to test your skills involving assemblies. Here’s how to win one of three Amazon.com gift cards or a 3-month premium membership to CADSharp.com.

How To Enter and Win
  1. Download the example file set here and open both assemblies.
  2. Write a VBA macro in as few lines as possible that meets the conditions stated below.
  3. Submit the macro to contest@cadsharp.combefore July 1, 12:00AM EST.
  4. The winners will be announced on our blog in July, along with everyone else who submitted a working macro, ranked from fewest lines to most lines.
Conditions for Success
  1. The only required precondition for running the macro is that “contest2_start.SLDASM” is active.
  2. After the macro runs, the resulting assembly has the same center of mass as “contest2_complete.SLDASM”.
  3. After the macro runs, the resulting assembly has the same degrees of freedom as “contest2_complete.SLDASM”. (The green cylinders can spin in place and no other components can move in any way.)
  4. The macro contains no hard coded physical property values: face areas, face normals, edge lengths, vertex coordinates, etc.
  5. The macro does not use IModelDocExtension::SelectByID2 to select entities for mating.
  6. The macro uses the Option Explicit statement.
Additional Comments
  • This problem is not intended to reflect any real life problem. It is simply a puzzle. As long as you achieve the result described above, you can use any tricks or shortcuts you can think of, regardless of whether they entail good programming practices.
  • The models were created in SolidWorks 2012 but any version of the SolidWorks API may be used.
  • Comments, blank lines, and lines resulting from a line continuation character (underscore) will not be counted in the final line count.
  • Multiple variable declarations on one line (and similar syntax tricks) will be counted as separate lines.
  • Any person may submit multiple solutions and I will only consider the submission with the fewest lines of code.
Prizes

Three winners will be chosen based on the number of lines of code in their macro.

First prize: $100 gift card at Amazon.com.
Second prize: $50 gift card at Amazon.com.
Third prize: $50 gift card at Amazon.com.

Note: The Amazon gift cards can only be awarded to entrants who may purchase Amazon.com or one of its affiliates in Australia, Canada, United Kingdom, Germany, Italy, France, Spain, Netherlands, China, Brazil, India, Mexico, and Japan. Otherwise, a 2-month Power User membership (valued at $199) will be awarded instead. Optionally, a winner that is entitled to a gift card may choose to receive the 2-month CADSharp.com Power User membership instead.

The winners will be announced in July. May the best programmer win!
Keith

Want to learn about future CADSharp.com contests and new content? Sign up for our newsletter.