No Fear! (of Programming)
Written by Paul Gimbel
Whether it’s automating something in SolidWorks, adding functionality to your PLM implementation or increasing the computing power and flexibility of an automated process, we engineers frequently stop short of programming. Why is that? Now I admit, I cannot write a product like DriveWorks or SolidWorks EPDM (then again, I never tried). Even though I don’t have a Linux penguin sticker on my car or a shirt with the caffeine molecule on it, I’m not scared of the code (granted, I also won’t be putting that “No Fear” sticker on my car either).
“Oh wow,” you’re thinking, “if he can do it, it can’t be that hard.” Well first of all, thanks for the vote of confidence, and second of all, no, it’s not that hard. The first thing that converts most people (from being code-fearful to code-confident) is the realization that there is no reason to write code, ever. Step one in coding (aside from writing a spec if you’re a consultant) is to obtain the code that you need. Google, Bing, or your favorite search engine will yield tons of free code snippets. Simply develop a nice description of what you want and include the language you want it in, and the results will speak for themselves. Other code sources (sorry for the pun) are out there as well, including SourceForge and Krugle . It’s like Hollywood. It’s all been done before. You just need to take the parts you want and leave the parts you don’t want.
So it’s not a matter of writing code. It’s a matter of tinkering to figure out how it works. If you’re an engineer, tinkering is second nature and a primary complaint of those who live with you. Programming environments from the VBA editors within Excel and SolidWorks to the powerhouse of Visual Studio have a host of tools to help you tinker. Stepping tools allow you to walk line by line through the code to understand how it flows. Real-time “watches” allow you to hover over variables to see the current value (as a tooltip). Watches allow you to see the values of multiple values as they change during code execution. The immediate window allows you to ask questions and test things … well, immediately. Breakpoints allow you to spin through the parts that you understand and stop right where you want to watch.
The biggest impediment to basic coding is the syntax. There are so many dots and bangs and underscores and apostrophes and #s (whatever they call those). How can you know when to use what? The Help file inside of your development environment is very helpful in this regard. I know, I was shocked, too. They not only explain each command and show you all of the options and syntax, but they quite often include sample code that can save you a trip to the browser window. But if you like your IE or Firefox, you can go there as well. There are almost as many free programming lessons online as there are sites that you should not access from your work PC. One great site is from Microsoft, the MSDN (Microsoft Developer Network).
OK, but what if you don’t know the command to look it up? Well that’s one of the great additions that object-oriented programming (or even VBA’s attempt at it) brings to the party. When you’re working in Excel or SolidWorks or anyone’s API, you’re using their objects. These objects have properties (attributes about the object), methods (actions the object can perform), and sometimes, events (things that happen to the object that can cause additional code to fire), and that’s pretty much all you can do with the object. Finding out what each object can do is as simple as using the Object Browser, or simply starting to type. Put a period after the object variable (that’s the syntax for a property, method, or event) and your environment will kick in the Intellisense and provide you a list with all of your options. Pick the one you want, and Intellisense shows you all of the parameters that you’re supposed to provide and the type for each.
Now you’re sold on programming, but can you sell your boss on the tools that you need? Well actually, I think that you can. A great place to start learning to program is inside of VBA (an antiquated version of Visual Basic that is still used in MS Office applications and SolidWorks macros). VBA development environments are built into all MS Office products (Excel, Word, Access, etc.) and into SolidWorks as well. Want to learn or use a language from this millennium? Then you can get into the .NET framework with Visual Basic or C# or C++ or even a Web environment. And the total bill…free. Microsoft has its Express series of products to get you hooked on programming so that you will buy the full suite, but oddly enough, they’re practically full-featured so most people have no reason to upgrade.
So that’s it! No more excuses. No more fear. No more deferring to outside resources (except Razorleaf, of course). You can do this. You can start coding. All you need is a project and a diversion so your boss won’t see you doing it. Contact us and we can help you at least come up with the first part.
Tags: .NET, API, DriveWorks, object browser, programming, VBA, Visual Studio.NET
Read more posts by Paul Gimbel





