Creating a Polygon Sketch in VBA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I need to create a sketch of a polygon using VBA but I do not know the code to make the happen.
I would appreciate any help!
This is the code i have i changed the code that i had for a circle and tried to make it work for the polygon the problem should be in the area of the code that is double spaced out.
Public Sub hex()
Dim doc As PartDocument
Set doc = ThisApplication.ActiveDocument
Dim partD As PartComponentDefinition
Set partD = doc.ComponentDefinition
Dim dim1, dim2
dim1 = InputBox("Enter Radius of Cylinder", "Radius")
dim2 = InputBox("Enter Length of Cylinder", "Length")
Dim sketch As PlanarSketch
Set sketch = partD.Sketches.Add(partD.WorkPlanes.Item(3))
Dim tg As TransientGeometry
Set tg = ThisApplication.TransientGeometry
Dim hex As SketchPolygon
Set hex = sketch.SketchPolygons.AddByCenterRadius(ThisApplication.TransientGeometry.CreatePoint2d(0, 0), dim1)
'Creates a profile.
Dim Pfile As Profile
Set Pfile = sketch.Profiles.AddForSolid
'Create an extrusion.
Dim extrudeDef As ExtrudeDefinition
Set extrudeDef = partD.Features.ExtrudeFeatures.CreateExtrudeDefinition(Pfile, kJoinOperation)
Call extrudeDef.SetDistanceExtent(dim2, kNegativeExtentDirection)
Dim extrude As ExtrudeFeature
Set extrude = partD.Features.ExtrudeFeatures.Add(extrudeDef)
End Sub