Table of Contents

Class Body2Extensions

Namespace
Hymma.Solidworks.Extensions
Assembly
Hymma.Solidworks.Extensions.dll

Extension methods for SolidWorks.Interop.sldworks.Body2 objects providing operations for solid bodies, sheet metal, and weldments.

public static class Body2Extensions
Inheritance
Body2Extensions
Inherited Members

Examples

Working with sheet metal bodies:

Body2 body = part.GetBodies()[0] as Body2;

if (body.IsSheetMetal())
{
    // Get flat pattern
    Feature flatPattern = body.GetFlatPattern();

    // Get dimensions
    string[] sizes = body.GetSheetMetalSizes(part, solidworks);
    string length = sizes[0];
    string width = sizes[1];
    string thickness = sizes[2];

    // Get bend lines
    var bendLines = body.GetBendLinePoints();
}

Remarks

These extensions provide convenient methods for working with SolidWorks bodies:

  • Feature extraction by name or type
  • Sheet metal operations (flat patterns, bend lines, sizes)
  • Weldment operations (cut lists, properties)
  • Face and mass property queries

Methods

GetBendLinePoints(Body2)

will return a list of skethcPoints key value pairs where key is StartPoint Value is the end point of a bend line

public static IList<SketchPoint[]> GetBendLinePoints(this Body2 body)

Parameters

body Body2

the body with flat pattern feature to get bend lines of

Returns

IList<SketchPoint[]>

list of skethcPoints key value pairs

GetCutListFolder(Body2, PartDoc, SldWorks)

gets the cut-list folder of this body, it applies to weldment or sheetmetal components only

public static Feature GetCutListFolder(this Body2 body, PartDoc part, SldWorks solidwork)

Parameters

body Body2
part PartDoc
solidwork SldWorks

Returns

Feature

GetCutListFolder as SolidWorks.Interop.sldworks.Feature

GetFaceByName(Body2, ModelDoc2, string)

if a face has name returns it otherwise returns null

public static Face2 GetFaceByName(this Body2 body, ModelDoc2 model, string name)

Parameters

body Body2
model ModelDoc2
name string

Returns

Face2

GetFeatureByName(Body2, string, bool)

get feature by its name

public static Feature GetFeatureByName(this Body2 body, string name, bool ExcludeSuppressed = true)

Parameters

body Body2
name string
ExcludeSuppressed bool

disregard feature if is suppressed

Returns

Feature

GetFeaturesByTypeName(Body2, string, bool)

get feature by its type name

public static IList<Feature> GetFeaturesByTypeName(this Body2 body, string type, bool ExcludeSuppressed = true)

Parameters

body Body2
type string

type of feature in string refer to link below to interpret the type

ExcludeSuppressed bool

disregard feature if is suppressed

Returns

IList<Feature>

SolidWorks.Interop.sldworks.Feature and null if the feature is suppressed or could not find the feature

GetFlatPattern(Body2)

get flat pattern in this body

public static Feature GetFlatPattern(this Body2 body)

Parameters

body Body2

Returns

Feature

GetFlatPatternBoxCoords(Body2)

will return flat-pattern bounding box coordinates in metric unit

public static double[] GetFlatPatternBoxCoords(this Body2 body)

Parameters

body Body2

Returns

double[]

An array of 6 doubles. where the first three are the x,y,z coordinations of one corner of the cube and the rest are the coordinations of the other corner

GetMassProperties(Body2, ModelDoc2)

Use this method to get component mass properties

public static double[] GetMassProperties(this Body2 body, ModelDoc2 model)

Parameters

body Body2
model ModelDoc2

Returns

double[]

The return value is an array of doubles as follows:

  • Solid body[ CenterOfMassX, CenterOfMassY, CenterOfMassZ, Volume, Area, Mass(Volume*density), MomXX, MomYY, MomZZ, MomXY, MomZX, MomYZ ]
  • Sheet body[ CenterOfMassX, CenterOfMassY, CenterOfMassZ, Area, Circumference, Mass(Area*density), MomXX, MomYY, MomZZ, MomXY, MomZX, MomYZ ]
  • Wire body [ CenterOfMassX, CenterOfMassY, CenterOfMassZ, Length, 0, Mass(Length*density), MomXX, MomYY, MomZZ, MomXY, MomZX, MomYZ ]

GetPropertyFromCutList(Body2, string, bool)

gets custom property value of a property in a weldment or sheetmetal component
required configuration must be activated prior to calling this method

public static string GetPropertyFromCutList(this Body2 body, string customPropertyName, bool useCachedData = false)

Parameters

body Body2
customPropertyName string
useCachedData bool

set this to false to get up-to-date data -

Returns

string

value of the property or empty string if not applicable

GetSheetMetalFeature(Body2)

Gets the sheet metal feature from this body.

public static Feature GetSheetMetalFeature(this Body2 body)

Parameters

body Body2

The body to query.

Returns

Feature

The sheet metal SolidWorks.Interop.sldworks.Feature if the body is sheet metal; otherwise, null.

Examples

Feature smFeature = body.GetSheetMetalFeature();
if (smFeature != null)
{
    SheetMetalFeatureData smData = smFeature.GetDefinition() as SheetMetalFeatureData;
    double thickness = smData.Thickness;
}

GetSheetMetalSizes(Body2, PartDoc, SldWorks)

get length, width and thickness of sheetmetal feature

public static string[] GetSheetMetalSizes(this Body2 body, PartDoc part, SldWorks solidworks)

Parameters

body Body2
part PartDoc
solidworks SldWorks

Returns

string[]

an array of string where first member is length in the unit of document, second member is width and third one is thickness

GetWidestFace(Body2)

get the face with most area

public static Face2 GetWidestFace(this Body2 body)

Parameters

body Body2

Returns

Face2

IsWeldment(Body2)

determine if this body has weldment feature in it or not

public static bool IsWeldment(this Body2 body)

Parameters

body Body2

Returns

bool