AnsweredAssumed Answered

I am new to programming please help me i wrote a program for v block which by giving dimensions designs v block on its own

Question asked by Saikiran Srirambhatla on Apr 29, 2015
Latest reply on May 5, 2015 by Jay Donihoo

i attached my program here please correct my program

Private Sub CommandButton1_Click()

Dim swApp As Object

 

 

Dim Part As Object

Dim boolstatus As Boolean

Dim longstatus As Long, longwarnings As Long

 

 

Sub main()

 

 

Set swApp = _

Application.SldWorks

 

 

Set Part = swApp.ActiveDoc

boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)

Part.SketchManager.InsertSketch True

Part.ClearSelection2 True

Dim skSegment As Object

Set skSegment = Part.SketchManager.CreateLine(-0.083999, -0.057931, 0#, 0.097241, -0.057931, 0#)

Set skSegment = Part.SketchManager.CreateLine(0.097241, -0.057931, 0#, 0.097241, 0.048827, 0#)

Set skSegment = Part.SketchManager.CreateLine(0.097241, 0.048827, 0#, 0.088137, 0.048827, 0#)

Set skSegment = Part.SketchManager.CreateLine(0.088137, 0.048827, 0#, 0.041793, -0.033931, 0#)

Set skSegment = Part.SketchManager.CreateLine(0.041793, -0.033931, 0#, -0.020276, -0.033931, 0#)

Set skSegment = Part.SketchManager.CreateLine(-0.020276, -0.033931, 0#, -0.071586, 0.048827, 0#)

Set skSegment = Part.SketchManager.CreateLine(-0.071586, 0.048827, 0#, -0.083999, 0.048827, 0#)

Set skSegment = Part.SketchManager.CreateLine(-0.083999, 0.048827, 0#, -0.083999, -0.057931, 0#)

Part.ClearSelection2 True

Part.SetPickMode

boolstatus = Part.Extension.SelectByID2("Line1", "SKETCHSEGMENT", -0.031034257852077, -5.83444047619048E-02, 0, False, 0, Nothing, 0)

Dim myDisplayDim As Object

Set myDisplayDim = Part.AddDimension2(-2.85515172239108E-02, -7.98614902060115E-02, 0)

Part.ClearSelection2 True

Dim myDimension As Object

Set myDimension = Part.Parameter("D1@Sketch1")

myDimension.SystemValue = TextBox1.Value / 1000

boolstatus = Part.Extension.SelectByID2("Point7", "SKETCHPOINT", -7.15856881121243E-02, 4.88272323539345E-02, 0, False, 0, Nothing, 0)

boolstatus = Part.Extension.SelectByID2("Point4", "SKETCHPOINT", 8.81372922998987E-02, 4.88272323539345E-02, 0, True, 0, Nothing, 0)

Set myDisplayDim = Part.AddDimension2(7.52465938892025E-02, 5.39403354766828E-02, 0)

boolstatus = Part.Extension.SelectByID2("D1@Sketch1@Part1.SLDPRT", "DIMENSION", 0, 0, 0, False, 0, Nothing, 0)

Part.ClearSelection2 True

Set myDimension = Part.Parameter("D2@Sketch1")

myDimension.SystemValue = TextBox2.Value / 1000

boolstatus = Part.Extension.SelectByID2("Line7", "SKETCHSEGMENT", -7.80276122658087E-02, 4.91654896991768E-02, 0, False, 0, Nothing, 0)

Set myDisplayDim = Part.AddDimension2(-7.77581071437855E-02, 0.066413817508659, 0)

boolstatus = Part.Extension.SelectByID2("D2@Sketch1@Part1.SLDPRT", "DIMENSION", 0, 0, 0, False, 0, Nothing, 0)

Part.ClearSelection2 True

Set myDimension = Part.Parameter("D3@Sketch1")

myDimension.SystemValue = TextBox3.Value / 1000

Part.ClearSelection2 True

boolstatus = Part.Extension.SelectByID2("Line3", "SKETCHSEGMENT", 9.09501179352416E-02, 4.95129105965846E-02, 0, False, 0, Nothing, 0)

Set myDisplayDim = Part.AddDimension2(9.63656239296345E-02, 7.14328158119844E-02, 0)

Part.ClearSelection2 True

Set myDimension = Part.Parameter("D4@Sketch1")

myDimension.SystemValue = TextBox4.Value / 1000

boolstatus = Part.Extension.SelectByID2("Line5", "SKETCHSEGMENT", 7.72551305096969E-03, -3.44094342691546E-02, 0, False, 0, Nothing, 0)

Set myDisplayDim = Part.AddDimension2(0.193302562314296, -4.74999315200947E-02, 0)

boolstatus = Part.Extension.SelectByID2("D4@Sketch1@Part1.SLDPRT", "DIMENSION", 0, 0, 0, False, 0, Nothing, 0)

Part.ClearSelection2 True

Set myDimension = Part.Parameter("D5@Sketch1")

myDimension.SystemValue = TextBox5.Value / 1000

Part.ClearSelection2 True

boolstatus = Part.Extension.SelectByID2("Line6", "SKETCHSEGMENT", -4.15563589525694E-02, 1.01191123338906E-03, 0, False, 0, Nothing, 0)

boolstatus = Part.Extension.SelectByID2("Line4", "SKETCHSEGMENT", 5.31572388042322E-02, 5.63208673372084E-03, 0, True, 0, Nothing, 0)

Part.SketchAddConstraints "sgSAMELENGTH"

Part.ClearSelection2 True

boolstatus = Part.Extension.SelectByID2("Line5", "SKETCHSEGMENT", -6.13501345002576E-03, -3.51794635192099E-02, 0, False, 0, Nothing, 0)

boolstatus = Part.Extension.SelectByID2("Point8", "SKETCHPOINT", -8.62757014543012E-02, 4.95771926425102E-02, 0, True, 0, Nothing, 0)

Set myDisplayDim = Part.AddDimension2(-0.130879751958984, 3.79733152360433E-02, 0)

Part.ClearSelection2 True

Set myDimension = Part.Parameter("D6@Sketch1")

myDimension.SystemValue = TextBox6.Value / 1000

Part.ClearSelection2 True

boolstatus = Part.Extension.SelectByID2("Line8", "SKETCHSEGMENT", -9.00682017060531E-02, -7.45841051721924E-03, 0, False, 0, Nothing, 0)

Set myDisplayDim = Part.AddDimension2(-0.176311477712246, -1.29817651677683E-03, 0)

Part.ClearSelection2 True

Set myDimension = Part.Parameter("D7@Sketch1")

myDimension.SystemValue = TextBox7.Value / 1000

Part.ClearSelection2 True

Part.ShowNamedView2 "*Trimetric", 8

Part.ClearSelection2 True

Dim myFeature As Object

Set myFeature = Part.FeatureManager.FeatureExtrusion2(True, False, False, 6, 0, TextBox8.Value / 1000, 0.01, False, False, False, False, 1.74532925199433E-02, 1.74532925199433E-02, False, False, False, False, True, True, True, 0, 0, False)

Part.SelectionManager.EnableContourSelection = False

End Sub

Outcomes