Get and Set Loft's Pick Points Example (C#)
This example shows how to get the pick points of a loft feature.
//---------------------------------------------------------------------------
// Preconditions:
// 1. Open:
// <SolidWorks_install_dir>\samples\tutorial\cosmosfloxpress\ball valve\handle.sldprt
// 2. The feature named 1 (a loft feature)
is selected.
//
// Postconditions: New loft pick points set.
//-----------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Diagnostics;
namespace GetPickPointsLoft_CSharp.csproj
{
partial
class SolidWorksMacro
{
ModelDoc2
swModel;
SelectionMgr
swSelMgr;
Feature
swFeat;
LoftFeatureData
swFeatData;
MathPoint
swMathPoint;
MathPoint[]
newMathPoint;
double[]
newTopPoint = new double[4];
double[]
pointArray;
object[]
pickPointData;
object
pointVar;
object
newTopVar;
object[]
pointData;
long
selCount;
long
chainCount;
long
pointCount;
long
numberOfChains;
long
numOfPointInEachChain;
long
newCount;
public
void Main()
{
swModel
= (ModelDoc2)swApp.ActiveDoc;
swSelMgr
= (SelectionMgr)swModel.SelectionManager;
selCount
= swSelMgr.GetSelectedObjectCount();
if
(selCount != 1)
{
System.Windows.Forms.MessageBox.Show("Select
a loft feature.");
}
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;
Debug.Print("No.
of chains = " + numberOfChains);
Debug.Print("");
for
(chainCount = pickPointData.GetLowerBound(0); chainCount <= pickPointData.GetUpperBound(0);
chainCount++)
{
pointData
= (Object[])pickPointData[chainCount];
numOfPointInEachChain
= pointData.GetUpperBound(0) + 1;
Array.Resize(ref
newMathPoint, (int)((numberOfChains * numOfPointInEachChain) - 1) + 1);
Debug.Print("Chain
= " + chainCount + ", Number of points = " + numOfPointInEachChain);
for
(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("");
}
//Change
the loft's pick points
newTopPoint[0]
= 0.0;
newTopPoint[1]
= 0.0;
newTopPoint[2]
= 0.2;
newTopVar
= newTopPoint;
newMathPoint[2].ArrayData
= newTopVar;
newTopPoint[0]
= 0.05;
newTopPoint[1]
= 0.0;
newTopPoint[2]
= 0.2;
newTopVar
= newTopPoint;
newMathPoint[5].ArrayData
= newTopVar;
newTopPoint[0]
= 0.05;
newTopPoint[1]
= 0.05;
newTopPoint[2]
= 0.2;
newTopVar
= newTopPoint;
newMathPoint[8].ArrayData
= newTopVar;
newTopPoint[0]
= 0.0;
newTopPoint[1]
= 0.05;
newTopPoint[2]
= 0.2;
newTopVar
= newTopPoint;
newMathPoint[11].ArrayData
= newTopVar;
//
Set the loft's new pick points
Boolean
status = false;
status
= swFeatData.AccessSelections(swModel, null);
swFeatData.PickPoints = newMathPoint;
status
= swFeat.ModifyDefinition(swFeatData, swModel, null);
Debug.Print("Loft
pick points were modified: " + status);
}
public
SldWorks swApp;
}
}