Hide Table of Contents

Get UV Parameters for XYZ Location Example (C#)

This example shows how to use IFace2 and ICurve interfaces to get the UV parameters from the XYZ location.

//---------------------------------------------------------------------------
// Preconditions:
// 1. Open public_documents\tutorial\cosmosxpress\aw_hook.sldprt.
// 2. Verify that Tools > System Options > Options > FeatureManager > Solid Bodies
//    drop-down selection is Show.
// 3. Expand the Solid Bodies folder and select Split Line1.
// 4. Open the Immediate window or modify the macro to write the output to a file.
//   
// Postconditions: Observe the output in the Immediate window.
//----------------------------------------------------------------------------

using SolidWorks.Interop.sldworks;

using SolidWorks.Interop.swconst;

using System;

using System.Diagnostics;


namespace ReverseEvalTestMIK_CSharp.csproj

{

    partial class SolidWorksMacro

    {

        ModelDoc2 swModel;

        SelectionMgr swSelMgr;

        Face2 swFace;
 

        public void Main()

        {

            swModel = (ModelDoc2)swApp.ActiveDoc;

            swSelMgr = (SelectionMgr)swModel.SelectionManager;

            double[] pntData = new double[3];

            Body2 swBody = default(Body2);

            Body2 procBody = default(Body2);

            swBody = (Body2)swSelMgr.GetSelectedObject6(1, -1);

            procBody = swBody.GetProcessedBody2(0.5, 0.5);

            //Bypass surface split

            swFace = (Face2)procBody.GetFirstFace();

            //Set swFace = swBody.GetFirstFace

            while ((swFace != null))

            {

                double[] uvBnds = null;

                uvBnds = (double[])swFace.GetUVBounds();

                double UminFace = 0;

                double UmaxFace = 0;

                double VminFace = 0;

                double VmaxFace = 0;

                UminFace = uvBnds[0];

                UmaxFace = uvBnds[1];

                VminFace = uvBnds[2];

                VmaxFace = uvBnds[3];

                Surface swSurf = default(Surface);

                swSurf = (Surface)swFace.GetSurface();

                uvBnds = (double[])swSurf.Parameterization();

                double UminSurf = 0;

                double UmaxSurf = 0;

                double VminSurf = 0;

                double VmaxSurf = 0;

                UminSurf = uvBnds[0];

                UmaxSurf = uvBnds[1];

                VminSurf = uvBnds[2];

                VmaxSurf = uvBnds[3];

                object[] vEdges = null;

                vEdges = (object[])swFace.GetEdges();

                int i = 0;

                for (i = 0; i <= vEdges.GetUpperBound(0); i++)

                {

                    Edge swEdge = default(Edge);

                    swEdge = (Edge)vEdges[i];

                    Curve swCurve = default(Curve);

                    swCurve = (Curve)swEdge.GetCurve();

                    double[] vCurveParams = null;

                    vCurveParams = (double[])swEdge.GetCurveParams2();

                    double startParam = 0;

                    double endParam = 0;

                    double incParam = 0;

                    double curParam = 0;

                    startParam = vCurveParams[6];

                    endParam = vCurveParams[7];

                    incParam = (endParam - startParam) / 10.0;

                    curParam = startParam;

                    while (curParam < endParam)

                    {

                        double[] vEdgePnt = null;

                        vEdgePnt = (double[])swEdge.Evaluate(curParam);

                        double[] vUVSurfParams = null;

                        double UEdge = 0;

                        double VEdge = 0;

                        // Get the UV parameters for the point using IFace2::ReverseEvaluate

                        vUVSurfParams = (double[])swFace.ReverseEvaluate(vEdgePnt[0], vEdgePnt[1], vEdgePnt[2]);

                        if ((vUVSurfParams != null))

                        {

                            UEdge = vUVSurfParams[0];

                            VEdge = vUVSurfParams[1];

                            Debug.Print("Edge point: " + " x: " + vEdgePnt[0] + " y: " + vEdgePnt[1] + " z: " + vEdgePnt[2]);

                            Debug.Print("U parameter returned from IFace2::ReverseEvaluate is " + UEdge);

                            if (UEdge > UmaxFace | UEdge < UminFace)

                            {

                                Debug.Print("U param error face");

                            }

                            //Stop

                            Debug.Print("V parameter returned from IFace2::ReverseEvalute is " + VEdge);

                            if (VEdge > VmaxFace | VEdge < VminFace)

                            {

                                Debug.Print("V param error face");

                            }

                            //Stop

                        }

                        else

                        {

                            Debug.Print("Face reverse evaluate fails - empty data");

                        }

                        // Get the UV parameters for the point using ICurve::ReverseEvaluate

                        vUVSurfParams = (double[])swSurf.ReverseEvaluate(vEdgePnt[0], vEdgePnt[1], vEdgePnt[2]);

                        if ((vUVSurfParams != null))

                        {

                            UEdge = vUVSurfParams[0];

                            VEdge = vUVSurfParams[1];

                            Debug.Print("U parameter returned from ICurve::ReverseEvaluate is " + UEdge);

                            if (UEdge > UmaxFace | UEdge < UminFace)

                            {

                                Debug.Print("U param error surface");

                            }

                            //Stop

                            Debug.Print("V parameter returned from ICurve::ReverseEvaluate is " + VEdge);

                            if (VEdge > VmaxFace | VEdge < VminFace)

                            {

                                Debug.Print("V param error surface");

                            }

                            //Stop

                        }

                        curParam = curParam + incParam;

                    }

                }

                swFace = (Face2)swFace.GetNextFace();

            }

            Debug.Print("Complete");

        }

        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 UV Parameters for XYZ Location 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) 2017 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.