Thursday, December 10, 2009

Overview On Recording Macro Using SolidWorks


Overview On Recording Macro

I thought of writing on SolidWorks customization since July on few of my friends demand, but never made it due to tight working schedules. December like wise it my favorite month with lot of rest!

So coming to you. First lets go with fundamentals of API programming.

Application Programming Interface (API) is used to automate redundant and lengthy design tasks using SolidWorks. One can create complete engineering application that runs inside or outside of SolidWorks application. So starting with basics of customization will help professionals as well as students developing fundamental skills.

Many times, it happens that Mechanical engineers are not aware about programming languages. Just having CAD designing knowledge is not enough, hence before we proceed I suggest Mechanical engineers to learn LISP, C, VB and if possible .NET. LISP is very easy language and lot of online help is available for one to learn. It helps to build good foundation of your programming skills.

Getting started

There are few things a programmer should note before recording a macro in SolidWorks or writing an application in VB that connects to SolidWorks.

File Type: SW VBA Macros (*.swp)

Option Explicit: It is recommended that you use "Option Explicit" statement in VB development. By doing so, the Visual Basic compiler forces you to declare of all variables before use.

Variable deceleration: Variables are used to store temporary values and are made up of two parts 'Name' and 'Data Type' Variable is declare with the Dim statement.

e.g. Dim variablename [As data type]

Option “As data type” allows you to define the data type or object type of the variable.

Data Types: Visual basic supports these standard types of data

· String - Holds characters

· Integer – Holds numeric values

· Long Integer – Holds numeric values with higher values

· Single precision – Holds numeric value with decimal points

· Double precision - Holds numeric value with decimal points, accurate to sixteen digits

· Decimal – For large numbers

· Date – Holds date, time values

· Byte – holds integer value

· Boolean – Holds values either True or False

· Variant – Holds all data types

· Object

NOTE: All APIs use meters and radians for length and angle units

You need to include SolidWorks Constant type library to each project, for whatever version you are using. But if record a macro using the VBA environment in SolidWorks the type library will be automatically included.

Starting Point

Recording a macro is best way to know basic functionality. Consider following tips while recording a macro.

· Use macro recording for small applications. Record few steps at a time

· Plan steps before recording a macro

· Limit the number of view changes you make while recording

· Remove unnecessary calls (that we will discuss later)

· Look for help topics, tutorials included with SolidWorks

Next session I will cover “Using Macro Recorder”

Bye,

Happy daily cadding

Sachin Nalawade

1 comment:

Rajeev Lochan said...

Good one Sachin..
Try to add some screenshots from next article, so that users can grasp better.

Regards,
Rajeev Lochan
http://www.smallguru.com