Get Component by Name (C#)
This examples shows how to get a component by name and to determine
if that component is fixed or floating.
//-------------------------------------------------------------------------
// Preconditions: Open:
// <SolidWorks_install_dir>\samples\tutorial\EDraw\claw\claw-mechanism.sldasm
//
// Postconditions: None.
//-------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace Macro1.csproj
{
public
partial class SolidWorksMacro
{
ModelDoc2
swModel;
AssemblyDoc
swAssy;
Component2
swComp;
public
void Main()
{
swModel
= swApp.ActiveDoc as ModelDoc2;
swAssy
= swModel as AssemblyDoc;
string
compName;
compName
= "center-1";
swComp
= swAssy.GetComponentByName(compName);
bool
bRet;
bRet
= swComp.IsFixed();
Debug.Print("Is
component fixed: " + bRet);
}
///
<summary>
///
The SldWorks
swApp variable is pre-assigned for you.
///
</summary>
public
SldWorks swApp;
}
}