{"id":16782,"date":"2017-06-05T11:00:33","date_gmt":"2017-06-05T15:00:33","guid":{"rendered":"https:\/\/blogs.solidworks.com\/tech\/?p=16782"},"modified":"2017-06-05T10:07:36","modified_gmt":"2017-06-05T14:07:36","slug":"solidcraft-using-solidworks-api-fun-games","status":"publish","type":"post","link":"https:\/\/blogs.solidworks.com\/tech\/2017\/06\/solidcraft-using-solidworks-api-fun-games.html","title":{"rendered":"SOLIDCRAFT &#8211; Using SOLIDWORKS API for Fun and Games"},"content":{"rendered":"<p><img decoding=\"async\" class=\"aligncenter\" title=\"SOLIDWORKS-Minecraft-Blog-SolidSolutions\" src=\"https:\/\/www.solidsolutions.co.uk\/Uploaded\/Image\/Blog\/Rodion%20-%20SOLIDCRAFT\/logo-with-trees.jpg\" alt=\"SOLIDWORKS-Minecraft-Blog-SolidSolutions\" \/><\/p>\n<h2><strong>What is SOLIDWORKS API?<\/strong><\/h2>\n<p>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.<\/p>\n<p>We at <a href=\"https:\/\/www.solidsolutions.co.uk\/solidworks\/Data-Management\/Packages\/PDM-Professional.aspx\">Solid Solutions<\/a> offer <a href=\"https:\/\/www.solidsolutions.co.uk\/solidworks-Services\/Consultancy\/default.aspx\">bespoke coding on a consultancy basis<\/a>. Be it a one-page input form, a <a href=\"https:\/\/www.solidsolutions.co.uk\/solidworks\/Data-Management\/Packages\/PDM-Professional.aspx\">PDM Pro<\/a> custom task or a multiplatform app that talks to SOLIDWORKS \u2013 we have a team of automation specialists able to tackle a wide range of challenges.<\/p>\n<p>But what can be done with API outside of office hours, just for fun? Well, it\u2019s not very hard to implement some basic MINECRAFT functionality with a couple of macros. Let\u2019s have a look at the process and some results!<\/p>\n<h2><strong>Creating a Macro<\/strong><\/h2>\n<ol>\n<li>We start with a small 10x10x10mm cube model (could be any other size).<\/li>\n<li>Start recording a macro (Tools-&gt;Macro-&gt;Record).<\/li>\n<li>Perform the following steps by hand:\n<ul>\n<li>Select any face on the cube surface and start a new Sketch.<\/li>\n<li>Use the Sketch -&gt; Convert Entities command.<\/li>\n<li>Boss extrude 10mm Blind without merging the result. Actual extrusion depth depends on the size of your initial cube.<\/li>\n<li>Stop recording the macro, save it into a separate folder.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><img decoding=\"async\" class=\"aligncenter\" title=\"SOLIDWORKS-Minecraft-Blog-SolidSolutions\" src=\"https:\/\/www.solidsolutions.co.uk\/Uploaded\/Image\/Blog\/Rodion%20-%20SOLIDCRAFT\/SOLIDCRAFT-MACRO-BLOG-1.png\" alt=\"SOLIDWORKS-Minecraft-Blog-SolidSolutions\" \/><\/p>\n<p>You will need to edit the code behind your macro to remove the selection part. This is done through Tools -&gt; Macro -&gt; Edit. Your macro code will look similar to one below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" title=\"SOLIDWORKS-Minecraft-Blog-SolidSolutions\" src=\"https:\/\/www.solidsolutions.co.uk\/Uploaded\/Image\/Blog\/Rodion%20-%20SOLIDCRAFT\/SOLIDCRAFT-MACRO-BLOG-2.png\" alt=\"SOLIDWORKS-Minecraft-Blog-SolidSolutions\" width=\"750\" height=\"491\" \/><\/p>\n<p>This macro allows you to \u2018draw\u2019 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.<\/p>\n<h2><strong>But all of these cubes are grey, where are the Minecraft textures?!<\/strong><\/h2>\n<p>Okay, this is where things get tricky. You will need some <a href=\"https:\/\/www.solidsolutions.co.uk\/solidworks\/Tutorial-Videos\/Automate-SOLIDWORKS-with-the-API.aspx\">SOLIDWORKS API<\/a> 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:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" title=\"SOLIDWORKS-Minecraft-Blog-SolidSolutions\" src=\"https:\/\/www.solidsolutions.co.uk\/Uploaded\/Image\/Blog\/Rodion%20-%20SOLIDCRAFT\/SOLIDCRAFT-MACRO-BLOG-3.png\" alt=\"SOLIDWORKS-Minecraft-Blog-SolidSolutions\" width=\"690\" height=\"508\" \/><\/p>\n<p>I created two macros for \u2018bark\u2019 and \u2018leaves. Now we can \u2018draw\u2019 some vegetation:<\/p>\n<div style=\"width: 1140px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-16782-1\" width=\"1140\" height=\"641\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/blog-assets.solidworks.com\/uploads\/sites\/4\/SOLIDCRAFT-MACRO-BLOG.mp4?_=1\" \/><a href=\"https:\/\/blog-assets.solidworks.com\/uploads\/sites\/4\/SOLIDCRAFT-MACRO-BLOG.mp4\">https:\/\/blog-assets.solidworks.com\/uploads\/sites\/4\/SOLIDCRAFT-MACRO-BLOG.mp4<\/a><\/video><\/div>\n<p>With some time and effort we can grow trees even:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" title=\"SOLIDWORKS-Minecraft-Blog-SolidSolutions\" src=\"https:\/\/www.solidsolutions.co.uk\/Uploaded\/Image\/Blog\/Rodion%20-%20SOLIDCRAFT\/tree%20growing.gif\" alt=\"SOLIDWORKS-Minecraft-Blog-SolidSolutions\" width=\"640\" height=\"481\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" title=\"SOLIDWORKS-Minecraft-Blog-SolidSolutions\" src=\"https:\/\/www.solidsolutions.co.uk\/Uploaded\/Image\/Blog\/Rodion%20-%20SOLIDCRAFT\/tree%20spinning.gif\" alt=\"SOLIDWORKS-Minecraft-Blog-SolidSolutions\" width=\"480\" height=\"373\" \/><\/p>\n<h2><strong>In Conclusion<\/strong><\/h2>\n<p>Here we have barely scratched the surface of what SOLIDWORKS API is capable of&#8230; Minecraft within\u00a0<a href=\"https:\/\/www.solidsolutions.co.uk\/solidworks\/3D-CAD\/Packages\/default.aspx\">SOLIDWORKS<\/a>!<\/p>\n<p>Now show this to the young people you know, maybe they will become SOLIDCRAFT Engineers one day.<\/p>\n<p><strong>Rodion Radchenko<br \/>\n<\/strong><a href=\"https:\/\/www.solidsolutions.co.uk\/About-Us\/Why-SolidSolutions\/Worlds-Best-SOLIDWORKS-Support.aspx\">Elite<\/a> Applications Engineer<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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<\/p>\n... <a href=\"https:\/\/blogs.solidworks.com\/tech\/2017\/06\/solidcraft-using-solidworks-api-fun-games.html\">Continued<\/a>","protected":false},"author":138,"featured_media":16783,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1475,35,36],"tags":[1884],"class_list":["post-16782","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-solidworks-2017","category-tips-tricks","category-usability","tag-solidworks-api"],"acf":[],"_links":{"self":[{"href":"https:\/\/blogs.solidworks.com\/tech\/wp-json\/wp\/v2\/posts\/16782","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.solidworks.com\/tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.solidworks.com\/tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.solidworks.com\/tech\/wp-json\/wp\/v2\/users\/138"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.solidworks.com\/tech\/wp-json\/wp\/v2\/comments?post=16782"}],"version-history":[{"count":9,"href":"https:\/\/blogs.solidworks.com\/tech\/wp-json\/wp\/v2\/posts\/16782\/revisions"}],"predecessor-version":[{"id":17056,"href":"https:\/\/blogs.solidworks.com\/tech\/wp-json\/wp\/v2\/posts\/16782\/revisions\/17056"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.solidworks.com\/tech\/wp-json\/wp\/v2\/media\/16783"}],"wp:attachment":[{"href":"https:\/\/blogs.solidworks.com\/tech\/wp-json\/wp\/v2\/media?parent=16782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.solidworks.com\/tech\/wp-json\/wp\/v2\/categories?post=16782"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.solidworks.com\/tech\/wp-json\/wp\/v2\/tags?post=16782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}