{"id":8197,"date":"2020-12-23T13:16:14","date_gmt":"2020-12-23T12:16:14","guid":{"rendered":"https:\/\/cadbooster.com\/?p=8197"},"modified":"2025-01-12T16:15:35","modified_gmt":"2025-01-12T15:15:35","slug":"macros-for-solidworks-the-absolute-basics","status":"publish","type":"post","link":"https:\/\/staging.cadbooster.com\/nl\/macros-for-solidworks-the-absolute-basics\/","title":{"rendered":"Macros for SOLIDWORKS: the absolute basics"},"content":{"rendered":"<p>This post is about how to create, edit and debug SOLIDWORKS macros when you are completely new to building software.<\/p>\n<p>We&#8217;ll record a simple macro, explain the code and clean it up. Then we explain how you can debug your own macros.<\/p>\n<p>You don\u2019t need to be a software engineer by profession to be able to create macros, but a basic understanding of programming will help. I myself am a mechanical engineer by trade. I only started coding professionally when I started CAD Booster in 2017.<\/p>\n<h3>In this post, you&#8217;ll find<\/h3>\n<ol>\n<li><a href=\"#what-is-a-macro\">What is a macro?<\/a><\/li>\n<li><a href=\"#what-is-an-addin\">What is an add-in?<\/a><\/li>\n<li><a href=\"#how-to-record-a-solidworks-macro\">How to record a SOLIDWORKS macro<\/a><\/li>\n<li><a href=\"#vba-editor-immediate-window\">VBA editor: what is the immediate window?<\/a><\/li>\n<li><a href=\"#explaning-the-recorded-code\">Explaining the recorded code<\/a><\/li>\n<li><a href=\"#improving-the-recorded-code\">Improving the recorded code<\/a><\/li>\n<li><a href=\"#checking-the-model-type\">Checking the model type to prevent errors<\/a><\/li>\n<li><a href=\"#how-to-debug-vba-solidworks-macros\">How to debug VBA SOLIDWORKS macros<\/a><\/li>\n<li><a href=\"#how-to-pick-a-language\">How to pick a language<\/a><\/li>\n<li><a href=\"#solidworks-macros-sources-and-courses\">Sources and courses<\/a><\/li>\n<\/ol>\n<h3 id=\"what-is-a-macro\" class=\"anchor\">1. What is a macro?<\/h3>\n<p>SOLIDWORKS has two flavors for automation: macros and add-ins.\u00a0Macros are the most accessible, so we&#8217;ll start with those.<\/p>\n<p>We&#8217;ll be using VBA or Visual Basic for Applications. VBA is an old Microsft programming language for creating macros for applications like Excel.<\/p>\n<p>A VBA macro is a single .SWP file that can sit anywhere on your computer. You can run the macro by browsing for it or by adding a shortcut button to your command manager in SOLIDWORKS..<\/p>\n<p>You can even record and play back macros, although not all actions can be recorded.<\/p>\n<h4>The advantages of macros<\/h4>\n<ol>\n<li>Relatively easy to get started with.<\/li>\n<li>SOLIDWORKS contains an editor to create and edit macros.<\/li>\n<li>Can be created in VBA (Visual Basic for Applications), VB (Visual Basic, formerly VB.net) and C#.<\/li>\n<li>You can quickly create a new macro. By now, I can build a simple macro in two minutes.<\/li>\n<li>If you are familiar with macros in Excel, you can reuse much of that knowledge.<\/li>\n<li>You can run them in a batch tool like <a href=\"https:\/\/centralinnovation.com\/solidworks\/extensions\/task-v2\/\">#Task<\/a>, although I&#8217;m not a big fan of that product.<\/li>\n<\/ol>\n<h4>The disadvantages of macros<\/h4>\n<ol>\n<li>The forms look ugly and gray unless you put in some real work.<\/li>\n<li>You cannot create task panes (those tabs on the right).<\/li>\n<li>You cannot do proper version control because the SWP file is not a text file. Version control software like Git can therefore not see what you have changed, only that the file has changed.<\/li>\n<li>It&#8217;s hard to roll out updates because:\n<ol>\n<li>Files can become locked when you access them with multiple people. I&#8217;ve heard people say they had to wait till everyone went home to update the macro file.<\/li>\n<li>When everyone has their own file, you are never sure everyone is using the same version.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<h3 id=\"what-is-an-addin\" class=\"anchor\">2. What is an add-in?<\/h3>\n<p>If you want to make a professional product that integrates with SOLIDWORKS, you need to build an add-in.<\/p>\n<p>With add-ins, you can create Property Manager Pages (PMPs, those menus on the left, that let you edit Extrude properties, for example) and task panes (the menu tabs on the right).<\/p>\n<p>Add-ins are usually installed on your computer with a Windows installer. After that, your new add-in appears in the list of available add-ins:<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-6808\" src=\"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/04\/059-01-enable-solidworks-routing-add-in.png\" alt=\"enable solidworks routing add-in\" width=\"646\" height=\"535\" srcset=\"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/04\/059-01-enable-solidworks-routing-add-in.png 646w, https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/04\/059-01-enable-solidworks-routing-add-in-300x248.png 300w\" sizes=\"(max-width: 646px) 100vw, 646px\" \/><\/p>\n<p>Add-ins can be built by SOLIDWORKS (like SOLIDWORKS Routing) or by third parties like CAD Booster. We develop and sell the products <a href=\"https:\/\/staging.cadbooster.com\/drew\/\">Drew<\/a> (for drawing automation) and <a href=\"https:\/\/staging.cadbooster.com\/solidworks-add-in\/lightning-fastener-filter\/\">Lightning<\/a> (the fast fastener filter) and we also build custom add-ins for our customers.<\/p>\n<h4>The advantages of add-ins<\/h4>\n<ol>\n<li>Completely integrated within SOLIDWORKS.<\/li>\n<li>You can create them in any programming language that supports COM. Frequently used languages are C#, C++ and Python.<\/li>\n<li>Allows you to create task panes and property manager pages.<\/li>\n<li>You can create your own user interface (with WPF, for example) in the task pane. There&#8217;s no need to use the ugly gray user interfaces from 20 years ago from Windows Forms.<\/li>\n<li>You can do proper version control (with Git, for example) because the source code is stored in multiple text files.<\/li>\n<li>Users can easily install add-ins and their updates with an installer.<\/li>\n<\/ol>\n<h4>The disadvantages of add-ins<\/h4>\n<ol>\n<li>There is a steep learning curve if you have never built software before, or if you have never built software for SOLIDWORKS before.<\/li>\n<li>You need external tools like Visual Studio to develop the software.<\/li>\n<li>You need to compile your code and create an installer.<\/li>\n<\/ol>\n<p>Overall, we love add-ins and we rarely build macros for our customers.<\/p>\n<h3 id=\"how-to-record-a-solidworks-macro\" class=\"anchor\">3. How to record a SOLIDWORKS macro<\/h3>\n<p>The first step in learning how to create macros is by recording your own actions using the macro recorder.<\/p>\n<p>Prepare your model file, hit record and only perform the actions that you want to record. Hit stop to save the file.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-8205\" src=\"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-02-record-solidworks-macros.png\" alt=\"record solidworks macros\" width=\"256\" height=\"155\" \/><\/p>\n<p>This great video by GoEngineer shows you how to record your actions and let SOLIDWORKS convert them into a macro. You can then create a button in your toolbar to run the macro whenever you need it again.<\/p>\n<div data-nosnippet=\"\"><div class=\"lyte-wrapper\" title=\"SOLIDWORKS - Basic Macro\" style=\"width:853px;max-width:100%;margin:5px;\"><div class=\"lyMe hidef\" id=\"WYL_hMkBQqkDUZI\" itemprop=\"video\" itemscope itemtype=\"https:\/\/schema.org\/VideoObject\"><div><meta itemprop=\"thumbnailUrl\" content=\"https:\/\/i.ytimg.com\/vi\/hMkBQqkDUZI\/maxresdefault.jpg\" \/><meta itemprop=\"embedURL\" content=\"https:\/\/www.youtube.com\/embed\/hMkBQqkDUZI\" \/><meta itemprop=\"duration\" content=\"PT3M27S\" \/><meta itemprop=\"uploadDate\" content=\"2014-09-10T23:42:35Z\" \/><\/div><div id=\"lyte_hMkBQqkDUZI\" data-src=\"https:\/\/i.ytimg.com\/vi\/hMkBQqkDUZI\/maxresdefault.jpg\" class=\"pL\"><div class=\"tC\"><div class=\"tT\" itemprop=\"name\">SOLIDWORKS - Basic Macro<\/div><\/div><div class=\"play\"><\/div><div class=\"ctrl\"><div class=\"Lctrl\"><\/div><div class=\"Rctrl\"><\/div><\/div><\/div><noscript><a href=\"https:\/\/youtu.be\/hMkBQqkDUZI\" rel=\"nofollow\"><img decoding=\"async\" src=\"https:\/\/i.ytimg.com\/vi\/hMkBQqkDUZI\/0.jpg\" alt=\"SOLIDWORKS - Basic Macro\" width=\"853\" height=\"460\" \/><br \/>Bekijk deze video op YouTube<\/a><\/noscript><meta itemprop=\"description\" content=\"Learn how to record a basic macro in SOLIDWORKS and create a custom button to execute the macro. Quick Tip presented by Jeff Jensen of GoEngineer. See more at: http:\/\/www.goengineer.com\/products\/solidworks\/\"><\/div><\/div><div class=\"lL\" style=\"max-width:100%;width:853px;margin:5px;\"><\/div><\/div>\n<p>SOLIDWORKS does not record all of your actions, though. This is confusing and annoying for people that are just getting started. So don&#8217;t be surprised if your action does not show up in the macro. Just be disappointed \ud83d\ude09<\/p>\n<p>The macro recorder <strong>does<\/strong> record most actions that create geometry or features. It <strong>does not<\/strong> record many of the clicks in the user interface.<\/p>\n<h3 id=\"vba-editor-immediate-window\" class=\"anchor\">4. VBA editor: what is the immediate window?<\/h3>\n<p>I have recreated the actions in the video above and saved the result. Clicking the rightmost button in the macro toolbar opens up the Microsoft Visual Basic for Applications editor. In my case, it looks like this.<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-8207 size-full\" src=\"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-03-VBA-editor-window-solidworks.png\" alt=\"VBA editor window solidworks\" width=\"1024\" height=\"545\" srcset=\"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-03-VBA-editor-window-solidworks.png 1024w, https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-03-VBA-editor-window-solidworks-300x160.png 300w, https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-03-VBA-editor-window-solidworks-768x409.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>The window has five sections:<\/p>\n<ol>\n<li>Upper left: <strong>Project Explorer.<\/strong>\n<ul>\n<li>Here you can find the modules, user forms, class modules and SOLIDWORKS objects in your macro. Right-click to add any one of those things.<\/li>\n<\/ul>\n<\/li>\n<li>Lower left: <strong>Properties window<\/strong>.\n<ul>\n<li>When you select an element in a UserForm, this section shows the properties of that element.<\/li>\n<\/ul>\n<\/li>\n<li>The big one in the center: your <strong>main window<\/strong> for the code.<\/li>\n<li>Lower center: <strong>Immediate window<\/strong>.\n<ul>\n<li>You can write text to this window for easy debugging. The text will stay there until you manually select and delete it.<\/li>\n<\/ul>\n<\/li>\n<li>Lower right: <strong>Watches<\/strong>.\n<ul>\n<li>You can right-click a variable and add a watch to it. When you step through the macro with a few lines at a time, you can follow how the contents of this variable change with each step.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>One window that is not visible here is the <strong>Locals window<\/strong>. The Locals window shows you a list of the variables in your code and their current values.<\/p>\n<p>If you don&#8217;t see a certain window, click View at the top to enable the missing window.<\/p>\n<h3 id=\"explaning-the-recorded-code\" class=\"anchor\">5. Explaining the recorded code<\/h3>\n<p>I added numbers in red to the previous image to explain the code.<\/p>\n<p>I&#8217;ve written down everything that is happening in this short macro, everything that does not make sense and everything that I think you should know.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-8209\" src=\"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-04-recorded-macro-result.png\" alt=\"recorded macro result\" width=\"1024\" height=\"418\" srcset=\"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-04-recorded-macro-result.png 1024w, https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-04-recorded-macro-result-300x122.png 300w, https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-04-recorded-macro-result-768x314.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<ol>\n<li>A line that starts with a single quote ( &#8216; ) is a comment\n<ul>\n<li>Commented code will not be executed.<\/li>\n<li>It is good practice to start your macro with a few lines on the who, why and how.<\/li>\n<li>You can comment out part of a line. Anything on a line after the apostrophe is ignored.<\/li>\n<\/ul>\n<\/li>\n<li>The variable called swApp is created, or defined.\n<ul>\n<li>It starts with <a href=\"https:\/\/docs.microsoft.com\/en-us\/office\/vba\/language\/concepts\/getting-started\/declaring-variables\">Dim<\/a>, a standard word to create a dimension new variable, then its name, <em>as<\/em> and its type.<\/li>\n<li>This variable is used in every SOLIDWORKS macro and most people call it <em>swApp<\/em> to be able to read each others&#8217; code easily.<\/li>\n<li>It starts with a prefix (sw) to help you understand its type (a <a href=\"https:\/\/help.solidworks.com\/2020\/english\/api\/sldworksapi\/solidworks.interop.sldworks~solidworks.interop.sldworks.isldworks_members.html\">SOLIDWORKS object<\/a>). This way of working is called <a href=\"https:\/\/en.wikipedia.org\/wiki\/Hungarian_notation\">Hungarian notation<\/a> and it has gone out of style by now. Notice how it is used for longstatus (type = <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/visual-basic\/language-reference\/data-types\/long-data-type\">long<\/a>) and longwarnings as well.<\/li>\n<li>The rest of the name is a user-friendly name. In this case, <em>app<\/em> is short for <em>application<\/em>, the SOLIDWORKS application itself.<\/li>\n<li>The variable type is <em>object<\/em>, which means it can basically contain anything.\u00a0It is better to pick a more narrow variable type so cannot put incorrect data into the variable.<\/li>\n<li>If your object has no value yet, it is <em>nothing<\/em>. When you then try to do anything with it, you get the cryptic error message <em>Object variable or with block variable not set.<\/em><\/li>\n<li>If you define a variable outside of a sub or function, you can access it everywhere in your macro. It&#8217;s a <em>global variable<\/em>. This sounds great, but you should avoid using these as much as possible.<\/li>\n<\/ul>\n<\/li>\n<li>Other variables are defined\n<ul>\n<li>As you can, see you can define multiple variables on one line<\/li>\n<li>If you don&#8217;t specify a type (&#8220;Dim swApp&#8221;), the variable will be a <a href=\"https:\/\/docs.microsoft.com\/en-us\/office\/vba\/language\/concepts\/getting-started\/understanding-variants\">variant<\/a>.<\/li>\n<li>Variants are strange types that can contain any type of data, but you need to convert them to specific types if you want to do some real work with them<\/li>\n<li>Variants are required for <a href=\"https:\/\/docs.microsoft.com\/en-us\/office\/vba\/language\/concepts\/getting-started\/using-for-eachnext-statements\">for each<\/a> loops.<\/li>\n<\/ul>\n<\/li>\n<li>The subprocedure called <em>main<\/em> is created.\n<ul>\n<li>Everything until the <em>End Sub<\/em> at line 19 is a part of the main subprocedure.<\/li>\n<li>The brackets after\u00a0<em>main<\/em> can contain variables, called arguments or parameters, that this subprocedure needs to function. In this case, we don&#8217;t need any.<\/li>\n<li><em> Main<\/em> is the subprocedure that gets called by default when no subprocedure is specified.<\/li>\n<li>If there is no subprocedure without arguments called main, any subprocedure may be called. That is not what you want, so keep Main as the starting point.<\/li>\n<\/ul>\n<\/li>\n<li>The swApp variable is set to the current SOLIDWORKS application so that our macro can talk to SOLIDWORKS.\n<ul>\n<li>The underscore _ is there for no reason at all. It allows you to create long lines of code that are on multiple lines. You can safely remove the underscore and the enter so the line becomes <em>set swApp = Application.SldWorks<\/em><\/li>\n<li>If you are working with an <a href=\"https:\/\/docs.microsoft.com\/en-us\/office\/vba\/language\/concepts\/getting-started\/creating-object-variables\">object<\/a>, you need to start the line with\u00a0<a href=\"https:\/\/docs.microsoft.com\/en-us\/office\/vba\/language\/reference\/user-interface-help\/set-statement\">set<\/a>, followed by the variable name, an equals sign and its new value.<\/li>\n<li>If you are working with a <em>value type\u00a0<\/em>like a string, integer (a whole number) or a double (a double-precision decimal number), don&#8217;t use the word <em>set<\/em>.<\/li>\n<\/ul>\n<\/li>\n<li>The Part variable is set to the document that is currently open\n<ul>\n<li><em>Part<\/em> is a really poor variable name here, because the active model may be a part, drawing, assembly or nothing.<\/li>\n<li>Its actual type is <a href=\"https:\/\/help.solidworks.com\/2020\/english\/api\/sldworksapi\/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IModelDoc2_members.html\">ModelDoc2<\/a>.<\/li>\n<li>Notice that we get the part object from the <em>swApp<\/em> object. Objects have properties and methods. The <em>active model<\/em> is a property of the SldWorks object.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-8209\" src=\"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-04-recorded-macro-result.png\" alt=\"recorded macro result\" width=\"1024\" height=\"418\" srcset=\"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-04-recorded-macro-result.png 1024w, https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-04-recorded-macro-result-300x122.png 300w, https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-04-recorded-macro-result-768x314.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>(I repeated the image to make the post more readable)<\/p>\n<ol start=\"7\">\n<li>Because the variable Part is assigned the active document, you can now call special SOLIDWORKS <em>functions<\/em> (also named <em>methods<\/em>).\n<ul>\n<li>Add a dot after a variable name to see all available functions. If you don&#8217;t see any options appear, your object is probably just that, an <em>object<\/em>. Use a more specific type like <em>SldWorks.SldWorks<\/em> or <em>ModelDoc2<\/em> to see more options.<\/li>\n<li>Right here we use the method <a href=\"https:\/\/help.solidworks.com\/2020\/English\/api\/sldworksapi\/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.ISketchManager~InsertSketch.html\" target=\"_blank\" rel=\"noopener noreferrer\">InsertSketch<\/a>\u00a0to start a sketch on a pre-selected surface.<\/li>\n<li>If you call a method that needs parameters, <strong>and<\/strong> you want to store the return value, you need parentheses around the arguments. See line 15.<\/li>\n<li>If you do not store the return value of a method or the method has no parameters, you need no parentheses. VBA allows both, which is confusing for beginners and annoying for experts.<\/li>\n<\/ul>\n<\/li>\n<li><a href=\"https:\/\/help.solidworks.com\/2020\/english\/api\/sldworksapi\/SOLIDWORKS.Interop.sldworks~SOLIDWORKS.Interop.sldworks.IModelDoc2~ClearSelection2.html\"><em>ClearSelection2<\/em> <\/a>is the second and latest version of the <a href=\"https:\/\/help.solidworks.com\/2020\/english\/api\/sldworksapi\/solidworks.interop.sldworks~solidworks.interop.sldworks.imodeldoc2~clearselection.html\"><em>ClearSelection<\/em> <\/a>method.\n<ul>\n<li>For some reason, SOLIDWORKS needed a newer version of this method. They never remove the old version so they don&#8217;t break older macros. The old method is now called <em>Obsolete<\/em>.<\/li>\n<li><img decoding=\"async\" class=\"alignnone size-full wp-image-8201\" src=\"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-01-obsolete-method-solidworks-macro.png\" alt=\"\" width=\"381\" height=\"75\" srcset=\"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-01-obsolete-method-solidworks-macro.png 381w, https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-01-obsolete-method-solidworks-macro-300x59.png 300w\" sizes=\"(max-width: 381px) 100vw, 381px\" \/><\/li>\n<li>If anything was selected before the macro was started, it is deselected with this method call.<\/li>\n<\/ul>\n<\/li>\n<li>A new <a href=\"https:\/\/help.solidworks.com\/2020\/english\/api\/sldworksapi\/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.ISketchSegment_members.html\">sketch segment<\/a> variable is defined\n<ul>\n<li>Because this variable is defined within a subprocedure, it is called a <em>local variable,<\/em> which means that it can only be used within this subprocedure.<\/li>\n<li>The variables declared at the top at 2 and 3 can be used from anywhere and are called <em>global variables<\/em>.<\/li>\n<\/ul>\n<\/li>\n<li>A circle is drawn by the coordinates of the center point and one other point on the circle.\n<ol>\n<li>This line actually chains multiple objects.<\/li>\n<li>It uses the Part object (the active model), then its <a href=\"https:\/\/help.solidworks.com\/2020\/english\/api\/sldworksapi\/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.ISketchManager_members.html\">SketchManager<\/a> object (an object that lets you create and edit sketches) and calls the <a href=\"https:\/\/help.solidworks.com\/2020\/english\/api\/sldworksapi\/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.ISketchManager~CreateCircle.html\">CreateCircle<\/a> method.<\/li>\n<\/ol>\n<\/li>\n<li>The selection is cleared again<\/li>\n<li>InsertSketch is called again, this time to close the sketch<\/li>\n<li>The sketch is opened again.<\/li>\n<li>The selection is cleared again, this all seems pretty useless.<\/li>\n<li>The sketch is selected<\/li>\n<li>A new variable that can hold a <a href=\"https:\/\/help.solidworks.com\/2020\/english\/api\/sldworksapi\/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IFeature_members.html\">feature<\/a> is defined<\/li>\n<li>A new feature is created using the selected sketch and a whole lot of options.\n<ul>\n<li>Don&#8217;t even bother trying to remember all options. The <a href=\"https:\/\/help.solidworks.com\/2020\/english\/api\/sldworksapi\/SOLIDWORKS.Interop.sldworks~SOLIDWORKS.Interop.sldworks.IFeatureManager~FeatureCut3.html\" target=\"_blank\" rel=\"noopener noreferrer\">help<\/a> page will tell you what those options are. I visit the API Help every single day.<\/li>\n<\/ul>\n<\/li>\n<li><a href=\"https:\/\/help.solidworks.com\/2020\/english\/api\/sldworksapi\/solidworks.interop.sldworks~solidworks.interop.sldworks.iselectionmgr~enablecontourselection.html\">EnableContourSelection<\/a> can be used to select the contour of the sketch for the cut extrude.\n<ul>\n<li>We don\u2019t need that option anymore, so it can be disabled. Notice it wasn\u2019t enabled in this code, so it is probably enabled by default.<\/li>\n<\/ul>\n<\/li>\n<li>The main subprocedure is closed.\n<ol>\n<li>You can have multiple subprocedures and functions. I fact, it is a good practice to try to limit each function and procedure to about ten lines of code.<\/li>\n<li>Officially, a subprocedure returns no value and a function does. You can, however, create a function that returns no value<\/li>\n<li>To create a function that returns a value, type\u00a0<em>as<\/em> and a type after the function&#8217;s brackets. Example:\u00a0<em>Function ReturnModel() as ModelDoc2.<\/em><\/li>\n<li>To set the value that you want to return, use the name of the function. If you return an object, start with set. Example:\u00a0<em>set ReturnModel = swModel.<\/em><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<div style=\"margin: 40px 0; text-align: center; display: block; background-color: #f8f8f8; user-select: none; justify-content: center; border: 3px solid #2ac819; border-radius: 5px;\">\r\n<h2 style=\"color: #363636; font-size: 45px; margin: 20px 0 0 0;\">Ditch the Toolbox, once and for all<\/h2>\r\n<span class=\"subtitle\">Start using the fastener library that actually follows the standards<\/span>\r\n<div style=\"margin: 20px;\"><img decoding=\"async\" class=\"alignnone size-full wp-image-12394\" src=\"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2023\/02\/Fastener-models-banner-1000x114-1.png\" alt=\"\" width=\"800\" height=\"91\" srcset=\"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2023\/02\/Fastener-models-banner-1000x114-1.png 1000w, https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2023\/02\/Fastener-models-banner-1000x114-1-300x34.png 300w, https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2023\/02\/Fastener-models-banner-1000x114-1-768x88.png 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/div>\r\n<div style=\"display: flex; flex-direction: row; padding: 10px;\">\r\n<div style=\"width: 33%; display: flex; justify-content: center;\">\r\n<ul class=\"check check_fastener_models\" style=\"color: #363636; text-align: left; margin-bottom: 0px;\">\r\n<li>No more mate errors<\/li>\r\n<\/ul>\r\n<\/div>\r\n<div style=\"width: 33%; display: flex; justify-content: center;\">\r\n<ul class=\"check check_fastener_models\" style=\"color: #363636; text-align: left; margin-bottom: 0px;\">\r\n<li>Made for speed<\/li>\r\n<\/ul>\r\n<\/div>\r\n<div style=\"width: 33%; display: flex; justify-content: center;\">\r\n<ul class=\"check check_fastener_models\" style=\"color: #363636; text-align: left; margin-bottom: 0px;\">\r\n<li>No yearly license fees<\/li>\r\n<\/ul>\r\n<\/div>\r\n<\/div>\r\n<div style=\"margin-bottom: 20px;\"><a id=\"drew-banner-confirm\" class=\" shortcode_button btn_small btn_type1 fastener_models_button\" href=\"\/fastener-models\/\" target=\"_blank\" rel=\"noopener noreferrer\">Show me how<\/a><\/div>\r\n<\/div>\n<h3 id=\"improving-the-recorded-code\" class=\"anchor\">6. Improving the recorded code<\/h3>\n<p>The output from the macro recorder is far from great.<\/p>\n<p>It does not even use all variables and some lines are in there way too many times. Time to clean it up. This is what it can look like afterwards.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-8211\" src=\"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-05-solidworks-macros-cleaned-up-recording.png\" alt=\"solidworks macros - cleaned up recording\" width=\"1024\" height=\"421\" srcset=\"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-05-solidworks-macros-cleaned-up-recording.png 1024w, https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-05-solidworks-macros-cleaned-up-recording-300x123.png 300w, https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-05-solidworks-macros-cleaned-up-recording-768x316.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>As you can see I have:<\/p>\n<ul>\n<li>Moved the variable declarations to the top of the program for clarity (2020 update: don&#8217;t create a long list of all variables at the top of your program)<\/li>\n<li>Chose more narrow variable types to prevent weird, unpredictable behavior.<\/li>\n<li>Removed the underscore at the definition of swApp. The underscore is used to split a long line of code across multiple lines. That\u2019s not the case here.<\/li>\n<li>Removed all of the selection clearing<\/li>\n<li>Removed two of the <em>Insert Sketch<\/em> lines that didn\u2019t do anything.<\/li>\n<li>Set the draft angles of the feature to zero instead of 1.7451558415E-02. Two of the \u2018false\u2019 statements were to disable a draft anyway.<\/li>\n<\/ul>\n<p>The functionality hasn\u2019t changed a bit though. It still creates a sketch and a cut-extrude on a previously selected face.<\/p>\n<p>And now that I am refreshing this blog post in 2020, I would make even more changes:<\/p>\n<ol>\n<li>I would move the global variables into the subprocedure. No globals unless we really need them.<\/li>\n<li>I would remove longstatus and longwarnings because they are never used.<\/li>\n<li>I would remove boolstatus if we don&#8217;t need its value after calling SelectByID2. We then need to remove the brackets around the parameters.<\/li>\n<li>I would rename <em>Part\u00a0<\/em>to\u00a0<em>swModel <\/em> and make it of type ModelDoc2. The naming is the convention in SOLIDWORKS macro land. The Part type is too restrictive because the model can also be an assembly.<\/li>\n<li>I would renamed myFeature to swFeat, also a convention.<\/li>\n<li>I would declare my variables just before I need them. This makes it easier to find out their type and makes it easier to spot problems. List all of you variables at the top is and old C++ convention that we don&#8217;t need here.<\/li>\n<\/ol>\n<h3 id=\"checking-the-model-type\" class=\"anchor\">7. Checking the model type to prevent errors<\/h3>\n<p>It is good practice to be ready for all possible situations.<\/p>\n<p>Your code should not crash or give an error when the user does something unexpected. It is your fault that you did not expect that, so don&#8217;t blame the user.<\/p>\n<p>So we&#8217;re adding some basic checks, which include, in this order:<\/p>\n<h4>Check if swModel is Nothing<\/h4>\n<p>After we get swApp, we can get the active model.<\/p>\n<pre class=\"lang:vb decode:true\">dim swApp as SldWorks.SldWorks\r\nset swApp = Applcation.Sldworks\r\n\r\nDim swModel as ModelDoc2\r\nset swModel = swApp.ActiveDoc\r\n\r\nif swModel is nothing then \r\n  Msgbox \"Please open a model first\" \r\n  End\r\nEnd if<\/pre>\n<p>Getting swApp never goes wrong. But if not model is open, swModel will be nothing. In that case, we show a message box to the user. <em>End<\/em> stops execution of the macro entirely.<\/p>\n<h4>Check if the model is the correct type<\/h4>\n<p>If you only want to work with the ModelDoc2 object, you don&#8217;t need these checks. But when you want to call methods that are only available for <a href=\"https:\/\/help.solidworks.com\/2020\/english\/api\/sldworksapi\/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IPartDoc.html\">part<\/a>, <a href=\"https:\/\/help.solidworks.com\/2020\/english\/api\/sldworksapi\/solidworks.interop.sldworks~solidworks.interop.sldworks.iassemblydoc_members.html\">assembly<\/a> or <a href=\"https:\/\/help.solidworks.com\/2020\/english\/api\/sldworksapi\/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IDrawingDoc.html\">drawing<\/a> objects, you need to verify the active model type. To make sure the model is a part:<\/p>\n<pre class=\"lang:vb decode:true\">dim swApp as SldWorks.SldWorks\r\nset swApp = Applcation.Sldworks\r\n\r\nDim swModel as ModelDoc2\r\nset swModel = swApp.ActiveDoc\r\n\r\nif swModel is nothing then \r\n  Msgbox \"Please open a model first\" \r\n  End\r\nEnd if\r\n\r\nif swModel.GetType &lt;&gt; swDocumentTypes_e.swDocPART then\r\n  Msgbox \"Please open a part first\"\r\n  End\r\nEnd if\r\n\r\n'Perform the actual work here<\/pre>\n<h4>Other checks<\/h4>\n<p>For this particular macro, we should also check if the user selected a face beforehand. If not, you can give the user a message box with an error and stop the execution of the macro.<\/p>\n<h3 id=\"how-to-debug-vba-solidworks-macros\" class=\"anchor\">8. How to debug VBA SOLIDWORKS macros<\/h3>\n<p>There are a few options that you should know when you want to properly test en debug your bits of code:<\/p>\n<h4>Step by step<\/h4>\n<p>You can execute your code until a certain point by setting your cursor where it needs to pause and click Debug &gt; Step into or press F8. The code runs until it reaches this point. From there you can run it line by line by pressing F8, this is a great way to debug your own code or to get to know another macro.<\/p>\n<p>Pressing F5 calls the run command and runs the macro until the end or until you reach a breakpoint.<\/p>\n<figure id=\"attachment_151\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"alignnone size-full wp-image-8213\" src=\"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-06-solidworks-macro-step-though-debug.png\" alt=\"solidworks macro step though debug\" width=\"768\" height=\"414\" srcset=\"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-06-solidworks-macro-step-though-debug.png 768w, https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-06-solidworks-macro-step-though-debug-300x162.png 300w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<h4>Breakpoints<\/h4>\n<p>By left-clicking before a line, you can add Break Points. The execution of code stops at these points.<\/p>\n<p>Now you can assert the values of variables by hovering over them or by checking those that you\u2019ve assigned watches to.<\/p>\n<p>Pressing the play button will make it hop until the next breakpoint, hitting stop will make it stop immediately.<\/p>\n<figure id=\"attachment_152\" class=\"wp-caption aligncenter below-entry-meta\"><img decoding=\"async\" class=\"alignnone size-full wp-image-8215\" src=\"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-07-Solidworks-macro-breakpoint.png\" alt=\"Solidworks macro breakpoint\" width=\"876\" height=\"461\" srcset=\"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-07-Solidworks-macro-breakpoint.png 876w, https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-07-Solidworks-macro-breakpoint-300x158.png 300w, https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-07-Solidworks-macro-breakpoint-768x404.png 768w\" sizes=\"(max-width: 876px) 100vw, 876px\" \/><\/figure>\n<h4>Debug.Print [variable name]<\/h4>\n<p>This line adds the contents of one or multiple variables to the Immediate Window, as long as they contain text or numbers. You can combine multiple strings or values with an ampersand (&amp;).<\/p>\n<p>Example: <em>Debug.Print \u201cThe value of boolstatus is \u201d &amp; boolstatus<\/em><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-8217\" src=\"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-08-vba-macro-immediate-window-debug.print_.png\" alt=\"vba macro immediate window debug.print\" width=\"320\" height=\"225\" srcset=\"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-08-vba-macro-immediate-window-debug.print_.png 320w, https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2020\/12\/067-08-vba-macro-immediate-window-debug.print_-300x211.png 300w\" sizes=\"(max-width: 320px) 100vw, 320px\" \/><\/p>\n<h4>Debug.Assert [variable name] [condition]<\/h4>\n<p>The line <em>Debug.Assert x &gt; 10<\/em> will assert whether x is indeed greater than 10 and it will pause the program if it isn\u2019t.<\/p>\n<h4>Call stack<\/h4>\n<p>The last tool for debugging that I want to mention is the Call Stack option.<\/p>\n<p>When the code execution is started and paused, you can press <em>View<\/em> &gt; <em>Call Stack<\/em> or <em>Ctrl + L<\/em> to see how the current function has been called by other functions. This is a really powerful tool, although the VBA implementation isn&#8217;t that great.<\/p>\n<h3 id=\"how-to-pick-a-language\" class=\"anchor\">9. How to pick a language<\/h3>\n<p>You can write macros in three Microsoft-based programming languages. The first one is Visual Basic for Applications (VBA), of which you have seen a lot above.<\/p>\n<p>It is easiest to start with VBA because it is the most accessible option. The help website by SOLIDWORKS is also extensive and sorted by version.<\/p>\n<p>VB (which used to be called VB.NET) and C# are the other two options. These are the more modern and more advanced options. They also allow you to create add-ins for SOLIDWORKS, this isn\u2019t possible with VBA.<\/p>\n<h3 id=\"solidworks-macros-sources-and-courses\" class=\"anchor\">10. Sources and courses<\/h3>\n<p>Here are some useful sites when you want to get started with building macros for SOLIDWORKS:<\/p>\n<ul>\n<li>The official <a href=\"https:\/\/help.solidworks.com\/2016\/English\/api\/sldworksapiprogguide\/Welcome.htm\" target=\"_blank\" rel=\"noopener noreferrer\">SOLIDWORKS API Help<\/a> and specifically, the section on <a href=\"https:\/\/help.solidworks.com\/2020\/English\/api\/sldworksapiprogguide\/GettingStarted\/SolidWorks_Macros.htm\">macros<\/a>.<\/li>\n<li>The official <a href=\"https:\/\/forum.solidworks.com\/welcome\" target=\"_blank\" rel=\"noopener noreferrer\">SOLIDWORKS forums<\/a>, where I regularly hang out.<\/li>\n<li>Microsoft\u00a0<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/office\/gg264383.aspx\" target=\"_blank\" rel=\"noopener noreferrer\">Office VBA reference<\/a>.<\/li>\n<\/ul>\n<ul>\n<li>I am writing a <a href=\"https:\/\/staging.cadbooster.com\/the-solidworks-object-model-api-explained-part-1\/\">blog series<\/a> on understanding the SOLIDWORKS API and its\u00a0<em>object model.<\/em><\/li>\n<li><a href=\"https:\/\/www.cadsharp.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">CADSharp.com<\/a> has many free videos and macros to learn from.<\/li>\n<li><a href=\"https:\/\/angelsix.com\/solidworks\" target=\"_blank\" rel=\"noopener noreferrer\">AngelSix<\/a> has two (rather dated, but still useful) freely available SOLIDWORKS books and many macros. His <a href=\"https:\/\/www.youtube.com\/playlist?list=PLrW43fNmjaQVMN1-lsB29ECnHRlA4ebYn\">videos<\/a> on C# and add-ins helped me get started after I launched CAD Booster.<\/li>\n<li>We have great articles about <a href=\"https:\/\/staging.cadbooster.com\/complete-overview-of-matrix-transformations-in-the-solidworks-api\/\">matrix transformations in SOLIDWORKS<\/a> and about <a href=\"https:\/\/staging.cadbooster.com\/improve-solidworks-macro-speed-10x\/\">How to improve macro speed 10x<\/a>.<\/li>\n<\/ul>\n<p>Doing a Google search in the form of <em>SOLIDWORKS API [your search term]<\/em> will also do miracles. I do that a dozen times a day.<\/p>\n<p>If you want some professional guidance in your endeavors, you can enroll in this course by SOLIDWORKS:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.solidworks.com\/sw\/support\/1509_ENU_HTML.htm\" target=\"_blank\" rel=\"noopener noreferrer\">API Fundamentals Course<\/a><\/li>\n<\/ul>\n<p>Your current Value Added Reseller (VAR) can help you with official SOLIDWORKS courses.<\/p>\n<h3 id=\"\" class=\"anchor\">11. Or just let us build you a macro (or add-in)<\/h3>\n<p>I started CAD Booster four years ago to automate the boring bits of my engineering job. Since then, I have created add-ins like <a href=\"https:\/\/staging.cadbooster.com\/drew\/\">Drew<\/a> and <a href=\"https:\/\/staging.cadbooster.com\/solidworks-add-in\/lightning-fastener-filter\/\">Lightning<\/a>, plus a dozen others for our customers.<\/p>\n<p>Because of all that experience, I know my way around the SOLIDWORKS API. So a macro that might take you days can sometimes take me only 30 minutes.<\/p>\n<p>I will usually advise you to develop an add-in because they are more stable and can be maintained properly, but I also just finished a macro for a customer.<\/p>\n<p>Check out the <a href=\"https:\/\/staging.cadbooster.com\/contact\/\">Contact page<\/a> for our email address and phone number.<\/p>\n<h3>12. Final words<\/h3>\n<p>Are you excited to build a simple program that can take over some of your daily tasks? I\u2019m pretty sure there are some great ideas out there.<\/p>\n<p>To learn more, check out my <a href=\"https:\/\/staging.cadbooster.com\/the-solidworks-object-model-api-explained-part-1\/\">blog series on the SOLIDWORKS API<\/a>.<\/p>\n<p>Now let\u2019s get those little robots to do our chores!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s how to get started with SOLIDWORKS macros if you never created one before.<\/p>\n","protected":false},"author":6,"featured_media":8280,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[214],"tags":[367,240,276,243,369],"class_list":["post-8197","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-solidworks-macros-en","tag-add-in","tag-api","tag-macro","tag-timesavers-show","tag-vba"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.1 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Macros for SOLIDWORKS: the absolute basics - CAD Booster<\/title>\n<meta name=\"description\" content=\"If you have never written SOLIDWORKS macros before, this is the post for you. We&#039;ll explain variables, the VBA editor and debugging.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/staging.cadbooster.com\/macros-for-solidworks-the-absolute-basics\/\" \/>\n<meta property=\"og:locale\" content=\"nl_NL\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Macros for SOLIDWORKS: the absolute basics\" \/>\n<meta property=\"og:description\" content=\"If you have never written SOLIDWORKS macros before, this is the post for you. We&#039;ll explain variables, the VBA editor and debugging.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/staging.cadbooster.com\/macros-for-solidworks-the-absolute-basics\/\" \/>\n<meta property=\"og:site_name\" content=\"CAD Booster\" \/>\n<meta property=\"article:published_time\" content=\"2020-12-23T12:16:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-12T15:15:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2021\/01\/067-00-solidworks-macros-absolute-basics.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1170\" \/>\n\t<meta property=\"og:image:height\" content=\"830\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Peter Brinkhuis\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Geschreven door\" \/>\n\t<meta name=\"twitter:data1\" content=\"Peter Brinkhuis\" \/>\n\t<meta name=\"twitter:label2\" content=\"Geschatte leestijd\" \/>\n\t<meta name=\"twitter:data2\" content=\"18 minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/staging.cadbooster.com\\\/macros-for-solidworks-the-absolute-basics\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/staging.cadbooster.com\\\/macros-for-solidworks-the-absolute-basics\\\/\"},\"author\":{\"name\":\"Peter Brinkhuis\",\"@id\":\"https:\\\/\\\/staging.cadbooster.com\\\/#\\\/schema\\\/person\\\/d210017041c9b4c601de29a8e7953506\"},\"headline\":\"Macros for SOLIDWORKS: the absolute basics\",\"datePublished\":\"2020-12-23T12:16:14+00:00\",\"dateModified\":\"2025-01-12T15:15:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/staging.cadbooster.com\\\/macros-for-solidworks-the-absolute-basics\\\/\"},\"wordCount\":3556,\"publisher\":{\"@id\":\"https:\\\/\\\/staging.cadbooster.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/staging.cadbooster.com\\\/macros-for-solidworks-the-absolute-basics\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/staging.cadbooster.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/067-00-solidworks-macros-absolute-basics.jpg\",\"keywords\":[\"add-in\",\"API\",\"macro\",\"TimeSavers-show\",\"vba\"],\"articleSection\":[\"API \\\/ macros\"],\"inLanguage\":\"nl-NL\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/staging.cadbooster.com\\\/macros-for-solidworks-the-absolute-basics\\\/\",\"url\":\"https:\\\/\\\/staging.cadbooster.com\\\/macros-for-solidworks-the-absolute-basics\\\/\",\"name\":\"Macros for SOLIDWORKS: the absolute basics - CAD Booster\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/staging.cadbooster.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/staging.cadbooster.com\\\/macros-for-solidworks-the-absolute-basics\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/staging.cadbooster.com\\\/macros-for-solidworks-the-absolute-basics\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/staging.cadbooster.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/067-00-solidworks-macros-absolute-basics.jpg\",\"datePublished\":\"2020-12-23T12:16:14+00:00\",\"dateModified\":\"2025-01-12T15:15:35+00:00\",\"description\":\"If you have never written SOLIDWORKS macros before, this is the post for you. We'll explain variables, the VBA editor and debugging.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/staging.cadbooster.com\\\/macros-for-solidworks-the-absolute-basics\\\/#breadcrumb\"},\"inLanguage\":\"nl-NL\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/staging.cadbooster.com\\\/macros-for-solidworks-the-absolute-basics\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"nl-NL\",\"@id\":\"https:\\\/\\\/staging.cadbooster.com\\\/macros-for-solidworks-the-absolute-basics\\\/#primaryimage\",\"url\":\"https:\\\/\\\/staging.cadbooster.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/067-00-solidworks-macros-absolute-basics.jpg\",\"contentUrl\":\"https:\\\/\\\/staging.cadbooster.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/067-00-solidworks-macros-absolute-basics.jpg\",\"width\":1170,\"height\":830,\"caption\":\"solidworks macros absolute basics\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/staging.cadbooster.com\\\/macros-for-solidworks-the-absolute-basics\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/staging.cadbooster.com\\\/nl\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Macros for SOLIDWORKS: the absolute basics\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/staging.cadbooster.com\\\/#website\",\"url\":\"https:\\\/\\\/staging.cadbooster.com\\\/\",\"name\":\"CAD Booster\",\"description\":\"SOLIDWORKS AUTOMATION\",\"publisher\":{\"@id\":\"https:\\\/\\\/staging.cadbooster.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/staging.cadbooster.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"nl-NL\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/staging.cadbooster.com\\\/#organization\",\"name\":\"CAD Booster\",\"url\":\"https:\\\/\\\/staging.cadbooster.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"nl-NL\",\"@id\":\"https:\\\/\\\/staging.cadbooster.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/staging.cadbooster.com\\\/wp-content\\\/uploads\\\/2016\\\/11\\\/logo-CAD-Booster.png\",\"contentUrl\":\"https:\\\/\\\/staging.cadbooster.com\\\/wp-content\\\/uploads\\\/2016\\\/11\\\/logo-CAD-Booster.png\",\"width\":1732,\"height\":964,\"caption\":\"CAD Booster\"},\"image\":{\"@id\":\"https:\\\/\\\/staging.cadbooster.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/staging.cadbooster.com\\\/#\\\/schema\\\/person\\\/d210017041c9b4c601de29a8e7953506\",\"name\":\"Peter Brinkhuis\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Macros for SOLIDWORKS: the absolute basics - CAD Booster","description":"If you have never written SOLIDWORKS macros before, this is the post for you. We'll explain variables, the VBA editor and debugging.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/staging.cadbooster.com\/macros-for-solidworks-the-absolute-basics\/","og_locale":"nl_NL","og_type":"article","og_title":"Macros for SOLIDWORKS: the absolute basics","og_description":"If you have never written SOLIDWORKS macros before, this is the post for you. We'll explain variables, the VBA editor and debugging.","og_url":"https:\/\/staging.cadbooster.com\/macros-for-solidworks-the-absolute-basics\/","og_site_name":"CAD Booster","article_published_time":"2020-12-23T12:16:14+00:00","article_modified_time":"2025-01-12T15:15:35+00:00","og_image":[{"width":1170,"height":830,"url":"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2021\/01\/067-00-solidworks-macros-absolute-basics.jpg","type":"image\/jpeg"}],"author":"Peter Brinkhuis","twitter_card":"summary_large_image","twitter_misc":{"Geschreven door":"Peter Brinkhuis","Geschatte leestijd":"18 minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/staging.cadbooster.com\/macros-for-solidworks-the-absolute-basics\/#article","isPartOf":{"@id":"https:\/\/staging.cadbooster.com\/macros-for-solidworks-the-absolute-basics\/"},"author":{"name":"Peter Brinkhuis","@id":"https:\/\/staging.cadbooster.com\/#\/schema\/person\/d210017041c9b4c601de29a8e7953506"},"headline":"Macros for SOLIDWORKS: the absolute basics","datePublished":"2020-12-23T12:16:14+00:00","dateModified":"2025-01-12T15:15:35+00:00","mainEntityOfPage":{"@id":"https:\/\/staging.cadbooster.com\/macros-for-solidworks-the-absolute-basics\/"},"wordCount":3556,"publisher":{"@id":"https:\/\/staging.cadbooster.com\/#organization"},"image":{"@id":"https:\/\/staging.cadbooster.com\/macros-for-solidworks-the-absolute-basics\/#primaryimage"},"thumbnailUrl":"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2021\/01\/067-00-solidworks-macros-absolute-basics.jpg","keywords":["add-in","API","macro","TimeSavers-show","vba"],"articleSection":["API \/ macros"],"inLanguage":"nl-NL"},{"@type":"WebPage","@id":"https:\/\/staging.cadbooster.com\/macros-for-solidworks-the-absolute-basics\/","url":"https:\/\/staging.cadbooster.com\/macros-for-solidworks-the-absolute-basics\/","name":"Macros for SOLIDWORKS: the absolute basics - CAD Booster","isPartOf":{"@id":"https:\/\/staging.cadbooster.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/staging.cadbooster.com\/macros-for-solidworks-the-absolute-basics\/#primaryimage"},"image":{"@id":"https:\/\/staging.cadbooster.com\/macros-for-solidworks-the-absolute-basics\/#primaryimage"},"thumbnailUrl":"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2021\/01\/067-00-solidworks-macros-absolute-basics.jpg","datePublished":"2020-12-23T12:16:14+00:00","dateModified":"2025-01-12T15:15:35+00:00","description":"If you have never written SOLIDWORKS macros before, this is the post for you. We'll explain variables, the VBA editor and debugging.","breadcrumb":{"@id":"https:\/\/staging.cadbooster.com\/macros-for-solidworks-the-absolute-basics\/#breadcrumb"},"inLanguage":"nl-NL","potentialAction":[{"@type":"ReadAction","target":["https:\/\/staging.cadbooster.com\/macros-for-solidworks-the-absolute-basics\/"]}]},{"@type":"ImageObject","inLanguage":"nl-NL","@id":"https:\/\/staging.cadbooster.com\/macros-for-solidworks-the-absolute-basics\/#primaryimage","url":"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2021\/01\/067-00-solidworks-macros-absolute-basics.jpg","contentUrl":"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2021\/01\/067-00-solidworks-macros-absolute-basics.jpg","width":1170,"height":830,"caption":"solidworks macros absolute basics"},{"@type":"BreadcrumbList","@id":"https:\/\/staging.cadbooster.com\/macros-for-solidworks-the-absolute-basics\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/staging.cadbooster.com\/nl\/"},{"@type":"ListItem","position":2,"name":"Macros for SOLIDWORKS: the absolute basics"}]},{"@type":"WebSite","@id":"https:\/\/staging.cadbooster.com\/#website","url":"https:\/\/staging.cadbooster.com\/","name":"CAD Booster","description":"SOLIDWORKS AUTOMATION","publisher":{"@id":"https:\/\/staging.cadbooster.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/staging.cadbooster.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"nl-NL"},{"@type":"Organization","@id":"https:\/\/staging.cadbooster.com\/#organization","name":"CAD Booster","url":"https:\/\/staging.cadbooster.com\/","logo":{"@type":"ImageObject","inLanguage":"nl-NL","@id":"https:\/\/staging.cadbooster.com\/#\/schema\/logo\/image\/","url":"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2016\/11\/logo-CAD-Booster.png","contentUrl":"https:\/\/staging.cadbooster.com\/wp-content\/uploads\/2016\/11\/logo-CAD-Booster.png","width":1732,"height":964,"caption":"CAD Booster"},"image":{"@id":"https:\/\/staging.cadbooster.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/staging.cadbooster.com\/#\/schema\/person\/d210017041c9b4c601de29a8e7953506","name":"Peter Brinkhuis"}]}},"_links":{"self":[{"href":"https:\/\/staging.cadbooster.com\/nl\/wp-json\/wp\/v2\/posts\/8197","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/staging.cadbooster.com\/nl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/staging.cadbooster.com\/nl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/staging.cadbooster.com\/nl\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/staging.cadbooster.com\/nl\/wp-json\/wp\/v2\/comments?post=8197"}],"version-history":[{"count":2,"href":"https:\/\/staging.cadbooster.com\/nl\/wp-json\/wp\/v2\/posts\/8197\/revisions"}],"predecessor-version":[{"id":14339,"href":"https:\/\/staging.cadbooster.com\/nl\/wp-json\/wp\/v2\/posts\/8197\/revisions\/14339"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/staging.cadbooster.com\/nl\/wp-json\/wp\/v2\/media\/8280"}],"wp:attachment":[{"href":"https:\/\/staging.cadbooster.com\/nl\/wp-json\/wp\/v2\/media?parent=8197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/staging.cadbooster.com\/nl\/wp-json\/wp\/v2\/categories?post=8197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/staging.cadbooster.com\/nl\/wp-json\/wp\/v2\/tags?post=8197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}