VBA3a Solidwork Sketch
-
Upload
sathishjey -
Category
Documents
-
view
230 -
download
0
Transcript of VBA3a Solidwork Sketch
7/26/2019 VBA3a Solidwork Sketch
http://slidepdf.com/reader/full/vba3a-solidwork-sketch 1/20
VBA with Sketch
Lecture 6 1Lecture 1
7/26/2019 VBA3a Solidwork Sketch
http://slidepdf.com/reader/full/vba3a-solidwork-sketch 2/20
Creating a lineDim swA As Ob ect
Dim Part As Object
Sub main()
e sw pp = pp ca on. or s
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
Condition: the sketch plane is already been set
Lecture 6 2
7/26/2019 VBA3a Solidwork Sketch
http://slidepdf.com/reader/full/vba3a-solidwork-sketch 3/20
What we are going to cover
n y o raw: arc, c rc e,
Selection set
Setting the sketch plane
Lecture 6 3
7/26/2019 VBA3a Solidwork Sketch
http://slidepdf.com/reader/full/vba3a-solidwork-sketch 4/20
Arc: CreateArcByCenter
retval = ModelDoc2.CreateArcB Center 1x 1 1z 2x 2 2zp3x, p3y, p3z )
This method creates an arc by center in this model document.
double 1x X coordinate for center oint in meters(double) p1y Y coordinate for center point in meters(double) p1z Z coordinate for center point in meters
(double) p2x X coordinate for start point in meters(double) p2y Y coordinate for start point in meters(double) p2z Z coordinate for start point in meters(double) p3x X coordinate for end point in meters(double) p3y Y coordinate for end point in meters(double) p3z Z coordinate for end point in meters
Output:(VARIANT_BOOL) retvalTRUE if successful, FALSE otherwise
boolstatus = Part.CreateArcByCenter(0, 0, 0, 5, 0, 0, -5, 0, 0)
Lecture 6 4
7/26/2019 VBA3a Solidwork Sketch
http://slidepdf.com/reader/full/vba3a-solidwork-sketch 5/20
7/26/2019 VBA3a Solidwork Sketch
http://slidepdf.com/reader/full/vba3a-solidwork-sketch 6/20
What is the difference?
return TRUE is the object successfully created andFALSE otherwise
Retval:LPDISPATCH
return pointer to the created object
Method to draw the arc using LPDISPATCH1. Part.CreateArc2 0, 0, 0, 5, 0, 0, -5, 0, 0, 1
2. Dim arc1 As ObjectSet arc1 = Part.CreateArc2(0, 0, 0, 5, 0, 0, -5, 0, 0, 1)
Lecture 6 6
7/26/2019 VBA3a Solidwork Sketch
http://slidepdf.com/reader/full/vba3a-solidwork-sketch 7/20
line properties.swp
What is the difference?
-. , , , , , , , , ,
Just draw the arc
Set arc1 = Part.CreateArc2(0, 0, 0, 5, 0, 0, -5, 0, 0, 1)
Draw the arc and name the arc as arc1. Therefore, we
etc
Properties can be changed
=
arc1.Width = 3
arc1.Style = 2
Lecture 6 7
7/26/2019 VBA3a Solidwork Sketch
http://slidepdf.com/reader/full/vba3a-solidwork-sketch 8/20
Other Create Sketch Entities
retval = ModelDoc2.CreateEllipse2 ( centerX, centerY,centerZ, majorX, majorY, majorZ, minorX, minorY,
Point retval = ModelDoc2.CreatePoint2 ( x, y, z )
Spline
retval = ModelDoc2.CreateSpline ( pointData )
*point data : array form
Lecture 6 8
7/26/2019 VBA3a Solidwork Sketch
http://slidepdf.com/reader/full/vba3a-solidwork-sketch 9/20
Selection Set
. . , , , , ,
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
swSelNOTHINGsw e
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 9
7/26/2019 VBA3a Solidwork Sketch
http://slidepdf.com/reader/full/vba3a-solidwork-sketch 10/20
=
Selection Set
Append, Mark, Callout, SelectOption )
Use these value for other parameters
Append : FALSE
Callout: Nothing
SelectOption: 0
Lecture 6 10
7/26/2019 VBA3a Solidwork Sketch
http://slidepdf.com/reader/full/vba3a-solidwork-sketch 11/20
Selection set: Name and Type
Name:
General line: SketchLineSpecific name: line1
Set line1 = Part.CreateLine2(0, 0, 0, 0, 10, 0)
Type:"SKETCHSEGMENT"
Lecture 6 11
7/26/2019 VBA3a Solidwork Sketch
http://slidepdf.com/reader/full/vba3a-solidwork-sketch 12/20
Selection set: coordinate
plane = . , , , , ,
‘Top plane
CS in selection set: global CSboolstatus = Part.Extension.SelectByID2(
e c ne, , , , - , a se, ,Nothing, 0)
Lecture 6 12
7/26/2019 VBA3a Solidwork Sketch
http://slidepdf.com/reader/full/vba3a-solidwork-sketch 13/20
Name and Type
Type: “PLANE”
Name: “To Plane” “Front Plane” “Ri ht Plane” “user defined name”, “” (empty name)
SKETCH ENTITY
Type: "SKETCHSEGMENT”
Name: S etc Arc, S etc Line, S etc E ipse,SketchParabola, SketchSpline, “user defined name”
Lecture 6 13
7/26/2019 VBA3a Solidwork Sketch
http://slidepdf.com/reader/full/vba3a-solidwork-sketch 14/20
Selection set line.swp
Selection Set Priority
‘
boolstatus = Part.Extension.SelectByID2(SketchLine,"SKETCHSEGMENT", 0, 0, -5, False, 0, Nothing, 0)
‘Select line1 when name line1 and the point on the line1
boolstatus = Part.Extension.SelectByID2("Line1","SKETCHSEGMENT" 0 0 -5 False 0 Nothin 0
‘Select line2 when name is line2 albeit the point on the line1
= " ". . ,"SKETCHSEGMENT", 0, 0, -5, False, 0, Nothing, 0)
*Hi hest riorit : s ecific name
Lecture 6 14
7/26/2019 VBA3a Solidwork Sketch
http://slidepdf.com/reader/full/vba3a-solidwork-sketch 15/20
Setting the 2D sketch plane
r ogona s e c s e c p ane
Select the plane: either front, top or right plane
Set the sketch plane
‘Set the to lane as sketch lane
boolstatus = Part.Extension.SelectByID2("Top Plane","PLANE", 0, 0, 0, False, 0, Nothing, 0)
. .
Lecture 6 15
7/26/2019 VBA3a Solidwork Sketch
http://slidepdf.com/reader/full/vba3a-solidwork-sketch 16/20
2D Sketch Plane: Face
boolstatus = Part.Extension.SelectByID2("","FACE", 1, 1, 0, False, 0, Nothing, 0)
Part.SketchManager.InsertSketch True
Lecture 6 16
7/26/2019 VBA3a Solidwork Sketch
http://slidepdf.com/reader/full/vba3a-solidwork-sketch 17/20
Plane 3p.swp
Non-orthogonal 2D sketch plane
roce ure us ng o or s
1. Set the sketch using 3DSketch
2. Draw the 3 points using x,y,z3. Insert the reference geometry plane
using the points
4. Activate the plane
Lecture 6 17
7/26/2019 VBA3a Solidwork Sketch
http://slidepdf.com/reader/full/vba3a-solidwork-sketch 18/20
Step 1 and 2
. e e s e c
Part.Insert3DSketch2 True
2. Draw the 3 pointsSet pt1 = Part.CreatePoint2(0, 0, 0)
Set pt2 = Part.CreatePoint2(10, 20, 0)
Set pt3 = Part.CreatePoint2(40, 20, 30)
Lecture 6 18
7/26/2019 VBA3a Solidwork Sketch
http://slidepdf.com/reader/full/vba3a-solidwork-sketch 19/20
Step 3
.
a. Select the pointsPart.ClearSelection2 Trueboolstatus = Part.Extension.SelectByID2("","EXTSKETCHPOINT", 0, 0, 0, True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2(""," ", , , , , , ,boolstatus = Part.Extension.SelectByID2("","EXTSKETCHPOINT", 40, 20, 30, True, 0, Nothing,
b. Draw the planePart.CreatePlaneThru3Points3 True
Lecture 6 19
7/26/2019 VBA3a Solidwork Sketch
http://slidepdf.com/reader/full/vba3a-solidwork-sketch 20/20
Step 4
. c va e e p ane
. . ,"PLANE", 0, 0, 0, False, 0, Nothing, 0)
Part.SketchManager.InsertSketch True
Lecture 6 20