Hide Table of Contents

Get Sketch Spline Parameters Example (C++ COM)

This example shows how to get splines parameter data from sketches and how to unpack that data.

The method ISketch::IGetSplineParams2 returns an array, so this code must be used in an in-process DLL. Otherwise, use the method ISketch::GetSplineParams2 that returns a VARIANT.

 

// Union for use unpacking the data in the first two array elements for each spline

union SplinePackedData

{

 double doublevalue[2];

 int  intvalue[4];

};

void GetSketchSplines(LPSKETCH pSketch,CString* Message)

{

// Assume that pSketch has been set to a valid sketch already

 

 CString   Text;

 double*   pData;

 long   DataSize, NoSplines;

 

 // Get the spline parameters

 if(S_OK != pSketch->GetSplineParamsCount(&DataSize, &NoSplines) )return;

 

 if(NoSplines==0)

 {

  *Message += " Has no spline curves\r\n";

  return;

 }

 pData = (double*)malloc(sizeof(double) * DataSize);

 

 if(S_OK != pSketch->IGetSplineParams2(pData) )return;

 

 // Format the spline parameter data

 ExtractSplineData ( DataSize, pData, Message );

 

}

 

//////////////////////////////////////////////////////////////////////////

// Method: ExtractSplinesData

// Arguments: DataSize - Size of the array containing the splines parameters

//     pData - Data array containing splines parameters

// Return: Message - A CString for returning the formatted information

// Description:Extract the splines parameter data returned

//   from GetSplineParams and format it into a

//   string for display.

//////////////////////////////////////////////////////////////////////////

void CGetSketchesApp::ExtractSplinesData(int DataSize, double* pData, CString* Message)

{

 int     Index = 0;

 int     Dim;

 int     Order;

 int     nCtrlPoints;

 int     Periodic;

 int     nKnots;

 double    Knot;

 SplinePackedData* pPackedData;

 int     i,j;

 CString    Line;

 

// Continue until all the data is processed, i.e. 1 loop per spline

 while ( Index < DataSize )

 {

  // Unpack the information about the spline

  pPackedData = (SplinePackedData*)&pData[Index];

  Dim = pPackedData->intvalue[0];

  Order = pPackedData->intvalue[1];

  nCtrlPoints = pPackedData->intvalue[2];

  Periodic = pPackedData->intvalue[3];

  nKnots = Periodic ? nCtrlPoints+1 : nCtrlPoints+Order;

 

  // Format Text

  Line.Format(_T("Spline\r\nDimension %d\r\nNumControlPoints %d\r\n

Num of Knots %d\r\nPeriodic %d\r\n"),Dim, nCtrlPoints, nKnots, Periodic);

 

  *Message += Line;

 

  // Extract Control points

  Index+=2;    

  // Step past packed data

  for ( i=0; i<nCtrlPoints; i++ )

  {

   // Assume 3 dimensions

   double CtrlPoint[3];    

 

   for ( j=0; j<3; j++ )

   {

    CtrlPoint[j] = pData[Index++];

   }

 

   // Format text (in this case assume 3 dimensions)

   Line.Format(_T("Control Point: %lf %lf %lf\r\n"),

     CtrlPoint[0],

      CtrlPoint[1],

      CtrlPoint[2]);

   *Message += Line;

  }

 

  // Extract Knots

  for ( i=0; i<nKnots; i++ )

  {

   Knot = pData[Index++];

 

   // Format text

   Line.Format(_T("Knot: %lf\r\n"), Knot);

   *Message += Line;

  }

 }

}



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

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Get Sketch Spline Parameters Example (C++ COM)
*Comment:  
*   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:

x

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
x

Web Help Content Version: API Help (English only) 2023 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.