Trimech-Main-Site-Group-Navigation Solid-Solutions-Group-Navigation Javelin-Group-Navigation Trimech-Enterprise-Solutions-Group-Navigation Trimech-Advanced-Manufacturing-Group-Navigation Trimech-Staffing-Solutions-Group-Navigation Solid-Print-Group-Navigation 3DPRINTUK-Group-Navigation 3DVERKSTAN-Group-Navigation Macdac-Site-Group-Navigation GRM-Consulting-Group-Navigation Solid-People-Group-Navigation
The TriMech Group offers a comprehensive portfolio of engineering and design software, hardware, professional services, and support, to clients accross the globe. Use the links above to visit the group's websites and learn more.
x
Search

SOLIDCRAFT. Using SOLIDWORKS API for fun and games.

Friday May 5, 2017 at 4:41pm None
SOLIDCRAFT. Using SOLIDWORKS API for fun and games. Read Applications Engineer, Rodion Radchenkos blog here.

SOLIDCRAFT. Using SOLIDWORKS API for fun and games.

 

 

What?

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!

 

How?

 

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:

a.        Select any face on the cube surface and start a new Sketch.

b.        Use the Sketch->Convert Entities command.

c.        Boss extrude 10mm Blind without merging the result. Actual extrusion depth depends on the size of your initial cube.

d.        Stop recording the macro, save it into a separate folder.

 

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?!

Okay, 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:

 

 

 

To conclude 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.

 

Rodion Radchenko

 Solid Solutions | Trimech Group

MENU
Top