Create Loft Body Example (C#)
This example shows how to create a loft body.
// ------------------------------------------------------------------------------
// Preconditions:
// (1)
Part document is open.
// (2)
Two closed sketches representing the profiles for the loft body exist.
// (3)
One curve representing a guide curve for the loft body exists.
//
// Postconditions: Loft body is created and displayed.
//
---------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Diagnostics;
namespace CreateLoftBody2Modeler_Csharp.csproj
{
partial
class SolidWorksMacro
{
public
void Main()
{
ModelDoc2
swModel = default(ModelDoc2);
ModelDocExtension
swModelDocExt = default(ModelDocExtension);
FeatureManager
swFeatMgr = default(FeatureManager);
int
count = 0;
object
featArr = null;
Feature
feat1 = default(Feature);
Feature
feat2 = default(Feature);
Feature
feat3 = default(Feature);
SelectionMgr
swSelMgr = default(SelectionMgr);
Modeler
swModeler = default(Modeler);
bool
boolstatus = false;
object
profileIn = null;
object
guideCurve = null;
Feature[]
pProfile = new Feature[2];
Feature[]
pGuide = new Feature[1];
int
bValue = 0;
Body2
swBody = default(Body2);
bool
bIsTempBody = false;
swModeler
= (Modeler)swApp.GetModeler();
swModel
= (ModelDoc2)swApp.ActiveDoc;
swModelDocExt
= swModel.Extension;
//
Select the sketches for the profiles
//
for the loft body and make them
//
elements of an array to use to
//
create the loft body
swFeatMgr
= swModel.FeatureManager;
count
= swFeatMgr.GetFeatureCount(false);
featArr
= swFeatMgr.GetFeatures(false);
swSelMgr
= (SelectionMgr)swModel.SelectionManager;
boolstatus
= swModelDocExt.SelectByID2("Sketch1", "SKETCH", 0.01432052560262,
0.03232526173853, 0, false, 0, null, 0);
feat1
= (Feature)swSelMgr.GetSelectedObject6(1, -1);
Debug.Print("First
profile's feature name: " + feat1.Name);
pProfile[0]
= feat1;
boolstatus
= swModelDocExt.SelectByID2("Sketch2", "SKETCH", 0,
0, 0, false, 0, null, 0);
feat2
= (Feature)swSelMgr.GetSelectedObject6(1, -1);
Debug.Print("Second
profile's feature name: " + feat2.Name);
pProfile[1]
= feat2;
profileIn
= pProfile;
//
Select a guide curve for the loft body
//
and make it an element of an array
//
to use to create the loft body
boolstatus
= swModelDocExt.SelectByID2("Curve1", "REFERENCECURVES",
0.1353192072154, 0.1043159291966, 0.09477145953832, false, 0, null, 0);
feat3
= (Feature)swSelMgr.GetSelectedObject6(1, -1);
Debug.Print("Guide
curve's feature name: " + feat3.Name);
pGuide[0]
= feat3;
guideCurve
= feat3;
//
Create the loft body
swBody
= swModeler.CreateLoftBody2(swModel,
profileIn, guideCurve, null, false, 0, 0, 0, true, false,
true,
false, true, 1, 1, 1, true, true, 1, 1,
true);
//
Test whether the loft body is a temporary body
bIsTempBody
= swBody.IsTemporaryBody();
Debug.Print("Is
the loft body a temporary body? " + bIsTempBody);
//
Display the loft body
bValue
= swBody.Display3(swModel, 256,
(int)swTempBodySelectOptions_e.swTempBodySelectOptionNone);
}
public
SldWorks swApp;
}
}