Hide Table of Contents

Create Equation-driven Curve Example (C#)

This example shows how to create and modify an equation-driven curve.

// Preconditions: 
// 1. Open a new part document.
// 2. Open the Immediate window.
// Postconditions:
// 1. Creates a 2D sketch and creates an equation-driven spline of
//    a sine curve.
// 2. Examine the graphics area, then Press F5.
// 3. Edits the curve and creates a cosine curve.
// 4. Reduces the number of points in the spline.
// 5. Examine the Immediate window and graphics area.
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
namespace SimplifySketchSpline_CSharp.csproj
partial class SolidWorksMacro

ModelDoc2 swModel;
ModelDocExtension swExt;
SelectionMgr swSelMgr;
bool boolstatus;
string y;
double r1;
double r2;
bool rad;
double ang;
double xOff;
double yOff;
bool LockStart;
bool LockEnd;

public void Main()
            swModel = (
            swExt = swModel.Extension;
            swSelMgr = (

            boolstatus = swExt.SelectByID2(
"Front Plane", "PLANE", 0, 0, 0, false, 0, null, 0);

SketchSegment skSegment = default(SketchSegment);
            skSegment = (
SketchSegment)swModel.SketchManager.CreateEquationSpline2("", "sin(x)", "", "0", "6.28", false, 0, 0, 0, true,

//Examine the graphics area, then press F5

SketchSpline skSpline = default(SketchSpline);
            skSpline = (
out y, out r1, out r2, out rad, out ang, out xOff, out yOff, out LockStart, out LockEnd);

Debug.Print("y: " + y);
Debug.Print("range start: " + r1);
Debug.Print("range end: " + r2);
Debug.Print("radian?: " + rad);
Debug.Print("ang offset: " + ang);
Debug.Print("x offset: " + xOff);
Debug.Print("y offset: " + yOff);
Debug.Print("lock start: " + LockStart);
Debug.Print("lock end: " + LockEnd);

// Change spline to a cosine curve
            y = "cos(x)";
            skSpline.SetEquationParameters(y, r1, r2, rad, ang, xOff, yOff, LockStart, LockEnd);

// Reduce the number of points in the spline



public SldWorks swApp;


Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

Subject:   Feedback on Help Topics
Page:   Create Equation-driven Curve Example (C#)
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:


We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again

Web Help Content Version: API Help (English only) 2016 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.