Hide Table of Contents

Get Frequencies in Mode Shape Plots Example (C#)

This example shows how to get frequencies for all mode shapes in amplitude plots.

//----------------------------------------------------------------------------
// 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 model exists.
//
// Postconditions:
// 1. Meshes the model.
// 2. Analyzes the study.
// 3. Gets the frequencies of all amplitude plot mode shapes.
// 4. Displays a message box with the frequency for mode shape 2.
// 5. Click OK.
//
// 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;
using System.Windows.Forms;
namespace GetFreqOrTime_CSharp.csproj
{
    partial class SolidWorksMacro
    {
        ModelDoc2 Part;
        CosmosWorks COSMOSWORKS;
        CwAddincallback CWAddinCallBack;
        CWModelDoc ActDoc;
        CWStudyManager StudyMngr;
        CWStudy Study;
        CWResults CWResult;
        CWMesh mesh;
        int errorCode;
        int longstatus;
        int longwarnings;
        object[] TimeorFrequency;
 
        int ModeShapeNumber;
 
        const double MeshEleSize = 47.9; //mm
        const double MeshTol = 2.39; //mm
 
        public void Main()
        {
            Part = swApp.OpenDoc6("C:\\Program Files\\SOLIDWORKS Corp\\SOLIDWORKS\\Simulation\\Examples\\Dynamics\\ac_unit.sldasm", (int)swDocumentTypes_e.swDocASSEMBLY, 1, ""ref longstatus, ref longwarnings);
 
            CWAddinCallBack = (CwAddincallback)swApp.GetAddInObject("CosmosWorks.CosmosWorks");
            COSMOSWORKS = CWAddinCallBack.CosmosWorks;
            ActDoc = COSMOSWORKS.ActiveDoc;
            StudyMngr = ActDoc.StudyManager;
            StudyMngr.ActiveStudy = 0;
            Study = StudyMngr.GetStudy(0);
 
            mesh = Study.Mesh;
            mesh.MesherType = 0;
            mesh.Quality = 0;
            errorCode = Study.CreateMesh(0, MeshEleSize, MeshTol);
 
            errorCode = Study.RunAnalysis();
            CWResult = Study.Results;
 
            ModeShapeNumber = 2;
            TimeorFrequency = (object[])CWResult.GetTimeOrFrequencyAtEachStep(0, out errorCode);
            MessageBox.Show("Frequency for mode shape 2: " + TimeorFrequency[ModeShapeNumber - 1]);
 
        }
 
        /// <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 Frequencies in Mode Shape Plots 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.