Browsed by
Tag: sketch

MidPlane Extrusion

MidPlane Extrusion

Compatible with WizoScript 3.00 and later.

Shows how to extrude from the mid-plane.

# create the part and then a sketch containing a circle
P = Part("Test")
S = P.AddSketch("Shape", P.GetPlane("XY-Plane"))
S.AddCircle(0, 0, 9, False)

# how far we will extrude from mid-plane
ExtrudeLength = 10

# extrude it
P.AddExtrudeBoss("Cyl", S, ExtrudeLength, False, Part.EndCondition.MidPlane, None, 0, Part.DirectionType.Normal, None, 0, False)
Wave Washer

Wave Washer

Compatible with WizoScript versions: 2.60

Generates wave washers. Uses a custom dialog window. Requires Geomagic Design V18 (2015.1.0) or later.

import math
from math import *
 
# radius
R = 100.0
# amplitude
A = 10.0
# number of waves (must be a whole number)
B = 4
 
# width
Width = 10
# thickness
Thickness = 5
 
Win = Windows()
 
Options = []
Options.append(["Radius", WindowsInputTypes.Real, R])
Options.append(["Amplitude", WindowsInputTypes.Real, A])
Options.append(["Number of Waves", WindowsInputTypes.Integer, B])
Options.append(["Width", WindowsInputTypes.Real, Width])
Options.append(["Thickness", WindowsInputTypes.Real, Thickness])
 
Values = Win.OptionsDialog("Wave Washer Generator", Options)
if Values == None:
  sys.exit()
 
R = Values[0]
A = Values[1]
B = Values[2]
Width = Values[3]
Thickness = Values[4]
 
# path accuracy = lower number = more points calculated
t_step = 0.1
 
# complete circle = PI x 2
t_max = 3.141592 * 2
 
# keep track of the total points we have calculated
TotalPoints = 0
 
# calculate points for 3D sketch
PathPoints = []
t = 0
while True:
  X = R * sin(t)
  Y = R * cos(t)
  Z = A * sin(B * t)
  PathPoints.extend([X, Y, Z])
  
  if TotalPoints == 0:
    P1 = [X, Y, Z]
  elif TotalPoints == 1:
    P2 = [X, Y, Z]
 
  t = t + t_step
  TotalPoints = TotalPoints + 1
  if t >= t_max:
    break
 
# close path
PathPoints.extend([PathPoints[0], PathPoints[1], PathPoints[2]])
 
# create part and add 3d sketch
P = Part("Wave Washer")
Path = P.Add3DSketch("Path")
Path.AddBspline(PathPoints)
 
# calculate normal vector for the plane at the start of the path
normal_vector = [P2[0] - P1[0], P2[1] - P1[1], P2[2] - P1[2]]
 
# create plane at the start of the path
Plane = P.AddPlane("Start Plane", normal_vector, P1)
 
CrossSection = P.AddSketch("Cross Section", Plane)
 
Origin = CrossSection.GlobaltoPoint(P1[0], P1[1], P1[2])
 
CrossSection.AddRectangle(Origin[0] - (Thickness / 2.0), Origin[1] - (Width / 2.0), Origin[0] + (Thickness / 2.0), Origin[1] + (Width / 2.0), False)
 
P.AddSweepBoss("Washer", CrossSection, Path, False, Part.EndCondition.EntirePath, None, 0, 0, False)
Polygon Incircle

Polygon Incircle

Compatible with WizoScript versions: 2.51

Polygons in Geomagic Design can be defined by an “exterior” or “interior” circle. The interior circle is typically used for bolt heads. The circle is called an “incircle”. This script shows how to draw a polygon by defining the incircle diameter.

import math
 
# diameter of circle that fits inside polygon
Diameter = 100
# number of sides
Sides = 6
 
# calculate exterior diameter of polygon
EDia = Diameter / math.cos(math.pi / Sides)
 
# create part, create polygon sketch, extrude
P = Part("Hex")
S = P.AddSketch("Hexagon", P.GetPlane("XY-Plane"))
S.AddPolygon(0, 0, EDia, Sides, False)
P.AddExtrudeBoss("Hex Head", S, 10, False)
Triangle

Triangle

Compatible with WizoScript versions: 2.51

Simple sketch of a triangle with angles 90, 15, 75 degrees.

# Create triangle with angles 90, 15, 75
 
import math
 
# set up parameters
Theta = 15.0
Adjacent = 100.0
 
# calculate side
Opposite = Adjacent * math.tan(math.radians(15.0))
 
# generate three vertices of triangle
P1_X = 0
P1_Y = 0
 
P2_X = Adjacent
P2_Y = 0
 
P3_X = Adjacent
P3_Y = Opposite
 
# create part and sketch
P = Part("Foo")
S = P.AddSketch("Shape", P.GetPlane("XY-Plane"))
 
# draw it
S.AddLine(P1_X, P1_Y, P2_X, P2_Y, False)
S.AddLine(P2_X, P2_Y, P3_X, P3_Y, False)
S.AddLine(P3_X, P3_Y, P1_X, P1_Y, False)
Everyone Loves a Slinky

Everyone Loves a Slinky

Compatible with WizoScript versions: 2.51

Demonstrates how to create a spiral spring. Uses a custom dialog window to get input parameters.

# Everyone Loves a Slinky
# Adapted from:
# http://forum.alibre.com/viewtopic.php?f=9&t=5752&p=30750&hilit=Spring#p30750
 
import sys
import math
 
# create dialog window
Win = Windows()
Options = []
Options.append(["Angle Increment", WindowsInputTypes.Real, 0.05])
Options.append(["Loop Scale", WindowsInputTypes.Real, 0.8])
Options.append(["Height Scale", WindowsInputTypes.Real, 1.0])
Options.append(["Major Helix Width Scale", WindowsInputTypes.Real, 2.0])
Options.append(["Turn Density", WindowsInputTypes.Integer, 25])
 
# show dialog window and get values
Values = Win.OptionsDialog("Everyone Loves a Slinky", Options)
if Values == None:
  sys.exit("User cancelled")
 
AngleIncrement = Values[0]
LoopScale = Values[1]
HeightScale = Values[2]
WidthScale = Values[3]
TurnDensity = Values[4]
print "Angle Increment = %f" % AngleIncrement
print "Loop Scale = %f" % LoopScale
print "Height Scale = %f" % HeightScale
print "Width Scale = %f" % WidthScale
print "Turn Density = %d" % TurnDensity
 
# create list of points for 3d sketch
Points = []
Angle = 0.0
for Pass in range(0, 437):
  X = (WidthScale + LoopScale * math.cos(Angle * TurnDensity)) * math.cos(Angle)
  Y = (WidthScale + LoopScale * math.cos(Angle * TurnDensity)) * math.sin(Angle)
  Z = HeightScale * Angle + LoopScale * math.sin(Angle * TurnDensity)
  Points.extend([X, Y, Z])
  Angle += AngleIncrement
 
# create part and add 3d sketch
Slinky = Part("Slinky")
Path = Slinky.Add3DSketch("Path")
Path.AddBspline(Points)
Creating a 3D Sketch Using a Spline and an Arc

Creating a 3D Sketch Using a Spline and an Arc

Compatible with WizoScript versions: 1.90

Shows how to create a 3D sketch that is comprised of a spline made of three points followed by an arc.

Units.Current = UnitTypes.Inches
 
P = Part("My Part")
 
# create 3d spline from a set of interpolation points
Path = P.Add3DSketch("Path")
Points = [0.6, -0.6625, 0.0]
Points.extend([0.6, -0.6625, -0.2175])
Points.extend([0.6, -0.8125, -0.6795])
Path.AddBspline(Points)
 
# arcs are counter clockwise, so to get a clockwise arc the start and end points are swapped
Path.AddArcCenterStartEnd(-5.6634, -3.92, -0.6795, 0.6, -7.0275, -0.6795, 0.6, -0.8125, -0.6795)
Scaling a Sketch

Scaling a Sketch

Compatible with WizoScript versions: 1.70

Creates a copy of a sketch and scales it to 50% in size

Units.Current = UnitTypes.Inches
 
TestRoom = Part("TEST ROOM Scaled", False)
OriginalSketch = TestRoom.GetSketch("Sketch<2>")
 
# currently 8.25" wide, need it to be 4.125"
ScaleFactor = 4.125 / 8.25 * 100.0
 
ScaledSketch = TestRoom.AddSketch("Scaled", TestRoom.GetFace("Face<6>"))
ScaledSketch.CopyFrom(OriginalSketch, 0, 0, 0, 0, 0, 0, 0, ScaleFactor)
Interactive Mobius Strip Generator

Interactive Mobius Strip Generator

Compatible with WizoScript versions: 1.70

Shows how to prompt the user for information and then use that information to manipulate a part that the user is already working on. Requires Geomagic Design V16 hotfix 1 (16.0.1.16490) or later.

# creates a mobius strip with a configurable number of rotations
 
print "Create a new part with a 2D sketch on the XY plane"
 
print "Enter name of part: "
PartName = Read()
 
Mobius = Part(PartName, False)
 
print "Enter name of sketch on XY plane: "
SketchName = Read()
 
print "Enter rotation point along X axis: "
Diameter = float(Read())
 
print "Enter number of rotations: "
Rotations = int(Read())
 
print "Enter number of steps: "
Steps = int(Read())
 
# calculate how far we rotate through 360 degrees for each step
RotationPerStep = Rotations / float(Steps) * 360.0
DegreesPerStep = 360.0 / Steps
 
# get the base sketch
S0Plane = Mobius.GetPlane("XY-Plane")
S0 = Mobius.GetSketch(SketchName)
 
Sketches = [S0]
 
# generate sketches
for Step in range (1, Steps):
  Plane = Mobius.AddPlane("S" + str(Step), S0Plane, Mobius.GetAxis("Y-Axis"), DegreesPerStep * Step)
  Sketch = Mobius.AddSketch("S" + str(Step), Plane)
  Sketch.CopyFrom(S0, RotationPerStep * Step, Diameter, 0, 0, 0, 0, 0, 100.0)
  Sketches.append(Sketch)
 
# the last sketch is the same as the first to form a complete loop
Sketches.append(Sketches[0])
 
# create loft
Mobius.AddLoftBoss("Strip", Sketches, False, False, False, False)
Lofting with Guide Curve

Lofting with Guide Curve

Compatible with WizoScript versions: 1.70

An example of creating a loft with a guide curve. This can easily be extended to use multiple curves. Requires Geomagic Design 16.0.1.16490 or later.

# create part
P = Part("foo")
 
# create sketch for bottom of loft
Bottom = P.AddSketch("Bottom", P.GetPlane("XY-Plane"))
Bottom.AddRectangle(0, 0, 10, 10, False)
 
# create sketch for top of loft
TopPlane = P.AddPlane("Top Plane", P.GetPlane("XY-Plane"), 30)
Top = P.AddSketch("Top", TopPlane)
Top.AddRectangle(0, 0, 50, 50, False)
 
# create guide curve
Guide = P.Add3DSketch("Guide")
Guide.AddBspline([10,10,0, 20,20,5, 45,45,15, 50,50,30])
 
# create loft using guide curve
P.AddLoftBoss("Loft Test", [Bottom, Top], [Guide], GuideCurveTypes.Global, True, False, False, False)
Calculating Length of Polylines

Calculating Length of Polylines

Compatible with WizoScript versions: 1.42

This example adds up the total lengths of all lines in a sketch in a part that is already open.

# Calculates the total length of all lines in a sketch
# This script assumes a part called 'Polyline' is already open
# and contains a single sketch called 'Sketch<1>' which has the lines
# to measure
 
Units.Current = UnitTypes.Millimeters
 
# get already opened part and then get sketch on part
P = Part("Polyline", False)
S = P.GetSketch("Sketch<1>")
 
# get total length of all lines in the sketch
TotalLength = 0
for Figure in S.Figures:
  if Figure.IsReference == False:
    TotalLength = TotalLength + Figure.Length
 
print "Total length of polyline = %.3f mm" % TotalLength