Hide Table of Contents

Set Composite Shell Options Example (C#)

This example shows how to set composite shell options.

//----------------------------------------------------------------------------
// Preconditions:
// 1. Add the SOLIDWORKS Simulation as an add-in 
//    (in SOLIDWORKS, select Tools > Add-ins > SOLIDWORKS Simulation,
//    and click OK). 
// 2. Add the SOLIDWORKS Simulation primary interop assembly as a reference 
//    (in the IDE's Project Explorer, right-click
//    the project name, click Add Reference, click the Browse tab,
//    navigate to install_dir\api\redist\CLR2
//    click SolidWorks.Interop.cosworks.dll, and click OK).
// 3. Ensure that the specified material library exists.
// 4. Ensure that the specified model document exists.
//
// Postconditions:
// 1. Opens the model.
// 2. Activates Ready - 8 plies.
// 3. Sets composite shell options.
// 4. Meshes the model.
// 5. Analyzes the study.
//
// NOTE: Because the model is used elsewhere, do not save 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 ShellComposite_CSharp.csproj
{
    partial class SolidWorksMacro
    {
 
        CosmosWorks COSMOSWORKS;
        CwAddincallback COSMOSObject;
        CWModelDoc ActDoc;
        CWStudyManager StudyMngr;
        CWStudy Study;
        CWShell Shell;
        CWMesh Mesh;
        CWStaticStudyOptions StaticOptions;
        ModelDoc2 Part;
        CWShellManager ShellMgr;
        CWCompositeShellOptions CWShellOptions;
        CWMaterial CWMat;
        int m;
        int errCode;
        int longstatus;
        int longwarnings;
        int bApp;
        int j;
        const double MeshEleSize = 1.4769;
        const double MeshTol = 0.073847;
 
 
        public void Main()
        {
            COSMOSObject = (CwAddincallback)swApp.GetAddInObject("CosmosWorks.CosmosWorks");
            if (COSMOSObject == null)
                ErrorMsg(swApp, "Simulation add-in not loaded");
            COSMOSWORKS = COSMOSObject.CosmosWorks;
            if (COSMOSWORKS == null)
                ErrorMsg(swApp, "No COSMOSWORKS object");
 
            Part = swApp.OpenDoc6("C:\\Program Files\\SOLIDWORKS Corp\\SOLIDWORKS\\Simulation\\Examples\\Composites\\tjoint.SLDPRT", (int)swDocumentTypes_e.swDocPART, 2, ""ref longstatus, ref longwarnings);
            if (Part == null)
                ErrorMsg(swApp, "Failed to open tjoint.SLDPRT");
 
            ActDoc = COSMOSWORKS.ActiveDoc;
            if (ActDoc == null)
                ErrorMsg(swApp, "No active document");
 
            StudyMngr = ActDoc.StudyManager;
            if (StudyMngr == null)
                ErrorMsg(swApp, "No study manager");
            StudyMngr.ActiveStudy = 1;
            Study = StudyMngr.GetStudy(1);
 
            ShellMgr = Study.ShellManager;
            if (ShellMgr == null)
                ErrorMsg(swApp, "No shell manager");
 
            Shell = ShellMgr.GetShellAt(0, out errCode);
            if (errCode != 0)
                ErrorMsg(swApp, "No shell");
 
            Shell.ShellBeginEdit();
            bApp = Shell.SetLibraryMaterial("C:\\Program Files\\SOLIDWORKS Corp\\SOLIDWORKS\\lang\\english\\sldmaterials\\solidworks materials.sldmat""Alloy Steel");
            Shell.Formulation = 2;
 
            CWShellOptions = Shell.CompositeOptions;
            if (CWShellOptions == null)
                ErrorMsg(swApp, "No composite shell options");
 
            CWShellOptions.Symmetric = 0;
            CWShellOptions.RotateZeroDegreeReference = 0;
            CWShellOptions.MappingType = 0;
            CWShellOptions.Symmetric = 0;
            CWShellOptions.Sandwich = 0;
            CWShellOptions.PlyRelativeAngle = 0;
            CWShellOptions.LengthUnit = 4;
            CWShellOptions.AllPliesSameMaterial = 1;
 
            m = CWShellOptions.GetTotalPlies();
            CWMat = Shell.GetShellMaterial();
            for (j = 0; j <= m - 1; j++)
            {
                errCode = CWShellOptions.SetPlyParameters(j + 1, 0.1 * (j + 1), 0.05 * j, CWMat);
            }
 
            Shell.ShellEndEdit();
 
            //Mesh
            Mesh = Study.Mesh;
            Mesh.MesherType = 0;
            Mesh.Quality = 0;
            errCode = Study.CreateMesh(0, MeshEleSize, MeshTol);
 
            StaticOptions = Study.StaticStudyOptions;
            StaticOptions.SolverType = 2;
 
            //Run analysis
            errCode = Study.RunAnalysis();
 
        }
 
        public void ErrorMsg(SldWorks SwApp, string Message)
        {
            SwApp.SendMsgToUser2(Message, 0, 0);
            SwApp.RecordLine("'*** WARNING - General");
            SwApp.RecordLine("'*** " + Message);
            SwApp.RecordLine("");
        }
 
        /// <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:   Set Composite Shell Options 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) 2016 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.