How To Model Gears With Vba User Form Tutorial v11
How To Model Gears With Vba User Form Tutorial v11
Alireza Reihani
Emmett Ross
1
Copyright Information
VB Scripting for CATIA V5: How to Model Gears with VBA User Form
All rights reserved. No part of this guide may be reproduced or transmitted in any form or by
any means, electronic or mechanical, including photocopying, recording, or by any information
storage and retrieval system, without permission in writing by the authors. The only exception
is by a reviewer, who may quote short excerpts in a review. CATIA is a registered trademark of
Dassault Systèmes. No affiliation with, or endorsed by anyone associated, or in any way
connected with Dassault Systèmes, Microsoft Corporation, UNIX, or any of their fantastic
products. We recognize that some words, model names and designations, for example,
mentioned herein are the property of the trademark owner. We use them for identification
purposes only. This is not an official publication.
Disclaimer
Although the authors have attempted to exhaustively research all sources to ensure the accuracy
and completeness of information on the subject matter, the authors assume no responsibility for
errors, inaccuracies, omissions, or any other inconsistencies herein. The data contained herein is
for informational purposes only and is not represented to be error free. Information may be
rendered inaccurate by changes made to the subject of the material, such as the applicable
software. No consequential damages can be sought against the authors for the use of these
materials by any third parties or for any direct or indirect result of that use. The purpose of this
text is to complement and supplement other texts and resources. You are urged to read all the
available literature, learn as much as you can and adapt the information to your particular needs.
There may be mistakes within this manual. Therefore, the text should only be used as a general
and introductory guide and not as the sole source for CATIA macro programming. The
information contained herein is intended to be of general interest to you and is provided “as is”,
and it does not address the circumstances of any particular individual or entity. Nothing herein
constitutes professional advice, nor does it constitute a comprehensive or complete statement of
the issues discussed thereto. Readers should also be aware that internet websites listed in this
work may have changed or disappeared between when this work was written and when it is read.
A prerequisite for this guide is to know the basics of CATIA, programming by Visual Basic, and
scratch, please read VB
VBScript for CATIA. To start learning programming for CATIA V5 from scratch,
SCRIPTING FOR CATIA V5 by
by Emmett Ross.
2
Contents
Copyright Information .................................................................................................................... 2
Disclaimer ....................................................................................................................................... 2
Introduction ....................................................................................................................................... 5
2-1-2) Get the Number of Gear Teeth and check its value .......................................................... 44
2-1-3)) Get the Module
2-1-3 Modul e of the Gear and check
che ck its value ....................................................
...............................................................
........... 45
2-1-4) Get the thickness of the gear and check its value ............................................................. 46
2-1-5) Get the Diameter of the Shaft Hole and check its value ................................................... 47
2-1-6) Get the width and depth of the Key and check their values ............................................. 48
2-1-7) Get the Chamfer Data and check its value ........................................................................ 49
2-1-9) Get the Scale of Diameter and check its value .................................................................. 51
2-1-10) Calculate the five Radiuses necessary to draw Gear Tooth ............................................ 52
2-1-11) Get the gear pressure angle and calculate the other angles to draw .............
....................
.............
.........
... 53
2-1-12) Control: shaft hole diameter must be smaller than Gear Dedendum ..........
................
.................. 54
............
2-1-13) Check: Width of Key must be smaller than Shaft hole Diameter .................................... 55
2-1-14) Check: Corner point of Key must be Inside of Gear Dedendum ..................................... 56
2-1-19) Find the intersection point on Addendum circle by Functions Xn,Yp .............
....................
.............
.........
... 61
3
2-1-23) Find the intersection point of the Dedendum circle and fillet circle .................
........................
.............
...... 65
2-5) Create Full Teeth Profile (Circular Pattern) and Join them .................................................. 81
4
Introduction
A good practice to take your CATIA programming skills to the next level is to model a complex
example like a gear. In this guide, you’ll learn how to develop a CATVBA program to model
In this case, step one is as important as step two, because there are many ways to model a gear
but some of them are not good and are inefficient. This is especially evident in Helical Gears
where sometimes they create errors in CATIA or the file size and/or time of creation is very high.
Before starting these two steps, let’s briefly review the structure of this program.
5
The UserForm consists of seven subroutine and two functions. At first, Subroutine common
creates Full Gear Profile, and then, depending on the Gear Type, one of four subroutines that
draws the desired gear type:
6
Initial Setting
This program creates Hybrid design (Planes, Points,…) in Body
Body and
and not in Geometrical Set,
Set, so it’s
necessary that you check Enable hybrid design when you want to create a new Part (Fig 3).
You can also change this setting by this method (Fig 4):
Tools>Options…>Infrastructure>PartInfrastru
Tools>Options…>Infrastructure>PartInfrastructure>Part
cture>Part Document (tab)>Hybrid Design:
Enable hybrid design inside part bodies and bodies
7
Step 1:
1: Drawing Gear Types in CATIA
Before starting a Sketch of the Tooth Profile (manually or by programming), it’s necessary to have
equations for drawing a gear tooth profile.
Beta
Ru
Rf Ro
Rt
Rd
Alpha Gamma
8
Note 1: Normally to draw a tooth profile, you must draw circles and lines, then trim them. This
can be very difficult to do by programming so use intersection points of two circles by these
equations:
equations:
( ) ( )
= ∗ 2 − 1 ± ℎ ∗ 2 − 1 + 1
= ∗ (2 − 1) ∓ ℎ ∗ (2 − 1) + 1
= � (1 − 2)2 + (1 − 2)2
12 − 22 + 2
= 2 ∗
ℎ = 12 − 2
where x,y are coordinates of intersection
intersection points, X1,Y1 are coordinates of center point of first
circle with radius=R1 and X2,Y2 are coordinates of center point of second circ
circle
le with radius=R2.
The fillets will also be drawn in sketch rather than using the fillet tool because it will be easier to
do programmatically.
In this guide, you will draw the Gear Sketch in a plane parallel to XZ plane. As a practice, you can
develop this program and then draw a gear in each plane.
9
10
For drawing full teeth profile, it doesn’t appear there is a VB function to have Circular Pattern in
Pattern in
Sketch ( ). Therefor
fore, we wil
illl use Circular patte
ttern in GSD ( ).
Fig 1-4: Full Teeth Profile and Create Pad for Gear Type 1
11
In type 2 (helical gear); after Translating of full teeth profile; it must be rotated (Fig. 1-5).
12
In type 3 (straight bevel); after Translating of full teeth profile; it must be scaled (Fig. 1-8).
13
In type 4 (spiral bevel); after Translating of full teeth profile; it must be rotated and be scaled. Do
it two times (Fig. 1-10).
Fig 1-10: Profile Translated, Rotated and Scaled in normal view (two times)
14
We have just created four different types of gear. Now it’s time to add automation so a user can
change the size of gears through a user form.
15
Fig 2-1-1: Form to get data for creating the gears to the specified size
16
17
If there is not a loaded CATVBA file, one message appears (Fig 2-1-3).
Press Yes to create one VBA project. Now Macro libraries window appears (Fig 2-1-4)
18
Click on Create new library... button (Library type must be VBA Project Fig 2-1-5). Now
Create a new VBA project window
window appears (Fig. 2-1-5). Enter a path and name for your VBA
project. (This path must be valid, otherwise an error message appears and CATIA doesn’t help
you to create these Folders.)
19
20
By clicking on Close button you will enter into the VBA environment (Fig 2-1-7)
21
To create a Form, Right click on the Project window (left side in Fig 2-1-7) then click on
Insert>UserForm (Fig 2-1-8) or use menu Insert>UserForm (Fig 2-1-9). New Form appears
(Fig 2-1-10).
22
23
To access to properties of this Form, click on menu View>Properties Window or press F4 or
24
25
To access CATIA when the Gear program is running, then set ShowModal property to False
(Fig 2-1-13). Forms are displayed by the Show method of the form object. This method has an
optional argument to specify whether the form should be displayed as either modal or
modeless. A modal form will not let you interact with any other part of the application until
that form is closed. This means that you cannot interactively use other CATIA commands or
interact with any other forms that might be displayed at the time. Forms are, by default, modal
unless otherwise specified. We want to interact with CATIA so set ShowModal property to
False.
Change the Caption property to 3D Gear (Fig 2-1-14). Finally, change the size of the Form (by
dragging of corners of Form or by setting width and Height property).
property).
26
To classify the controls such as TextBoxes, Labels,... , insert a Frame (Fig 2-1-15) by dragging
its icon on Toolbox window (Fig 2-1-16) to Form or by clicking on its icon and click a point on
Form. (If you don’t see this window click on menu: View>Toolbox or click on its icon in
Standard Toolbars )
27
28
29
30
To show the user that TextBox is a place to enter text, change MousePointer (Fig
(Fig 2-1-20) and
MouseIcon property of TextBox.
31
32
Change Font of TextBox and its Height to better viewing of texts by Font property
property of TextBox
(Fig 2-1-22).
33
Change BackStyle property of Label to 0 (Transparency) (Fig 2-1-23) now its color is
dependent of Frame color.
34
To show pictures, put image control and set its Picture property. Pictures should be in format
.bmp, .gif or .jpg. (Fig 2-1-24)
35
Each type of gear can have a shaft hole or not. If a shaft hole exists, it can have a key or not.
The best control for this purpose is to use a CheckBox (Fig 2-1-25). Put two CheckBoxes and
change their Name property to ChHole and ChKey. In MouseUp event of ChHole, write the
following code to control the key. Remember: the key can only exist when the shaft hole
exists.
ChKey.Value = False
ChKey.Enabled = False
Else
ChKey.Enabled = True
End If
End Sub
36
ChChamfer.Enabled = True
End Sub
ChChamfer.Enabled = True
End Sub
37
ChChamfer.Value = False
ChChamfer.Enabled = False
End Sub
ChChamfer.Value = False
ChChamfer.Enabled = False
End Sub
This program can draw four different types of gear but only one at a time can be select. Each
time one type is drawn and the user can select only one type so we need four OptionButtons.
You can add an image beside each optionButton to visually show the user what each type of
gear is.
38
We need a Command button to execute the create gear program. Add a new command button
and change the BackColor and
and ForeColor property (Black and white).
Continue adding controls and set their properties. After setting properties of a control, you can
use Copy-Paste to quickly create the other
o ther controls.
39
Fig 2-1-28 shows the Name property of controls that will be used in the VBA program
p rogram code.
ChHole
TxtKey
TxtKeyDep
Depth
th TxtKe
TxtKe Width
Width ChKeye
TxtZ
CmbM TxtShaftDiae
TxtAlpha
TxtT
TxtY O 4
O 1
O 3
O 2
TxtScale
TxtChX
TxtChY
ChChamfer
CmdDraw
Tx
TxtH
tHel
elix
ixAn
An le
40
To show the form of program, add a module to the project. A new module can be added just
like adding a form: right-click on the project window
wind ow and select Insert>Module (Fig 2-1-29).
41
Now add this code to your newly created module. This code will show the form when the
program is run.
Sub CATMain()
FrmGear.Show
End Sub
Later on you’ll learn how you can assign this module to an icon in CATIA to show the Form.
42
When the program runs, after clicking on Draw command button, the variable ProfileError is
is set
to false, a subroutines HidePlanes (to be explained later) and common will be executed.
ProfileError = Falsend
Call HidePlanes
Call Common
End Sub
Subroutine common gets the information from the form, analyzes it, creates the body and a plane
parallel to XZ plane and finally draws a full gear profile. After assigning the input information to
variables, they must be controlled. For example, if the teeth number, module or thickness is zero,
the program must alert the user to change
chan ge it. This is called error handling.
Sub Common()
Me.Hide
43
2-1-2) Get the Number of Gear Teeth and check its value
QtyZ = Val(TxtZ.Text)
Dim Z As Double
Z = CDbl(QtyZ)
FrmGear.Show
TxtZ.SetFocus
Exit Sub
End If
44
2-1-3) Get the Module of the Gear and check its value
m = Val(CmbM.Text)
If m = 0 Then
FrmGear.Show
CmbM.SetFocus
Exit Sub
End If
45
2-1-4) Get the thickness of the gear and check its value
t = Val(TxtT.Text)
If t = 0 Then
FrmGear.Show
TxtT.SetFocus
Exit Sub
End If
46
2-1-5) Get the Diameter of the Shaft Hole and check its value
SD = Val(TxtShaftDia.Text)
If SD = 0 Then
FrmGear.Show
TxtShaftDia.SetFocus
Exit Sub
End If
End If
47
2-1-6) Get the width and depth of the Key and check their values
KW = Val(TxtKeyWidth.Text)
If KW = 0 Then
FrmGear.Show
TxtKeyWidth.SetFocus
Exit Sub
End If
KD = Val(TxtKeyDepth.Text)
If KD = 0 Then
FrmGear.Show
TxtKeyDepth.SetFocus
Exit Sub
End If
End If
48
ChX = Val(TxtChX.Text)
If ChX = 0 Then
FrmGear.Show
TxtChX.SetFocus
Exit Sub
End If
ChY = Val(TxtChY.Text)
If ChY = 0 Then
FrmGear.Show
TxtChY.SetFocus
Exit Sub
End If
End If
49
HelixAngle = Val(TxtHelixAngle.Text)
50
Sc = Val(TxtScale.Text)
FrmGear.Show
TxtScale.SetFocus
Exit Sub
End If
51
Dim Rt As Double
Dim Ro As Double
Ro = m * Z / 2#
Rt = 0.94 * Ro
Rd = Ro - 1.25 * m
Ru = Ro + m
Rf = 0.35 * m
If Rd <= 0 Then
FrmGear.Show
TxtZ.SetFocus
Exit Sub
End If
52
2-1-11) Get the gear pressure angle and calculate the other angles to draw
Alpha = Val(TxtAlpha.Text)
Beta = 90 / Z
TotalAngle = 360 / Z
53
2-1-12) Control: shaft hole diameter must be smaller than Gear Dedendum
If SD >= Rd * 2 Then
FrmGear.Show
TxtShaftDia.SetFocus
Exit Sub
End If
End If
54
2-1-13) Check: Width of Key must be smaller than Shaft hole Diameter
If KW >= SD Then
FrmGear.Show
TxtKeyWidth.SetFocus
Exit Sub
End If
55
2)) ^ 2)
FrmGear.Show
TxtKeyDepth.SetFocus
Exit Sub
End If
End If
56
FrmGear.Show
TxtChY.SetFocus
Exit Sub
End If
FrmGear.Show
TxtChX.SetFocus
Exit Sub
End If
End If
57
Dim X0 As Double
Dim Y0 As Double
Dim Z0 As Double
X0 = 0
Y0 = Val(TxtY0.Text)
Z0 = 0
Dim H0 As Double
Dim V0 As Double
H0 = 0
V0 = 0
XPtOc1 = Rt * Cos(GamaRad)
YPtOc1 = Rt * Sin(GamaRad)
58
YPt1 = Ro * Cos(BetaRad)
59
Dim R1 As Double
60
61
FrmGear.Show
Exit Sub
End If
62
63
2-1-22) Find the intersection point of pitch circle and fillet circle
64
2-1-23) Find the intersection point of the Dedendum circle and fillet circle
FrmGear.Show
Exit Sub
End If
65
YPt5 = Rd * Cos(TetaRad)
66
FrmGear.Show
Exit Sub
End If
67
'File: Gear1~4.CATPart/Body.2
68
'Define ZX Plane
'File: Gear1~4.CATPart/Body.2/Plane.1
myBody.InsertHybridShape myPlaneY
myPart.Update
69
This sketch (like the sketch of Chamfer and Shaft Hole) is not fully defined. As a practice, you can
add constraints to the objects.
70
2-4-1) Find the Center points of circles and Start point and End point of Arcs
Use the Intersection points of the circles.
71
myPart.InWorkObject = mySketch
'File: Gear1~4.CATPart/Body.2/Sketch.1/Point.1
'File: Gear1~4.CATPart/Body.2/Sketch.1/Point.2
'File: Gear1~4.CATPart/Body.2/Sketch.1/Point.3
72
'File: Gear1~4.CATPart/Body.2/Sketch.1/Point.4
'File: Gear1~4.CATPart/Body.2/Sketch.1/Point.5
'File: Gear1~4.CATPart/Body.2/Sketch.1/Point.6
'File: Gear1~4.CATPart/Body.2/Sketch.1/Point.7
Circle1.CenterPoint = PtOc1
Circle1.StartPoint = Pt2
Circle1.EndPoint = Pt3
73
Circle2.CenterPoint = PtOc2
Circle2.StartPoint = Pt4
Circle2.EndPoint = Pt3
'File: Gear1~4.CATPart/Body.2/Sketch.1/Point.8
'File: Gear1~4.CATPart/Body.2/Sketch.1/Point.9
'File: Gear1~4.CATPart/Body.2/Sketch.1/Point.10
Circle1m.CenterPoint = PtOc1m
Circle1m.StartPoint = Pt3m
Circle1m.EndPoint = Pt2m
74
'File: Gear1~4.CATPart/Body.2/Sketch.1/Point.11
'File: Gear1~4.CATPart/Body.2/Sketch.1/Point.12
'File: Gear1~4.CATPart/Body.2/Sketch.1/Circle.4
Circle2m.CenterPoint = PtOc2m
Circle2m.StartPoint = Pt3m
Circle2m.EndPoint = Pt4m
'File: Gear1~4.CATPart/Body.2/Sketch.1/Point.13
'----------------------------------------------
'File: Gear1~4.CATPart/Body.2/Sketch.1/Circle.5
CircleU.CenterPoint = PtCtr
CircleU.StartPoint = Pt2m
CircleU.EndPoint = Pt2
75
'File: Gear1~4.CATPart/Body.2/Sketch.1/Circle.6
CircleD.CenterPoint = PtCtr
CircleD.StartPoint = Pt4
CircleD.EndPoint = Pt5
'File: Gear1~4.CATPart/Body.2/Sketch.1/Circle.7
Circle1Const.Construction = True
'File: Gear1~4.CATPart/Body.2/Sketch.1/Circle.8
Circle2Const.Construction = True
CircleUConst.Construction = True
CircleDConst.Construction = True
76
CircletConst.Construction = True
CircleOConst.Construction = True
Line1Const.Construction = True
Line2Const.Construction = True
'---------------------------------------------
mySketch.CloseEdition
myPart.InWorkObject = mySketch
myPart.Update
'-------------------------------------------------------
77
'File: Gear1~4.CATPart/Body.2/Join.1
myBody.InsertHybridShape myJoin
myPart.Update
Dim D As Double
Dim L As Double
Dim H As Double
Epsilon = 0.00001
L = (R1 ^ 2 - R2 ^ 2 + D ^ 2) / (2 * D)
ProfileError = True
Exit Function
End If
78
H = 0
Else
H = Sqr(R1 ^ 2 - L ^ 2)
End If
End Function
Dim D As Double
Dim L As Double
Dim H As Double
Epsilon = 0.00001
L = (R1 ^ 2 - R2 ^ 2 + D ^ 2) / (2 * D)
ProfileError = True
Exit Function
End If
79
H = 0
Else
H = Sqr(R1 ^ 2 - L ^ 2)
End If
End Function
80
2-5) Create Full Teeth Profile (Circular Pattern) and Join them
(Sub: common)
'File: Gear1~4.CATPart/Body.2/CircPattern.1
myCP1.CircularPatternParameters = catInstancesandAngularSpacing
angle1.Value = 360 / Z
81
intParam1.Value = Z + 1
Dim HS As HybridShapeFactory
Set HS = myPart.HybridShapeFactory
myCP1.SetRotationAxis RefYDir
myPart.Update
myBody.InsertHybridShape myJoin2
82
myPart.Update
HS.GSMVisibility RefmyJoin, 0
HS.GSMVisibility RefmyJoin2, 0
End If
End If
83
End If
End If
End If
End If
End If
84
'Create Pad
myPart.InWorkObject = myBody
myPart.Update
End Sub
85
(Sub: Gear2)
2-7-1) Translate and Rotate of first profile
'MULTI-SECTION
myPart.InWorkObject = myBody
Set HS = myPart.HybridShapeFactory
'File: Gear2.CATPart/Body.2/Translate.1
myTranslate1.ElemToTranslate = RefmyCP1
myTranslate1.VectorType = 0
86
myTranslate1.Direction = YDir
myTranslate1.DistanceValue = -t
myTranslate1.VolumeResult = False
myBody.InsertHybridShape myTranslate1
myPart.InWorkObject = myTranslate1
Set RefmyTranslate1 =
myPart.CreateReferenceFromObject(myTranslate1)
myPart.Update
'File: Gear2.CATPart/Body.2/Rotate.1
myRotate1.ElemToRotate = RefmyTranslate1
myRotate1.VolumeResult = False
myRotate1.RotationType = 0
myRotate1.Axis = RefYDir
myRotate1.AngleValue = HelixAngle
myBody.InsertHybridShape myRotate1
87
myPart.InWorkObject = myRotate1
HS.GSMVisibility RefmyTranslate1, 0
myPart.Update
myBody.InsertHybridShape myJoin3
myPart.Update
myPart.Update
Dim SF As ShapeFactory
Set SF = myPart.ShapeFactory
myPart.Update
HS.GSMVisibility RefmyJoin, 0
HS.GSMVisibility RefmyJoin2, 0
HS.GSMVisibility RefmyJoin3, 0
''''''''''''''
myPart.Update
End Sub
89
'---MULTI-SECTION
myPart.InWorkObject = myBody
Set HS = myPart.HybridShapeFactory
'File: Gear3.CATPart/Body.2/Translate.1
90
myTranslate1.ElemToTranslate = RefmyCP1
myTranslate1.VectorType = 0
myTranslate1.Direction = YDir
myTranslate1.DistanceValue = -t
myTranslate1.VolumeResult = False
myBody.InsertHybridShape myTranslate1
myPart.InWorkObject = myTranslate1
Set RefmyTranslate1 =
myPart.CreateReferenceFromObject(myTranslate1)
HS.GSMVisibility RefmyTranslate1, 0
myPart.Update
'File: Gear3.CATPart/Body.2/Point.1
myBody.InsertHybridShape PtCtr2
'File: Gear3.CATPart/Body.2/Scaling.1
myScaling1.VolumeResult = False
myBody.InsertHybridShape myScaling1
Set RefmyScaling1 =
myPart.CreateReferenceFromObject(myScaling1)
HS.GSMVisibility RefmyScaling1, 0
HS.GSMVisibility RefPtCtr2, 0
myBody.InsertHybridShape myJoin3
myPart.Update
92
myPart.Update
Dim SF As ShapeFactory
Set SF = myPart.ShapeFactory
myPart.Update
HS.GSMVisibility RefmyJoin, 0
HS.GSMVisibility RefmyJoin2, 0
HS.GSMVisibility RefmyJoin3, 0
'-------------------------------
myPart.Update
End Sub
94
'---MULTI-SECTION
myPart.InWorkObject = myBody
Set HS = myPart.HybridShapeFactory
'File: Gear4.CATPart/Body.2/Translate.1
myTranslate1.ElemToTranslate = RefmyCP1
myTranslate1.VectorType = 0
95
myTranslate1.Direction = YDir
myTranslate1.DistanceValue = -t / 2
myTranslate1.VolumeResult = False
myBody.InsertHybridShape myTranslate1
myPart.InWorkObject = myTranslate1
Set RefmyTranslate1 =
myPart.CreateReferenceFromObject(myTranslate1)
myPart.Update
'File: Gear4.CATPart/Body.2/Rotate.1
myRotate1.ElemToRotate = RefmyTranslate1
myRotate1.VolumeResult = False
myRotate1.RotationType = 0
myRotate1.Axis = RefYDir
myRotate1.AngleValue = HelixAngle
myBody.InsertHybridShape myRotate1
96
myPart.InWorkObject = myRotate1
HS.GSMVisibility RefmyTranslate1, 0
myPart.Update
HS.GSMVisibility RefmyRotate1, 0
'File: Gear4.CATPart/Body.2/Point.1
myBody.InsertHybridShape PtCtr2
'File: Gear4.CATPart/Body.2/Scaling.1
myScaling1.VolumeResult = False
myBody.InsertHybridShape myScaling1
Set RefmyScaling1 =
myPart.CreateReferenceFromObject(myScaling1)
97
HS.GSMVisibility RefmyScaling1, 0
HS.GSMVisibility RefPtCtr2, 0
myBody.InsertHybridShape myJoin3
myPart.Update
myPart.Update
'File: Gear4.CATPart/Body.2/Translate.2
myTranslate2.ElemToTranslate = RefmyCP1
myTranslate2.VectorType = 0
myTranslate2.Direction = YDir
myTranslate2.DistanceValue = -t
myTranslate2.VolumeResult = False
myBody.InsertHybridShape myTranslate2
myPart.InWorkObject = myTranslate2
98
Set RefmyTranslate2 =
myPart.CreateReferenceFromObject(myTranslate2)
myPart.Update
'File: Gear4.CATPart/Body.2/Rotate.2
myRotate2.ElemToRotate = RefmyTranslate2
myRotate2.VolumeResult = False
myRotate2.RotationType = 0
myRotate2.Axis = RefYDir
myRotate2.AngleValue = 3 * HelixAngle / 2
myBody.InsertHybridShape myRotate2
myPart.InWorkObject = myRotate2
HS.GSMVisibility RefmyTranslate2, 0
HS.GSMVisibility RefmyRotate2, 0
99
myPart.Update
'File: Gear4.CATPart/Body.2/Point.2
myBody.InsertHybridShape PtCtr3
myScaling2.VolumeResult = False
myBody.InsertHybridShape myScaling2
Set RefmyScaling2 =
myPart.CreateReferenceFromObject(myScaling2)
HS.GSMVisibility RefmyScaling2, 0
HS.GSMVisibility RefPtCtr3, 0
myBody.InsertHybridShape myJoin4
myPart.Update
myPart.Update
Dim SF As ShapeFactory
Set SF = myPart.ShapeFactory
myPart.Update
HS.GSMVisibility RefmyJoin, 0
HS.GSMVisibility RefmyJoin2, 0
HS.GSMVisibility RefmyJoin3, 0
HS.GSMVisibility RefmyJoin4, 0
'------------------------------------------------
myPart.Update
End Sub
102
'File: Gear1~4.CATPart/Body.2/Pocket.1/Sketch.2
myPart.InWorkObject = mySketchHole
103
XPt1Key = KW / 2
XPt2Key = KW / 2
YPt2Key = YPt1Key + KD
YPt3Key = YPt2Key
XPt4Key = -KW / 2
YPt4Key = YPt1Key
104
'File: Gear1~4.CATPart/Body.2/Pocket.1/Sketch.2/Point.1
'File: Gear1~4.CATPart/Body.2/Pocket.1/Sketch.2/Point.2
'File: Gear1~4.CATPart/Body.2/Pocket.1/Sketch.2/Point.3
'File: Gear1~4.CATPart/Body.2/Pocket.1/Sketch.2/Point.4
'File: Gear1~4.CATPart/Body.2/Pocket.1/Sketch.2/Line.1
Line12Key.StartPoint = Pt1Key
Line12Key.EndPoint = Pt2Key
'File: Gear1~4.CATPart/Body.2/Pocket.1/Sketch.2/Line.2
Line23Key.StartPoint = Pt2Key
Line23Key.EndPoint = Pt3Key
105
'File: Gear1~4.CATPart/Body.2/Pocket.1/Sketch.2/Line.3
Line34Key.StartPoint = Pt3Key
Line34Key.EndPoint = Pt4Key
'File: Gear1~4.CATPart/Body.2/Pocket.1/Sketch.2/Point.5
'File: Gear1~4.CATPart/Body.2/Pocket.1/Sketch.2/Circle.1
Else
End If
mySketchHole.CloseEdition
myPart.InWorkObject = mySketchHole
myPart.Update
myPart.Update
End Sub
106
Dim myPlaneYZ
'File: Gear1,2.CATPart/Body.2/Groove.1/Sketch.3
myPart.InWorkObject = mySketchChamfer
XPt1Ch = Y0 - ChX
YPt1Ch = Ru
XPt2Ch = Y0 + 0
YPt2Ch = Ru - ChY
XPt3Ch = Y0 + 0
YPt3Ch = Ru + 2
YPt11Ch = YPt1Ch
XPt22Ch = XPt2Ch - t
YPt22Ch = YPt2Ch
XPt33Ch = XPt3Ch - t
YPt33Ch = YPt3Ch
'File: Gear1,2.CATPart/Body.2/Groove.1/Sketch.3/Point.1
'File: Gear1,2.CATPart/Body.2/Groove.1/Sketch.3/Point.3
'File: Gear1,2.CATPart/Body.2/Groove.1/Sketch.3/Point.4
'File: Gear1,2.CATPart/Body.2/Groove.1/Sketch.3/Point.5
'File: Gear1,2.CATPart/Body.2/Groove.1/Sketch.3/Point.6
Line12Ch.StartPoint = Pt1Ch
Line12Ch.EndPoint = Pt2Ch
'File: Gear1,2.CATPart/Body.2/Groove.1/Sketch.3/Line.2
Line23Ch.StartPoint = Pt2Ch
Line23Ch.EndPoint = Pt3Ch
'File: Gear1,2.CATPart/Body.2/Groove.1/Sketch.3/Line.3
111
Line333Ch.StartPoint = Pt3Ch
Line333Ch.EndPoint = Pt33Ch
'File: Gear1,2.CATPart/Body.2/Groove.1/Sketch.3/Line.4
Line3322Ch.StartPoint = Pt33Ch
Line3322Ch.EndPoint = Pt22Ch
'File: Gear1,2.CATPart/Body.2/Groove.1/Sketch.3/Line.5
Line2211Ch.StartPoint = Pt22Ch
Line2211Ch.EndPoint = Pt11Ch
'File: Gear1,2.CATPart/Body.2/Groove.1/Sketch.3/Line.6
Line111Ch.StartPoint = Pt11Ch
Line111Ch.EndPoint = Pt1Ch
112
'File: Gear1,2.CATPart/Body.2/Groove.1/Sketch.3/Line.7
mySketchChamfer.CenterLine = CenterLine
mySketchChamfer.CloseEdition
myPart.InWorkObject = mySketchChamfer
myPart.Update
myPart.Update
End Sub
113
This subroutine just hides Planes XY, YZ and ZX for better viewing of Gears.
Sub HidePlanes()
Set HS = myPart.HybridShapeFactory
HS.GSMVisibility RefmyPlaneXY, 0
HS.GSMVisibility RefmyPlaneYZ, 0
HS.GSMVisibility RefmyPlaneZX, 0
myPart.Update
End Sub
114
As a last step, you can add an icon to a toolbar to quickly execute your program. Follow these
pictures to add an icon assigned to your VB program.
115
117
Thank You!
Now you know how to model and program gears in CATIA V5! You're on your way to automating
even more repetitive processes and impressing your co-workers and bosses. For more real world
examples, articles, tutorials, and how-to videos please visit
visit www.scripting4v5.com
www.scripting4v5.com
I hope you’ve enjoyed this program as much as we loved writing it for you. We really appreciate
each and every one of you for taking time out of your day or evening to read this, and if you have
we would
an extra second, we would love to hear what you think about it.
it. Please leave a comment or
forum post at http://www.scripting4v5.com
http://www.scripting4v5.com,, or if you’d rather reach us in private, don’t hesitate
to shoot us an email.
We’ve worked very hard on this guide and spent countless hours working on the website and
simply ask that you do not share this document with anyone who has not purchased it. Please
Video Demo
https://www.youtube.com/watch?v=Q7pERp0PfvI
119
If your code is not working, please double check these sections of code:
Confused or still stuck? Post your question in the forum if you get stuck or have any suggestions
for improving the tutorial.
http://www.scripting4v5.com/forums/forum/catia-macro-programming/
120
Appendix I: Keyboard
Keyboard Shor
Shortcuts
tcuts
CATIA V5:
VBA Editor:
Appendix II:
II: Resources
The following is a list of resources used when creating this tutorial and other recommended tools.
https://www.youtube.com/watch?v=dvyLuOPvMV8
https://www.youtube.com/watch?v=H989ooFHrxo
http://math.stackexchange.com/questions/256100/how-can-i-find-the-points-at-which-two-
circles-intersect
Types of gears:
http://sdp-si.com/resources/gears/pdf/gear_types_manufacturing.pdf