API Programming Contest #2 Winners!

Blog 7.6.2015 No Comments

This year’s SolidWorks API programming contest, sponsored by CADSharp, brought in five fascinating submissions. This may seem like a low number, but I quite pleased considering the complexity of the contest. If you aren’t familiar with the contest rules, visit here.

My intention with the contest is that entrants would use geometry/topology traversal techniques to find the appropriate entities for mating. I did not, however, specify sufficient contest parameters to ensure this outcome, as I quickly discovered. Rather than penalizing the individuals who used alternative approaches that technically were within the boundaries of the contest, I have decided to awards prizes to all entrants.

Download submissions (.swp files)

Each .swp is named after the initials of the entrant. Let’s discuss each one, from shortest to longest:

1. rj.swp A very clever solution that utilizes the ability to put multiple statements on the same line as long as each statement can return a value. Even if you split up the conditional statements onto different lines, this macro still comes out to less than 30 lines. Rajat obtained the mating entities by hard-coding the feature names and considering the face order in the array returned by IFeature::GetFaces.

2. eq.swp Edgar’s 46 line solution locates and selects the exact edges necessary for mating by considering the order in which the edges were returned in certain arrays.

3. rb.swp Raghvendra’s macro, which comes out to 53 lines (discounting using a colon to place statements on the same line), traverses the feature tree while examining several criteria until the right faces for mating are found.

4. ik.swp At a mere 64 lines, Ivana’s macro represents a very efficient way to solve the problem without hard-coding feature names or the order in which desired entities appear in entity arrays.

5. cs.swp At 110 lines, Corey offers a straightforward use of geometry and topology traversal to solve the problem. This is similar to how I solved the problem, which you can see in kr.swp. Both of our solutions are largely unoptimized for minimal length but also have the advantage of being easier to read and understand.

Thanks again to everyone who took the time to enter our contest!

Did any of the techniques utilized stand out to you as particularly clever? Hopefully you can pick up some new programming tricks while looking over these submissions, just as I have.

Until next time,

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

Leave Comment

API Programming Contest #2: Win $100!

Blog 6.11.2015 2 Comments

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.

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.

Leave Comment

What’s New In The SolidWorks 2015 API

Blog 10.20.2014 No Comments

SolidWorks 2015

The SolidWorks 2015 API contains quite a few enhancements that I am excited to share with you. Here are some of the most significant:

  • Access scenes.
  • Insert a table-driven pattern feature.
  • Get or set the components and transforms for interferences.
  • Specify more document printing options.
  • Create and access local curve- and sketch-driven patterns.
  • Get type of body folder cut list.
  • Specify more options when mirroring components in an assembly.
  • Add a width mate to an assembly.
  • Specify whether to print a specified layer when printing a drawing document.
  • Get a feature’s folder.
  • Move a feature to another location in the FeatureManager design tree of a part or assembly.
  • Get all of the bodies that result from splitting a part.
  • Modify a split-body feature by changing its split bodies.
  • Specify more options when editing a mate in an assembly.
  • Support for intersect features.
  • Support for extracting Scanto3D information.
  • Specify whether to keep or delete bodies in a multibody part.
  • Divide a sketch segment into equally spaced sketch segments or points.
  • Get the display dimension object for a specified pattern property or a sketch relation.
  • Get the sketch segments that define the path of a structural member body.
  • Specify more properties when creating a weldment gusset.
  • Specify more properties when creating a structural member end cap.
  • Specify more properties when creating cosmetic threads.
  • Modify variable-pitch helix features.

Want to see the API interfaces and calls related to each of these topics? You need only open up the local API Help, go to the Index tab, and search for the “Release Notes” category. This will show all enhancements in SolidWorks 2015 SP0 in great detail.

As always, if you discover an area where the API is lacking, don’t be afraid to submit it to the SolidWorks API support team.


Want to keep up with future CADSharp.com content, webinars, and special offers? Sign up for our newsletter.

Leave Comment