Insert Cosmetic Weld Bead Example (C#)
This example shows how to insert a cosmetic weld bead feature and access its
properties.
//----------------------------------------------------------------------------
// Preconditions: Open:
// install_dir\samples\tutorial\api\Insert_weld.sldprt
//
// Postconditions:
// 1. A fillet weld, Weld Bead2, is created and added to the Weld Folder in
// the FeatureManager design tree.
// 2. Inspect the Weld Bead1 settings and properties in the Immediate
window.
//
// NOTE: Because the model is used elsewhere,
// do not save changes when closing it.
//
---------------------------------------------------------------------------
using
Microsoft.VisualBasic;
using
System;
using
System.Collections;
using
System.Collections.Generic;
using
System.Data;
using
System.Diagnostics;
using
SolidWorks.Interop.sldworks;
using
SolidWorks.Interop.swconst;
using
System.Runtime.InteropServices;
namespace
InsertWeld2_CSharp.csproj
{
partial
class
SolidWorksMacro
{
ModelDoc2
Part;
bool
boolstatus;
CosmeticWeldBeadFeatureData
FeatureData;
CosmeticWeldBeadFolder
WeldFolder;
SelectionMgr
selman;
Feature
myFeature;
public
void Main()
{
Part = (ModelDoc2)swApp.ActiveDoc;
boolstatus = Part.Extension.SelectByID2("",
"FACE",
-0.0344320907599354, 0.0170180000000641, -0.00227566098720899,
false, 0,
null, 0);
boolstatus = Part.Extension.SelectByID2("",
"FACE",
-0.0161637176506133, 0.0503122973344716, -0.0013752238241409,
true, 0,
null, 0);
myFeature = Part.FeatureManager.InsertCosmeticWeldBead(0.51);
Part.ClearSelection2(true);
boolstatus = Part.Extension.SelectByID2("Weld
Bead1",
"COSMETIC_WELD", 0, 0, 0,
false, 0,
null, 0);
selman = (SelectionMgr)Part.SelectionManager;
myFeature = (Feature)selman.GetSelectedObject6(1,
0);
FeatureData = (CosmeticWeldBeadFeatureData)myFeature.GetDefinition();
FeatureData.AccessSelections(Part,
null);
Debug.Print("weld
bead settings: ");
Debug.Print("
weld bead size was " + FeatureData.BeadSize);
FeatureData.BeadSize = 0.6;
Debug.Print("
weld bead size is now " + FeatureData.BeadSize);
if
(FeatureData.TangentPropagation ==
false)
{
FeatureData.TangentPropagation =
true;
}
Debug.Print("
tangent propagation? " + FeatureData.TangentPropagation);
Debug.Print("
weld sides as defined in swCosmeticWeldBeadSide_e: "
+ FeatureData.Side);
if
(FeatureData.FromToLength == false)
{
FeatureData.FromToLength =
true;
}
Debug.Print("
from/to length properties enabled? " +
FeatureData.FromToLength);
if
(FeatureData.FromToLength)
{
Debug.Print("
start weld at: " + FeatureData.FromToStartPoint);
Debug.Print("
weld length: " + FeatureData.FromToWeldLength);
Debug.Print("
reverse weld? " + FeatureData.FromToReverse);
}
if
(FeatureData.IntermittentWeld ==
false)
{
FeatureData.IntermittentWeld =
true;
}
Debug.Print("
intermittent weld properties enabled? " +
FeatureData.IntermittentWeld);
if
(FeatureData.IntermittentWeld)
{
if
(FeatureData.GapOrPitch)
{
Debug.Print("
intermittent weld gap: " + FeatureData.Gap);
Debug.Print("
intermittent weld length: " + FeatureData.IntermittentWeldLength);
}
else
{
Debug.Print("
intermittent weld pitch: " + FeatureData.Pitch);
Debug.Print("
intermittent weld length: " + FeatureData.IntermittentWeldLength);
Debug.Print("
stagger welds if welding on both sides? " +
FeatureData.Staggered);
}
}
WeldFolder = (CosmeticWeldBeadFolder)FeatureData.GetWeldBeadFolder();
Debug.Print("weld
bead properties:");
WeldFolder.Material =
"Steel";
Debug.Print("
weld material is " + WeldFolder.Material);
Debug.Print("
welding cost per unit mass: " + WeldFolder.CostPerUnitMass);
Debug.Print("
weld mass per unit length: " + WeldFolder.MassPerUnitLength);
Debug.Print("
number of weld passes: " + WeldFolder.NumberOfWeldPasses);
Debug.Print("
weld process: " + WeldFolder.Process);
Debug.Print("
welding time per unit length: " +
WeldFolder.TimePerUnitLength);
Debug.Print("
total welding cost: " + WeldFolder.TotalCost);
Debug.Print("
total weld length: " + WeldFolder.TotalLength);
Debug.Print("
total weld mass: " + WeldFolder.TotalMass);
Debug.Print("
total number of welds: " + WeldFolder.TotalNumber);
Debug.Print("
total welding time: " + WeldFolder.TotalTime);
boolstatus = myFeature.ModifyDefinition(FeatureData,
Part, null);
}
public
SldWorks
swApp;
}
}