Hide Table of Contents

Get B-Spline Surface Parameterization Data Example (C#)

This example shows how to get B-spline parameterization data for a selected face or surface.

//---------------------------------------------------------------------------
// Preconditions:
// 1.  Open <SolidWorks_install_dir>\samples\tutorial\molds\telephone.sldprt.
// 2.  Select a face in the graphics area.
// 3.  Open an Immediate Window.
//
// Postconditions:
//  View the following parameterization data about the selected surface

//  in the Immediate Window:
//
//  * U minimum
//  * U maximum
//  * V minimum
//  * V maximum
//  * Boundary behaviors at U minimum, U maximum, V minimum, V maximum

//    are as defined in swBoundType_e
//  * # of U and V properties
//  * U and V parameter properties as defined in swParameterizationPropertyType_e
//  * U order
//  * V order
//  * # control point columns
//  * # control point rows
//  * Control point dimension:
//       3 - non-rational surfaces
//       4 - rational surfaces (weighted control points)
//  * U periodicity
//  * V periodicity
//  * Knot vector in the U direction
//   (# knots = (control point column count) + (U order))
//  * Knot vector in the V direction
//   (# knots = (control point row count) + (V order))
//  * Control point at row=2 and column=3 of the control point matrix
//--------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Diagnostics;
namespace MacroBSurf_CSharp.csproj
{
    
partial class SolidWorksMacro
    {

        
public void Main()
        {

            
ModelDoc2 swModel = default(ModelDoc2);
            
SelectionMgr swSelMgr = default(SelectionMgr);
            
Face2 swFace = default(Face2);
            
Surface swSurf = default(Surface);
            
SurfaceParameterizationData swSurfParam = default(SurfaceParameterizationData);
            
BSurfParamData swBSurfParam = default(BSurfParamData);
            
bool sense = false;
            
object UKnots = null;
            
object VKnots = null;
            
object vCtrlPts = null;
            
int i = 0;

            swModel = (
ModelDoc2)swApp.ActiveDoc;
            swSelMgr = (
SelectionMgr)swModel.SelectionManager;
            swFace = (
Face2)swSelMgr.GetSelectedObject5(1);
            swSurf = (
Surface)swFace.GetSurface();
            swSurfParam = (
SurfaceParameterizationData)swSurf.Parameterization2();
            
Debug.Print("File = " + swModel.GetPathName());
            
Debug.Print(" Surface:");
            
Debug.Print(" U minimum is: " + swSurfParam.UMin);
            
Debug.Print(" U minimum bound type is: " + swSurfParam.UMinBoundType);
            
Debug.Print(" U maximum is: " + swSurfParam.UMax);
            
Debug.Print(" U maximum bound type is: " + swSurfParam.UMaxBoundType);
            
Debug.Print(" U property count is: " + swSurfParam.UPropertyNumber);
            
object varUProperties = null;
            
int[] uProperties;
            varUProperties = swSurfParam.UProperties;
            uProperties = (
int[])varUProperties;
            
Debug.Print(" U properties: ");
            
for (i = 0; i <= uProperties.GetUpperBound(0); i++)
            {
                
Debug.Print(" " + uProperties[i]);
            }

            
Debug.Print(" V minimum is: " + swSurfParam.VMin);
            
Debug.Print(" V minimum bound type is: " + swSurfParam.VMinBoundType);
            
Debug.Print(" V maximum is: " + swSurfParam.VMax);
            
Debug.Print(" V maximum bound type is: " + swSurfParam.VMaxBoundType);
            
Debug.Print(" V property count is: " + swSurfParam.VPropertyNumber);
            
object varVProperties = null;
            
int[] vProperties;
            varVProperties = swSurfParam.VProperties;
            vProperties = (
int[])varVProperties;
            
Debug.Print(" V properties: ");
            
for (i = 0; i <= vProperties.GetUpperBound(0); i++)
            {
                
Debug.Print(" " + vProperties[i]);
            }

            swBSurfParam = (
BSurfParamData)swSurf.GetBSurfParams3(false, false, swSurfParam, 0.01, out sense);

            
Debug.Print("U order is: " + swBSurfParam.UOrder);
            
Debug.Print("V order is: " + swBSurfParam.VOrder);
            
Debug.Print(" Control point column count is: " + swBSurfParam.ControlPointColumnCount);
            
Debug.Print(" Control point row count is: " + swBSurfParam.ControlPointRowCount);
            
Debug.Print(" Control point dimension is: " + swBSurfParam.ControlPointDimension);
            
Debug.Print(" U periodicity is: " + swBSurfParam.UPeriodicity);
            
Debug.Print(" V periodicity is: " + swBSurfParam.VPeriodicity);

            UKnots = swBSurfParam.UKnots;
            
double[] uknots;
            uknots = (
double[])UKnots;
            
Debug.Print("Knot vector in the U direction: ");
            
for (i = 0; i <= uknots.GetUpperBound(0); i++)
            {
                
Debug.Print(uknots[i].ToString());
            }
            VKnots = swBSurfParam.VKnots;
            
double[] vknots;
            vknots = (
double[])VKnots;
            
Debug.Print("Knot vector in the V direction: ");
            
for (i = 0; i <= vknots.GetUpperBound(0); i++)
            {
                
Debug.Print(vknots[i].ToString());
            }

            
// Get control points in row = 2, column = 3 of the control point matrix
            vCtrlPts = swBSurfParam.GetControlPoints(2, 3);
            
double[] ctrlpts;
            ctrlpts = (
double[])vCtrlPts;
            
Debug.Print("Control point at row=2 and column=3: ");
            
for (i = 0; i <= ctrlpts.GetUpperBound(0); i++)
            {
                
Debug.Print(ctrlpts[i].ToString());
            }
        }


        
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

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Get B-Spline Surface Parameterization Data Example (C#)
*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) 2013 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.