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
- Download the example file set here and open both assemblies.
- Write a VBA macro in as few lines as possible that meets the conditions stated below.
- Submit the macro to firstname.lastname@example.org July 1, 12:00AM EST.
- 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
- The only required precondition for running the macro is that “contest2_start.SLDASM” is active.
- After the macro runs, the resulting assembly has the same center of mass as “contest2_complete.SLDASM”.
- 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.)
- The macro contains no hard coded physical property values: face areas, face normals, edge lengths, vertex coordinates, etc.
- The macro does not use IModelDocExtension::SelectByID2 to select entities for mating.
- The macro uses the Option Explicit statement.
- 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.
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!
Want to learn about future CADSharp.com contests and new content? Sign up for our newsletter.
1. Is the geometry subject to change (ie. changing diameter of holes or pins)? or all the parts will remain the same as downloaded?
2. Can we assume that the macro should not crash under any circumstance (validation)?
1. The macro only needs to work with the model as you download it. I won’t test your macro on any other variation of that model.
2. The sole purpose of the macro should be to achieve the result shown in the completed assembly (identical COG, though the cylinders must still spin), regardless of how the non-fixed components are oriented initially. (Base1 is always fixed in the same place.)