Class ModelDoc2Extensions
- Namespace
- Hymma.Solidworks.Extensions
- Assembly
- Hymma.Solidworks.Extensions.dll
Extension methods for SolidWorks.Interop.sldworks.ModelDoc2 objects providing common operations for parts, assemblies, and drawings.
public static class ModelDoc2Extensions
- Inheritance
-
ModelDoc2Extensions
- Inherited Members
Examples
Common usage patterns:
ModelDoc2 model = solidworks.ActiveDoc as ModelDoc2;
// Switch configuration
model.ActivateConfiguration("Config2");
// Get custom property
string partNumber = model.GetCustomProperty("PartNumber");
// Optimize performance for batch operations
model.Freeze();
try
{
// Perform many operations...
}
finally
{
model.UnFreeze();
}
Remarks
These extensions simplify common SolidWorks API operations such as:
- Configuration management
- Graphics performance optimization (freeze/unfreeze)
- Custom property access
- Mass properties retrieval
- Unit conversions
Methods
ActivateConfiguration(ModelDoc2, string)
Activates (switches to) a specified configuration in the model.
public static bool ActivateConfiguration(this ModelDoc2 model, string configurationName)
Parameters
modelModelDoc2The model document.
configurationNamestringThe name of the configuration to activate.
Returns
- bool
trueif the configuration was successfully activated or is already active;falseif the configuration could not be activated.
Examples
if (model.ActivateConfiguration("Machined"))
{
// Configuration is now active, proceed with operations
}
Freeze(ModelDoc2)
Freezes graphics updates and feature tree to improve performance during batch operations.
public static void Freeze(this ModelDoc2 model)
Parameters
modelModelDoc2The model document to freeze.
Examples
model.Freeze();
try
{
// Perform batch operations (add features, modify dimensions, etc.)
for (int i = 0; i < 100; i++)
{
// Operations here run much faster with graphics frozen
}
}
finally
{
model.UnFreeze();
}
Remarks
Freezing disables graphics updates and feature tree refreshes, which can significantly improve performance when performing many operations in sequence.
Important: Always call UnFreeze(ModelDoc2) in a finally block to ensure the UI is restored even if an exception occurs.
- See Also
GetCustomProperty(ModelDoc2, string, string, bool)
Gets the custom properties for this document or configuration
File custom information is stored in the document file. It can be:
- General to the file, in which case there is a single value whatever the model's configuration
- Configuration-specific, in which case a different value may be set for each configuration in the model
To access a general custom information value, set the configuration argument to an empty string. To get a document-level property, pass an empty string ("") to the configuration argument.
public static string GetCustomProperty(this ModelDoc2 modelDoc, string property, string configuration = "", bool useCachedData = false)
Parameters
Returns
GetLengthUnitName(ModelDoc2)
returns units of length in string format
public static string GetLengthUnitName(this ModelDoc2 model)
Parameters
modelModelDoc2
Returns
GetMassProperties(ModelDoc2, Body2, int)
Use this method to get component mass properties
use index (base zero) to retrieve a specific value
public static double GetMassProperties(this ModelDoc2 model, Body2 body, int index)
Parameters
modelModelDoc2bodyBody2indexint
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 ]
UnFreeze(ModelDoc2)
Restores graphics updates and feature tree after a Freeze(ModelDoc2) operation.
public static void UnFreeze(this ModelDoc2 model)
Parameters
modelModelDoc2The model document to unfreeze.
Remarks
Call this method after completing batch operations to restore normal UI behavior. The graphics view will be refreshed automatically.
- See Also