This website uses cookies to ensure you get the best experience on our website. By using our website you agree on the following Cookie Policy, Privacy Policy, and Terms Of Use
SOLIDWORKS allows to insert the free form curve through XYZ coordinates from the external text file. This file however is not linked to the feature itself and the curve is not updated when external file changes.
This VBA macro allow to automatically link the external file with coordinates and update the selected curve with single click.
Example of curve file:
0mm 0mm 0mm
10mm 10mm 10mm
5mm 1mm 25mm
Curve text file must be saved in the same folder where the SOLIDWORKS file is saved and must be named as [Model Title]_[Feature Name].sldcrv. For example if curve feature is named Curve1 and resides in the SOLIDWORKS file named Part1.sldprt, the curve text file must be named Part1_Curve1.sldcrv.
Dim swApp As SldWorks.SldWorks
Sub main()
Set swApp = Application.SldWorks
Dim swModel As SldWorks.ModelDoc2
Set swModel = swApp.ActiveDoc
IfNot swModel IsNothingThenDim swFeat As SldWorks.Feature
Set swFeat = swModel.SelectionManager.GetSelectedObject6(1, -1)
IfNot swFeat IsNothingThenDim swCurveFeatDef As SldWorks.FreePointCurveFeatureData
Set swCurveFeatDef = swFeat.GetDefinition
IfNot swCurveFeatDef IsNothingThenDim filePath AsString
filePath = swModel.GetPathName
filePath = Left(filePath, InStrRev(filePath, ".") - 1)
filePath = filePath & "_" & swFeat.Name & ".sldcrv"IfFalse = swCurveFeatDef.LoadPointsFromFile(filePath) Then
MsgBox "Failed to update curve"EndIf
swFeat.ModifyDefinition swCurveFeatDef, swModel, NothingElse
MsgBox "Selected feature is not XYZ points curve"EndIfElse
MsgBox "Please select Curve XYZ feature"EndIfElse
MsgBox "Please open model"EndIfEndSub