Hide Table of Contents

Get and Set Loft's Pick Points Example (C#)

This example shows how to get and set the pick points of a loft feature.

//----------------------------------------------------------  
// Preconditions:
// 1. Open a part that contains a loft.
// 2. Open the Immediate window.
// 3. Select the loft feature.
//
// Postconditions:
// 1. New loft pick points are set.
// 2. Examine the part and Immediate window to verify.
//
//----------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace GetPickPointsLoft_CSharp.csproj
{
    
partial class SolidWorksMacro
    {

        ModelDoc2 swModel;
        SelectionMgr swSelMgr;
        Feature swFeat;
        LoftFeatureData swFeatData;
        MathPoint swMathPoint;
        MathPoint[] newMathPoint;
        
double[] pointArray;
        
Object[] pickPointData;
        
Object pointVar;
        
Object[] pointData;
        
Object[] newChains;
        
int selCount;
        
int numberOfChains;
        
int newCount;

        
public void Main()
        {

            swModel = (ModelDoc2)swApp.ActiveDoc;
            swSelMgr = (SelectionMgr)swModel.SelectionManager;
            selCount = swSelMgr.GetSelectedObjectCount();
            
if (selCount != 1)
            {
                System.Windows.Forms.MessageBox.Show(
"Select the loft feature and rerun the macro.");
                
return;
            }

            swFeat = (Feature)swSelMgr.GetSelectedObject6(1, -1);
            swFeatData = (LoftFeatureData)swFeat.GetDefinition();

            
// Get the loft's pick points
            newCount = 0;
            pickPointData = (
Object[])swFeatData.PickPoints;
            numberOfChains = pickPointData.GetUpperBound(0) + 1;
            newChains =
new Object[numberOfChains];
            
Debug.Print("No. of chains = " + numberOfChains);
            
Debug.Print("");


            
for (int chainCount = pickPointData.GetLowerBound(0); chainCount <= pickPointData.GetUpperBound(0); chainCount++)
            {
                pointData = (
Object[])pickPointData[chainCount];
                
int numOfPointInEachChain = pointData.GetUpperBound(0) + 1;


                MathPoint[] newPoints =
new MathPoint[numOfPointInEachChain];
                
Debug.Print("Chain = " + chainCount + ", Number of points = " + numOfPointInEachChain);
                
for (int pointCount = pointData.GetLowerBound(0); pointCount <= pointData.GetUpperBound(0); pointCount++)
                {
                    swMathPoint = (MathPoint)pointData[pointCount];
                    pointVar = swMathPoint.ArrayData;
                    pointArray = (
Double[])pointVar;
                    newPoints[pointCount] = swMathPoint;
                    
Debug.Print("X = " + (double)pointArray[0] * 1000 + " Y = " + (double)pointArray[1] * 1000 + " Z = " + (double)pointArray[2] * 1000);

                    newCount = newCount + 1;
                }
                newChains[chainCount] = newPoints;
                
Debug.Print("");
                numPoints = numOfPointInEachChain;
            }

            
// Change the loft pick points, rotating them to create a twist
            MathPoint[] tmpPoints = (MathPoint[])newChains[newChains.GetUpperBound(0)];
            MathPoint objPrev = tmpPoints[numPoints - 1];
            
Object[] chainArr = new Object[newChains.GetUpperBound(0) + 1];
            
for (int chainCount = newChains.GetLowerBound(0); chainCount <= newChains.GetUpperBound(0); chainCount++)
            {
                MathPoint[] newPoints = (MathPoint[])newChains[chainCount];
                MathPoint tmp = newPoints[numPoints - 1];
                newPoints[numPoints - 1] = objPrev;
                objPrev = tmp;

                
DispatchWrapper[] newPointWrapArray = (DispatchWrapper[])ObjectArrayToDispatchWrapperArray(newPoints);
                chainArr[chainCount] = newPointWrapArray;
            }



            
// Set the loft's new pick points
            Boolean status = false;
            status = swFeatData.AccessSelections(swModel,
null);
            swFeatData.PickPoints = chainArr;

            status = swFeat.ModifyDefinition(swFeatData, swModel,
null);
            
Debug.Print("Loft's pick points were modified: " + status);
            
Debug.Print("");

            
// Get the loft's pick points
            newCount = 0;
            pickPointData = (
Object[])swFeatData.PickPoints;
            numberOfChains = pickPointData.GetUpperBound(0) + 1;
            
Debug.Print("No. of chains = " + numberOfChains);
            
Debug.Print("");
            
for (int chainCount = pickPointData.GetLowerBound(0); chainCount <= pickPointData.GetUpperBound(0); chainCount++)
            {
                pointData = (
Object[])pickPointData[chainCount];
                
long numOfPointInEachChain = pointData.GetUpperBound(0) + 1;
                
Array.Resize(ref newMathPoint, (int)((numberOfChains * numOfPointInEachChain) - 1) + 1);
                
Debug.Print("Chain = " + chainCount + ", Number of points = " + numOfPointInEachChain);
                
for (int pointCount = pointData.GetLowerBound(0); pointCount <= pointData.GetUpperBound(0); pointCount++)
                {
                    swMathPoint = (MathPoint)pointData[pointCount];
                    pointVar = swMathPoint.ArrayData;
                    newMathPoint[newCount] = swMathPoint;
                    newMathPoint[newCount].ArrayData = pointVar;
                    pointArray = (
Double[])pointVar;
                    
Debug.Print("X = " + (double)pointArray[0] * 1000 + " Y = " + (double)pointArray[1] * 1000 + " Z = " + (double)pointArray[2] * 1000);
                    newCount = newCount + 1;
                }
                
Debug.Print("");
            }
        }


        
public DispatchWrapper[] ObjectArrayToDispatchWrapperArray(object[] SwObjects)
        {
            
int arraySize = 0;
            arraySize = SwObjects.GetUpperBound(0);
            
DispatchWrapper[] dispwrap = new DispatchWrapper[arraySize + 1];
            
int arrayIndex = 0;
            
for (arrayIndex = 0; arrayIndex <= arraySize; arrayIndex++)
            {
                dispwrap[arrayIndex] =
new DispatchWrapper(SwObjects[arrayIndex]);
            }
            
return dispwrap;
        }



        
public SldWorks swApp;
        
public int numPoints;


    }
}
 



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 and Set Loft's Pick Points 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) 2011 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.