6
Lecture 1
Creating a line
Dim swApp As Object
Dim Part As Object
Sub main()
S t swApp
Set
A
= A
Application.SldWorks
li ti
SldW k
Set Part = swApp.ActiveDoc
Part.CreateLine2 p1x, p1y, 0, p2x, p2y, 0
OR
Dim line1 As Object
Set line1 = Part.CreateLine2 (p1x, p1y, 0, p2x, p2y, 0)
End Sub
Lecture 6
Arc: CreateArcByCenter
retval = ModelDoc2.CreateArcByCenter ( p1x, p1y, p1z, p2x, p2y, p2z,
p3x, p3y, p3z )
This method creates an arc by center in this model document.
(
(double)
)
(double)
(double)
(double)
(double)
(double)
(double)
(double)
(double)
p
p1x
p1y
p1z
p2x
p2y
p2z
p3x
p3y
p3z
Lecture 6
Arc:CreateArc2
retval = ModelDoc2.CreateArc2 ( xc, yc, zc, xp1, yp1, zp1, xp2,
yp2, zp2, direction )
This method creates an arc based on a center point, a start, end
point, and a direction.
(double) xc
X value of the circle center point in meters
(double) yc
Y value of the circle center point in meters
(double) zc
Z value of the circle center point in meters
(double) xp1
X value of the start point of the arc in meters
(double) yp1
Y value of the start point of the arc in meters
(double) zp1
Z value of the start point of the arc in meters
(double) xp2
X value of the end point of the arc in meters
(double) yp2
Y value of the end point of the arc in meters
(double) zp2
Z value of the end point of the arc in meters
(short) direction
+1 : Go from the start point to the end point in a counter-clockwise
direction
-1 : Go from the start point to the end point in a clockwise direction
Lecture 6
Retval:LPDISPATCH
return pointer to the created object
line properties.swp
Lecture 6
Selection Set
retval = Part.Extension.SelectByID2
Part Extension SelectByID2 ( Name,
Name Type,
Type X,
X Y,
Y Z,
Z
Append, Mark, Callout, SelectOption )
This method selects the specified entity.
(BSTR) Name
Name of object to select or an empty string
(BSTR) Type
Type of object (uppercase) or an empty string
swSelNOTHING
swSelEDGES
S lEDGES
"EDGE
swSelFACES
"FACE
swSelVERTICES
"VERTEX
swSelDATUMPLANES
"PLANE
(double) XX
selection location or 0
(double) YY
selection location or 0
(double) ZZ
selection location or 0
Lecture 6
Selection Set
retval = Part.Extension.SelectByID2 ( Name, Type, X, Y, Z,
Append, Mark, Callout, SelectOption )
Use these value for other parameters
Append : FALSE
Mark
:0
Callout: Nothing
SelectOption: 0
Lecture 6
10
Type:
"SKETCHSEGMENT"
Lecture 6
11
Lecture 6
12
SKETCH ENTITY
Type: "SKETCHSEGMENT
Name: SketchArc,
k
h
SketchLine,
k
h
SketchEllipse,
k
h ll
SketchParabola, SketchSpline, user defined name
Lecture 6
13
Select line2 when name is line2 albeit the point on the line1
boolstatus = Part
Part.Extension.SelectByID2(
Extension SelectByID2("Line2"
Line2 ,
"SKETCHSEGMENT", 0, 0, -5, False, 0, Nothing, 0)
*Highest
g
p
priority:
y specific
p
name
Lecture 6
14
Lecture 6
15
Lecture 6
16
Plane 3p.swp
Lecture 6
17
Step 1 and 2
1
1.
S t the
Set
th 3D sketch
k t h
Part.Insert3DSketch2 True
2.
Lecture 6
18
Step 3
3 Insert the geometry plane
3.
a. Select the points
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("",
"EXTSKETCHPOINT", 0, 0, 0, True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("",
"EXTSKETCHPOINT"
EXTSKETCHPOINT , 10,
10 20,
20 0,
0 True,
True 0,
0 Nothing,
Nothing 0)
boolstatus = Part.Extension.SelectByID2("",
"EXTSKETCHPOINT", 40, 20, 30, True, 0, Nothing,
0)
Part.CreatePlaneThru3Points3 True
Lecture 6
19
Step 4
4 Activate
4.
A ti t the
th plane
l
boolstatus = Part
Part.Extension.SelectByID2(RefPlane,
Extension SelectByID2(RefPlane
"PLANE", 0, 0, 0, False, 0, Nothing, 0)
Part.SketchManager.InsertSketch True
Lecture 6
20