Archive for the ‘API Macros’ Category
Design Automation and SolidWorks API and Macros
Paul Gimbel provided in SlideShare website some few things about automation that each designer should know:1
Design Automation
- 100% automation is generally unachievable.
- Typically, the last 10% of automation will not be worth it.
- Something you didn’t plan for will always come up.
- Your drawings are probably going to require clean-up.
- Testing will take you far longer than you expect.
- Your system will require ongoing maintenance and updates.
Design automation is a time-saver that is used to reduce the design cycle time by providing consistency and repeatability, which are two things that are essential in capturing and sharing efficient design methods. Design automation results to a quicker development and a shorter time to market which in turn results to a reduced total design cycle time and an increase in profitability.4 The SolidWorks API (Application Programmer’s Interface) is a “group of functions that provides direct access to SolidWorks functionality.” Examples of such functionalities are creation of a line, extruding a boss, or outputting a file format. The SolidWorks API is the gateway to the automation of repetitive tasks such as batch plotting, custom property access, or assembly “configurators.” [5] A page in DesignPoint Solutions provides some examples of what SolidWorks API can do:5
Design Automation with SolidWorks Macros and API
- Creating an application that can take any sheet metal part, generate its flat pattern and output it as a DXF file for use in a manufacturing environment
- Creating an application that can take all the drawings associated with a project and can print them at one time with no user interaction
- Creating an application that controls the custom properties of a part within the company standards that you define
- Creating an application that would take the input of a sales person, build a custom design and automatically generate an eDrawing of the new product for delivery to the customer
- Creating an application that could access any project, query the design, generate a Bill of Materials and output it in a format suitable for MRP integration
- Creating an application that could generate a custom hole chart based on a coordinate system and any part
Macro information is the “recording of the modeling commands sequence or the modeling history.”2 SolidWorks macros are un-compiled “programs written in Visual Basic for Applications, VBA for short,” although it can also be programmed using any software that supports COM (Component Object Model). VBA is the “most common COM-supporting development environment.” To save time, macros are used to simplify or automate tasks that are constantly being repeated.3 The words “macro” and “API” are sometimes used interchangeably. The difference lies in their nature. APIs are compiled programs, such as add-ins or some external executables, while macros are un-compiled programs.3
1Gimbel, Paul. “Design Automation: Simple Solid Works Solutions to Practical Programmatic Packages.” Razorleaf. 15 Sep 2009. 3 Jan 2011 <http://www.slideshare.net/Razorleaf/design-automation-simple-solid-works-solutions-to-practical-programmatic-packages>.
2Kim, Byungchul, and Soonhung Han. “Integration of History-Based Parametric Translators Using the Automation APIs.” International Journal of Product Lifecycle Management 2.1 (2007): 18-29. 4 Jan 2011 <http://macro-parametrics.org/wiki/Datas/publications_link/1.pdf>.
3CharlesCulp. “Macros and API.” SolidMentor. 29 Nov 2007. 3 Jan 2011 <http://solidmentor.com/modules/wiwimod/index.php?page=Macros>.
4Nikolic, Dragomir M. An Improved Method and Apparatus for Automated Design and Verification of Integrated Circuits. Kentucky: University of Kentucky, 2005. 3 Jan 2011 <http://archive.uky.edu/bitstream/10225/279/thesis_final.pdf>.
5“Training – SolidWorks API Fundamentals and Intro to VB Programming.” DesignPoint Solutions. 13 Aug 2010. 3 Jan 2011 <http://www.design-point.com/t/designpoint_training_api.html>.
For more information about CAD services, please read more.
API Macros
A MACRO (merge and correlate recorded output) is “anything more than a single command1” and a “rule or pattern that specifies how a certain input sequence should be mapped to an output sequence according to a defined procedure.4” Macro programs are “computer programs that capture the user’s actions as if it is recording the user.5” For example, macros can record mouse clicks, menu choices, and keystrokes.4 A macro may be made up of either a command and an option or commands, their options, and programming codes. Additional programming codes are included in macros to make it sure that macros work under any condition. For example, “^C^C^C” is used to cancel running AutoCAD commands, and “_” is used to make macros work with AutoCAD in any language.1 When being shared, some macros, such as those written using VBA (Visual Basic for Applications), require users to share source codes also.2 With the help of macros, users interact with the model environment through the API (application programming interface). Macros require some knowledge about software languages, but these programming languages are limited by what the command processor can handle. In macros, calls that are directed towards the API are like operations the users do in the UI. Macro programs can create, manipulate, plot, and print files as well as start programs or applications. For example, macro programs can use the mail function of the operating system to send files when such function is not supported by the interface of the CAD system. Macro programs are executed by a command processor in the system. In order to be effective and to serve their purpose, macro programs are expected to perform faster than users who enter commands in the UI.4,5 The following are some reasons to write macros:4
What Are Macros?
Why Write Macros?
- Automation of common and repetitive tasks
- Design optimization
- Macros as bases for the development of special tools
- For retrieving or exporting data from documents of the CAD solid modeler
- Increase in productivity and standardization of procedures
The following are commonly used for writing macros, particularly macros for SolidWorks:4
- VBA
- Programming languages for writing standalone applications
Users get VBA along with their SolidWorks. Here, macros are saved as *.swp files. For them to create or edit SolidWorks macros, they first launch the VBA editor from within SolidWorks.4 For standalone applications, knowledge in Visual C++.Net, Visual Basic.Net, Visual C++, Visual Basic, and Visual Studio is required.4 It is easier to develop most macros in VBA than in VB.Net.2 Another way to develop macros is by the use of VSTA (Visual Studio Tools for Applications). In VSTA, users can store macros either externally or within a document. VSTA allows users to develop them using either Visual Basic.NET or C#.3 The result of automating common and repetitive tasks is a reduced time in doing processes.4 For example, a company need not do same tasks over and over again to create a standard component where formulas and parameters are used in the overall geometry of the component, if a macro program for doing it is already available.5 An API is used in designing solid modeling systems. It serves as the canvas for writing a macro. Based on a given parameter, the macro issues geometric instructions to the solid modeler, and then these geometric instructions are used in creating solid models of 3D designs.4 In SolidWorks, to create a macro program, the user clicks the start button in the macro toolbar, thereby ordering the CAD software to start recording. Then the user does operations that are being captured. Finally, the user clicks the stop button to tell the software to stop recording, and then the user saves the newly created macro.5 In 2D and 3D designs, macros automate design processes, while in 3D CAD packages, macros create and analyze design iterations.4 Macro programs are not necessarily the same with API programs. Sometimes, API-type of programs performs faster than macro programs. For example, creating thousands of lines, arcs, and dimensions would take a macro program some time to finish, but an API-type of program can do these tasks in seconds. API-type of programs uses the following languages: FORTRAN, Lisp, ADA, C, C++, or Java.5 For SolidWorks, its API uses VBA in developing procedural algorithms into the modeler.4 By using an API, entity databases can be accessed directly, which cannot be done by using macros. Scope and readability are limitations for macro programs, while the computer language that is being used is the only limitation for API-type of programs.5 API programming has its own advantages. These are the following:5
Macro Programs and API-Type of Programs
- Ability to run as fast as the CAD system
- Program sophistication
The following are SolidWorks API entities:4
- Native geometrical entities
- Native mathematical entities
- User-defined entities
The following are list of SolidWorks API:4
- EDrawings API
- FeatureWorks API
- PDMWorks API
- PhotoWorks API
- SolidWorks Routing API
- SolidWorks API
- SolidWorks Utilities API
The following are CAD packages that support API:4
- CATIA
- Mechanical Desktop
- Pro/ENGINEER
- SolidWorks
- Unigraphics
1Ralph Grabowski. “TIPS: Macros.” Online posting. 5 Feb 2004. WorldCAD Access. 26 July 2010 <http://worldcadaccess.typepad.com/blog/2004/02/tips_macros.html>.
2Ekins, Brian. Inventor® API: Taking the Step from VBA Macros to Add-Ins. Autodesk University, 2008. 26 July 2010 <http://modthemachine.typepad.com/files/vbatoaddins.pdf>.
3Mason, Matt. “Revit 2009 API: VSTA: Here Comes the Neighborhood.” Online posting. 28 Feb 2008. CAD Application Development. 26 July 2010 <http://cadappdev.blogspot.com/2008/02/revit-2009-api-vsta-here-comes.html>.
4Srivastava, Rahul. Customization of CAD Modeling Software using Parametric Macros for Design of Machinable Artistic Surface Patterns. Patiala: Thapar University, 2009. 27 July 2010 <http://dspace.thapar.edu:8080/dspace/bitstream/10266/1033/1/RAHUL+SRIVASTAVA+80781021-+2009.pdf>.
5Schoonmaker, Stephen J. The CAD Guidebook: A Basic Manual for Understanding and Improving Computer-Aided Design. New York: Marcel Dekker, 2003.
For more information about CAD services, please read more.