Introduction

This tutorial demonstrates how to create a library of parts in a CAD neutral format based on a single template part. It takes advantage of parameterization in Geomagic Design.

We will start by creating the base part that we will use to create the library. This will be a simple cap head bolt.

Next we will use WizoScript to generate a library of 10 bolts of different lengths.

This type of task is ideally suited to scripting because it handles the tedious repetitive operations needed. While the part demonstrated in this tutorial is simple the same principles can easily be used for complex parts with multiple parameters.

Creating the Template Part

In Geomagic Design create a new part and then a sketch on the XY-Plane. On this sketch draw a circle centered on the origin with a diameter of 4mm and then extrude into a cylinder with a length of 10mm.

Under the Viewing and Analysis tab click on the Equation Editor button.

Double-click on “D2” and enter “Length” to give the length of the bolt a useful name then close the equation editor window.

Create the bolt head by adding a sketch to the end of the cylinder on the XY-Plane, setting the diameter to 8mm and extruding 4mm.

Create a new sketch on the top of the bolt head, draw a hexagon with an inside diameter of 4mm and then extrude cut 2mm.

Create a new folder called “PartLibrary” and save as TemplatePart.AD_PRT. Keep the part open in Geomagic to continue with the tutorial.

Writing a Basic Script

Start WizoScript 1.70 or later. When it runs it automatically creates an empty script that we can start using right away.

First we need to tell the script about our template part. For this tutorial the part must be open in Geomagic when the script runs, however it is possible to use a saved part that is not currently open. Please see the WizoScript reference manual for further details.

The following script line tells WizoScript “I have a part open and I want you to use it”:

TemplatePart = Part(“TemplatePart”, False)

Next we need to get access to the length parameter that we have already created it. Once we have access to it we can change its value

Length = TemplatePart.GetParameter("Length")

The default units for a script are millimeters, so if we enter the following:

Length.Value = 10

Then we are setting the length of the bolt to 10mm. Enter this into the script.

Now that we have set the length of the bolt we need to export it in a CAD-neutral formal so it can be shared with others. Here is how to do it:

TemplatePart.ExportSTEP214("C:\Users\Andy\Desktop\M4-Bolt-10")

This is what you should have so far:

Save the script and click on the Run button. If there are any errors correct them in the script and try again. If the script is successful you should now have a M4-Bolt-10.stp file.

Generating Multiple Parts

So far it’s not very interesting. We’ve generated a single STEP part that we could have easily created directly in Geomagic Design without needing scripting. Now we will look at generating multiple parts in one go.

The first step is to create a function that is given a length and creates a STEP file. A function is a way of grouping parts of a script together so they can be run over and over again. Edit your script to look like the following:

def GenerateBolt(NewLength):
  Length.Value = NewLength
  TemplatePart.ExportSTEP214("C:\Users\Andy\Desktop\M4-Bolt-"+str(NewLength))

TemplatePart = Part("TemplatePart", False)

Length = TemplatePart.GetParameter("Length")

GenerateBolt(10)
GenerateBolt(12)

We now have a function called GenerateBolt that takes a length and creates a STEP file. The function has to be defined before it is used so put it at the start of the script.

Another key change is that the name of the STEP file contains the length, whatever that may be. This is achieved by appending “M4-Bolt-“ with the length value.

Run the script. It will call GenerateBolt twice and create two STEP files containing a 10mm bolt and a 12mm bolt.

The final step is to create a loop that goes from a minimum length to a maximum length creating bolts. Replace the two calls to GenerateBolt with the following:

MinimumLength = 10
MaximumLength = 20
for NewLength in range(MinimumLength, MaximumLength + 1):
  GenerateBolt(NewLength)

Run the script and it will generate bolts with lengths from 10mm to 20mm.

Here is the final script with comments added to explain:

# Takes a template bolt and creates a library of bolts of different lengths in
# a CAD neutral format

# Creates a bolt of a specific length. NewLength = desired length of bolt in mm
# Saves the bolt to the desktop as a STEP file
def GenerateBolt(NewLength):
  Length.Value = NewLength
  TemplatePart.ExportSTEP214("C:\Users\Andy\Desktop\M4-Bolt-" + str(NewLength))

# Get access to currently opened part that we will used as a template
TemplatePart = Part("TemplatePart", False)

# The template part has a Length parameter defined which we will control
Length = TemplatePart.GetParameter("Length")

# Create bolts from 10mm to 20mm
MinimumLength = 10
MaximumLength = 20
for NewLength in range(MinimumLength, MaximumLength + 1):
  GenerateBolt(NewLength)