Re: SolidWorks VBA (Visual Basic for Applications) to work with dimensions
Sub CreateAndDimensionPart()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSketchMgr As SldWorks.SketchManager
Dim swSketch As SldWorks.Sketch
Dim swLine As SldWorks.SketchSegment
Dim swDimension As SldWorks.Dimension
' Create a new SolidWorks instance
Set swApp = CreateObject("SldWorks.Application")
' Create a new part document
Set swModel = swApp.NewDocument("C:PathToYourPartTemplate.prtdot", 0, 0, 0)
' Get the active sketch manager
Set swSketchMgr = swModel.SketchManager
' Create a new sketch
Set swSketch = swSketchMgr.AddSketch(swPlaneXY)
' Draw a line in the sketch
Set swLine = swSketch.CreateLine(0, 0, 0, 1, 0, 0)
' Add a dimension to the line
Set swDimension = swModel.Parameter("D1@Sketch1")
swDimension.SystemValue = 10 ' Set the dimension value
' Rebuild the part
swModel.ForceRebuild3 (False)
' Save the part
swModel.SaveAs3 "C:PathToYourNewPart.sldprt", 0, 2
' Close SolidWorks
swApp.ExitApp
End Sub