SOLIDCRAFT. Using SOLIDWORKS API for fun and games.
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!
We start with a small 10x10x10mm cube model (could be
any other size).
Start recording a macro (Tools->Macro->Record).
Perform the following steps by hand:
Select any face on the cube surface and start a new Sketch.
Use the Sketch->Convert
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
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:
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?!
this is where things get tricky. You will need some SW API and VBA programming
knowledge from here onward.
I created some textured appearances and saved them as .p2m files in a subfolder next to my macro file.
Then we add some bits of intelligence to the already existing macro:
I created two macros for ‘bark’ and ‘leaves. Now we can
‘draw’ some vegetation:
With some time and effort we can grow trees even:
all of this:
Here we have barely scratched the surface of what SOLIDWORKS
API is capable of.
Minecraft in your SOLIDWORKS!
Now show this to young people you know, maybe they will become SOLIDCRAFT Engineers one day.