Get Options of Nonlinear Study (C#)
This example shows how to get a nonlinear
study's options.
//---------------------------------------------------------------------------
// Preconditions:
// 1. Add the SOLIDWORKS Simulation as an add-in
// (in SOLIDWORKS, click Tools > Add-ins > SOLIDWORKS Simulation).
// 2. Add the SOLIDWORKS Simulation primary interop assembly as
// a reference (in the IDE's Project Explorer, right-click
// the project name, select Add Reference, click the Browse tab,
// navigate to the install_dir\api\redist\CLR2 folder and
// select SolidWorks.Interop.cosworks.dll).
// 3. The specified file exists.
// 4. Open the Immediate window.
//
// Postconditions: Data for each nonlinear study in the
// active model is printed to the Immediate window.
//
// NOTE: Because the model is used elsewhere, do not
// save any
changes when closing it.
//-------------------------------------
using
SolidWorks.Interop.sldworks;
using
SolidWorks.Interop.swconst;
using
SolidWorks.Interop.cosworks;
using
System;
using
System.Diagnostics;
namespace
CWNonLinearStudyOptionsCSharp.csproj
{
partial
class
SolidWorksMacro
{
public
void Main()
{
CwAddincallback swAddin;
CosmosWorks ssApp;
CWModelDoc ssModelDoc;
CWStudyManager ssStudyMgr;
CWStudy ssStudy;
object
ssStudyOption;
CWNonLinearStudyOptions ssNonLinearStudyOptions;
string
docName;
int
errors = 0;
int
warnings = 0;
int
studyCnt;
string
studyName;
int
studyType;
int
i;
double
maxLoad;
double
maxDisplacement;
int
unit;
object
selectedEntity;
int
maxArcSteps;
double
arcLengthMultiplier;
int
displacementComponent;
int
frequency;
int
maximum;
double
convergence;
double
tolerance;
double
factor;
Entity swEntity;
int
entityType;
string
selEntityType;
// Open specified document,
which has two nonlinear studies
docName =
"c:\\Program Files\\solidworks
Corp\\SOLIDWORKS\\Simulation\\Examples\\Nonlinear\\nl_plate.sldprt";
swApp.OpenDoc6(docName, (int)swDocumentTypes_e.swDocPART,
(int)swOpenDocOptions_e.swOpenDocOptions_Silent,
"",
ref errors,
ref
warnings);
// Get SOLIDWORKS Simulation
and its Study Manager object
swAddin = (CwAddincallback)swApp.GetAddInObject("SldWorks.Simulation");
ssApp = (CosmosWorks)swAddin.CosmosWorks;
ssModelDoc = (CWModelDoc)ssApp.ActiveDoc;
ssStudyMgr = (CWStudyManager)ssModelDoc.StudyManager;
// Get data for only nonlinear
types of studies
studyCnt = ssStudyMgr.StudyCount;
for
(i = 0; i <= studyCnt - 1; i++)
{
ssStudy = (CWStudy)ssStudyMgr.GetStudy(i);
studyName = ssStudy.Name;
Debug.Print("");
Debug.Print("Study
name: " + studyName);
studyType = ssStudy.AnalysisType;
if
((studyType == (int)swsAnalysisStudyType_e.swsAnalysisStudyTypeNonlinear))
{
// Get nonlinear
study's data
ssStudyOption = (object)ssStudy.NonLinearStudyOptions;
Debug.Print(" Study
type: Nonlinear");
ssNonLinearStudyOptions = (CWNonLinearStudyOptions)ssStudyOption;
Debug.Print(" Control
method type: " + ssNonLinearStudyOptions.ControlMethodType);
Debug.Print(" Start
time: " + ssNonLinearStudyOptions.StartTime);
Debug.Print(" End
time: " + ssNonLinearStudyOptions.EndTime);
Debug.Print(" Solution-time
increment: " + ssNonLinearStudyOptions.TimeIncrement);
Debug.Print(" Fixed-time
increment: " + ssNonLinearStudyOptions.FixedTimeIncrement);
Debug.Print(" Integration
method type: " + ssNonLinearStudyOptions.IntegrationMethodType);
Debug.Print(" Results
folder path: " + ssNonLinearStudyOptions.ResultFolderPath);
Debug.Print(" Save
data for restarting analysis? " +
ssNonLinearStudyOptions.SaveDataForRestartingAnalysis);
Debug.Print(" Solver
type: " + ssNonLinearStudyOptions.SolverType);
Debug.Print(" Use
large strain formulation? " +
ssNonLinearStudyOptions.UseLargeStrain);
Debug.Print(" Update
direction of load at every solution step with deflection? "
+ ssNonLinearStudyOptions.UseUpdateLoadDirection);
ssNonLinearStudyOptions.GetArcLengthCompletionOptions(out
maxLoad, out
maxDisplacement, out
unit, out
maxArcSteps, out
arcLengthMultiplier);
Debug.Print(" Use
large displacement formulation? " +
ssNonLinearStudyOptions.UseLargeDisplacement);
Debug.Print(" Arc-length
completion options (maximum load, maximum displacement, unit, maximum arc
steps, and arc-length multiplier): " +
maxLoad + ", "
+ maxDisplacement + ", "
+ unit + ", "
+ maxArcSteps + ", "
+ arcLengthMultiplier);
selEntityType =
"null";
ssNonLinearStudyOptions.GetDisplacementControlOptions2(out
displacementComponent, out
unit, out
selectedEntity);
if
(selectedEntity != null)
{
swEntity = (Entity)selectedEntity;
entityType = swEntity.GetType();
switch
(entityType)
{
case
3:
selEntityType =
"vertex";
break;
case
6:
selEntityType =
"reference point";
break;
case
0:
selEntityType =
"null";
break;
}
}
Debug.Print(" Displacement
control options (displacement component, unit, selected entity): "
+ displacementComponent + ", "
+ unit + ", "
+ selEntityType);
Debug.Print(" Iterative
method type: " + ssNonLinearStudyOptions.IterativeMethodType);
ssNonLinearStudyOptions.GetStepToleranceOptions(out
frequency, out
maximum, out
convergence, out
tolerance, out
factor);
Debug.Print(" Tolerance:
");
Debug.Print("
Frequency of performing equilibrium in number of solution steps: "
+ frequency);
Debug.Print("
Maximum number of equilibrium iterations for any solution step: "
+ maximum);
Debug.Print("
Relative displacement tolerance used for equilibrium convergence: "
+ convergence);
Debug.Print("
Tolerance for strain increment for models with creep or plasticity: "
+ tolerance);
Debug.Print("
Stiffness singularity elimination factor: "
+ factor);
}
}
}
///
<summary>
///
The SldWorks swApp variable is pre-assigned for you.
///
</summary>
public
SldWorks swApp;
}
}