Solidworks api vba how to#
This makes the macro customizable without having to know how to program VBA, C++, or the SolidWorks API.įor the example shown here, I have defined the following rules to maintain consistency within my macros and source files: An external source file allows users to define their own parameters and options that are used when running a macro. These routines are used in a number of macros I have written and placed on these web pages.
Use 'ComboMaterial.ListCount - 1' to determine list length, number of rows or entries in list.Use 'ComboMaterial.List(ComboMaterial.ListCount - 1, column)' to add data to each column of the last row.This places material data entry in a separate row. Use 'ComboMaterial.AddItem' to add a row.Set column widths for columns 2 thru 4 to zero (0) to hide the data in these columns.The list is formatted as follows: Material Name, Density, Hatch Name and Color.Place list into 'ComboMaterial' combo box as it's read from the external source file.If external source file does not exist, use program defaults.Read external source file (see below) for list of material options.The data that does not need to be viewed by the user is hidden by setting the column's width to zero (0). The following example was used in the macro MaterialProperties where material data is read into the material selection combobox control on the form.
Solidworks api vba software#
Your only limit is the maximum number of rows that can be places into the combobox or listbox that is defined by the programming software you are using. The advantage is that you don't need to know, or have to set/limit, the size of the data array when the program is executed. Instead of creating arrays, of potentially unknown length, place the values in a hidden column in an existing combobox or listbox on the form, or if necessary, create a new combobox or listbox, and hide it from the user. Do some research ahead of time to save time for you later on.
Solidworks api vba code#
There are a lot of websites on the internet where you can get existing code for doing those common tasks. If you have already been writing macros, export the code and forms into another directory where they can easily be referenced while you writing other macros.
The idea here is to write and test small portions of code at a time. When writing a macro, is very easy to get overwhelmed very quickly.
Here are some techniques I use when writing a new macro. See my AnnotationsPro macro.įor more ideas, take a look at my Macros page. You can create a macro that ensures specific settings are properly set, and the document complies with these settings.