SOLIDCRAFT – Using SOLIDWORKS API for Fun and Games

SOLIDWORKS-Minecraft-Blog-SolidSolutions

What is SOLIDWORKS API?

SOLIDWORKS API is a gateway to automating your design process and data management. Using .NET compatible languages (VB, C#, C++) one can write small macros or build full-blown add-ins for modelling, routine edits and feeding data from one software package to another.

We at Solid Solutions offer bespoke coding on a consultancy basis. Be it a one-page input form, a PDM Pro custom task or a multiplatform app that talks to SOLIDWORKS – we have a team of automation specialists able to tackle a wide range of challenges.

But what can be done with API outside of office hours, just for fun? Well, it’s not very hard to implement some basic MINECRAFT functionality with a couple of macros. Let’s have a look at the process and some results!

Creating a Macro

  1. We start with a small 10x10x10mm cube model (could be any other size).
  2. Start recording a macro (Tools->Macro->Record).
  3. Perform the following steps by hand:
    • Select any face on the cube surface and start a new Sketch.
    • Use the Sketch -> Convert Entities command.
    • Boss extrude 10mm Blind without merging the result. Actual extrusion depth depends on the size of your initial cube.
    • Stop recording the macro, save it into a separate folder.

SOLIDWORKS-Minecraft-Blog-SolidSolutions

You will need to edit the code behind your macro to remove the selection part. This is done through Tools -> Macro -> Edit. Your macro code will look similar to one below:

SOLIDWORKS-Minecraft-Blog-SolidSolutions

This macro allows you to ‘draw’ cubes on top/below/next to other cubes. If bound to a keyboard shortcut or a spare mouse button this can be done very quickly.

But all of these cubes are grey, where are the Minecraft textures?!

Okay, this is where things get tricky. You will need some SOLIDWORKS API and VBA programming knowledge from here onward. I created some textured appearances and saved them as .p2m files in a sub folder next to my macro file. Then we add some bits of intelligence to the already existing macro:

SOLIDWORKS-Minecraft-Blog-SolidSolutions

I created two macros for ‘bark’ and ‘leaves. Now we can ‘draw’ some vegetation:

With some time and effort we can grow trees even:

SOLIDWORKS-Minecraft-Blog-SolidSolutions

 

SOLIDWORKS-Minecraft-Blog-SolidSolutions

In Conclusion

Here we have barely scratched the surface of what SOLIDWORKS API is capable of… Minecraft within SOLIDWORKS!

Now show this to the young people you know, maybe they will become SOLIDCRAFT Engineers one day.

Rodion Radchenko
Elite Applications Engineer

Solid Solutions Technical Team
Solid Solutions Management Ltd was founded in 1998, originally as a SOLIDWORKS training and support provider. Now a Group with over 20 offices across the UK and Ireland, Solid Solutions is not only the leading SOLIDWORKS 3D CAD reseller in both regions, it also offers expert professional design solutions and consultancy services to more than 15,000+ customers. With over 200 employees and the largest SOLIDWORKS technical team in the world, Solid Solutions is focused on growth and on its customers’ development and success.
Solid Solutions Technical Team
Solid Solutions Technical Team
Solid Solutions Technical Team

Latest posts by Solid Solutions Technical Team (see all)