Hide Table of Contents

Get Linearized Stress Results Example (C#)

This example shows how to get the linearized stress results from a pressure vessel study.

//----------------------------------------------------------------------------
// Preconditions:
//  1. Add the SOLIDWORKS Simulation as an add-in (in SOLIDWORKS, click 
//     Tools > Add-ins > SOLIDWORKS Simulation > OK).

//  2. Add the SOLIDWORKS Simulation primary interop assembly as a reference
//     (in the IDE, click Project > Add Reference > .NET > 
//     SolidWorks.Interop.cosworks > OK).

//  3. Open pubic_documents\Simulation Examples\pressurevessel.sldprt.
//  4. Open the Immediate window.
//  5. Modify Ready-Solids and Partial-Solids to have the same fixtures and a
//     pressure load of 100psi.
//  6. Analyze Ready-Solids and Partial-Solids.
//  7. Create Pressure Vessel Design 1 study, using a linear combination of
//     Ready-Solids and Partial-Solids with Factor = 1.
//  8. Analyze Pressure Vessel Design 1.
//  9. Create a default von Mises stress plot of the results.
// 10. Create a planar section view of the von Mises stress plot:
//     a. Right-click the von Mises stress plot of Pressure Vessel Design 1 and
//        click Section Clipping.
//     b. In Section 1, click Plane, delete Front, and select Top in the
//        FeatureManager design tree.
//     c. In Options, click Union and select the first three check boxes.
//     d. Click the green check mark to accept the settings.
//
// Postconditions:
//  1. Gets the following linearized normal stress values in the X-direction for
//     the specified points on the planar section view of Stress1:
//     * Membrane stress
//     * Bending (Point 1) stress
//     * Membrane stress + bending (Point 1) stress
//     * Bending (Point 2) stress
//     * Membrane stress + Bending (Point 2) stress
//     * Peak (Point 1)
//     * Peak (Point 2)
//  2. Inspect the Immediate window.
//
// NOTE: Because the model is used elsewhere, do not save any changes.
// ---------------------------------------------------------------------------
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 SolidWorks.Interop.cosworks;
using System.Runtime.InteropServices;
namespace GetLinearizedStresses_CSharp.csproj
{
    partial class SolidWorksMacro
    {
 
        CosmosWorks COSMOSWORKS;
        CwAddincallback CWObject;
        CWModelDoc ActDoc;
        CWStudyManager StudyMngr;
        CWStudy Study;
        CWResults CWResult;
        object[] stress;
        int errCode;
 
        bool boolCode;
 
        public void Main()
        {
            CWObject = (CwAddincallback)swApp.GetAddInObject("SldWorks.Simulation");
            COSMOSWORKS = CWObject.CosmosWorks;
 
            ActDoc = COSMOSWORKS.ActiveDoc;
            StudyMngr = ActDoc.StudyManager;
            Study = StudyMngr.GetStudy(4);
            StudyMngr.ActiveStudy = 4;
 
            CWResult = Study.Results;
            object plotNames = null;
            plotNames = CWResult.GetPlotNames();
            boolCode = CWResult.ActivatePlot("Stress1");
            stress = (object[])CWResult.GetLinearizedStressValues(0, 0.21, 0.0, -0.206, 0.2667, 0.0, -0.1303, 40, 0, out errCode);
 
            Debug.Print("Linearized normal stresses in the X-direction:");
            Debug.Print("  Membrane:                     " + stress[0]);
            Debug.Print("  Bending (Point 1):            " + stress[1]);
            Debug.Print("  Membrane + Bending (Point 1): " + stress[2]);
            Debug.Print("  Bending (Point 2):            " + stress[3]);
            Debug.Print("  Membrane + Bending (Point 2): " + stress[4]);
            Debug.Print("  Peak (Point 1):               " + stress[5]);
            Debug.Print("  Peak (Point 2):               " + stress[6]);
 
        }
 
 
        /// <summary>
        /// The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
 
        public SldWorks swApp;
 
    }
 
}



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Get Linearized Stress Results Example (C#)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2018 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.