2 Replies Latest reply on Sep 23, 2014 5:32 AM by Xinyu Lin

    API - how to get component's display mode ( Wireframe, Hidden Lines, Shaded, etc.)

    Xinyu Lin

      Dear All,

      We need an API (in C#) to retrieve the component's current display mode (Wireframe, Hidden Lines, Shaded, etc.). The equivalent operation in application's UI is illustrated below.

      componentDisplayMode.png

       

      We are able to Set the component's display mode through "SolidWorks command" like this:

       

      IModelDoc2.Extension.RunCommand( swCommands_Comp_Display_Wireframe , ""); 
      

       

      But the problem is that we cannot find a way to simply Get the display mode through an API programmatically. We searched the Knowledge Base, and found an item as illustrated below:

      componentDisplayMode-KB288909.png

       

      From its description, this item seems to be related to what we want. Are there any such API exist? We are using SolidWorks 2014.

       

      we would really appreciate it if any helps/information are kindly provided.

        • Re: API - how to get component's display mode ( Wireframe, Hidden Lines, Shaded, etc.)
          Eddy Alleman

          Hi Xinyu,

           

          Have a look at :

               DisplayMode Property (IModelView)

           

                 C#
          System.int DisplayMode {get; set;}

           

          Hope this helps,

           

          Eddy

          1 person found this helpful
          • Re: API - how to get component's display mode ( Wireframe, Hidden Lines, Shaded, etc.)
            Xinyu Lin

            Hi Eddy,

            Thank you very much for the promptly reply.

             

            With you hint, we managed to find the example from the solidworks api.

             

            This example shows how to get display modes, transparency states, and visibility states of components.

            //------------------------------------------------------------------------------
            // Preconditions: Open an assembly that contains a minimum of three top-level 
            // components and two display states, "DS_1" and "DS_2".
            // 
            // Postconditions: Inspect the Immediate Window for the display modes, 
            // transparency states, and visibility states of all three components 
            // in both DS_1 and DS_2.
            //-----------------------------------------------------------------------------
            using SolidWorks.Interop.sldworks;
            using SolidWorks.Interop.swconst;
            using System;
            using System.Diagnostics;
            namespace GetDisplayMode.csproj
            {
              public partial class SolidWorksMacro
              {
              ModelDoc2 swDoc = null;
              ModelDocExtension swExt = null;
              DisplayStateSetting swDSS = null;
              object varStatus;
              object varTStatus;
              object varVStatus;
              Array statusArray;
              Array statusTArray;
              Array statusVArray;
              const int maxEntMode = 3;
            
              public void Main()
              {
              swDoc = (ModelDoc2)(swApp.ActiveDoc);
              swExt = swDoc.Extension;
              int docType = swDoc.GetType();
              if (docType == (int)swDocumentTypes_e.swDocASSEMBLY)
              {
              CreateDisplayStateSetting();
            
              varStatus = swExt.get_DisplayMode(swDSS);
              statusArray = (Array)varStatus;
            
              varTStatus = swExt.get_Transparency(swDSS);
              statusTArray = (Array)varTStatus;
            
              varVStatus = swExt.get_Visibility(swDSS);
              statusVArray = (Array)varVStatus; 
            
              WriteOutput();
              }
              }
            
              public void CreateDisplayStateSetting()
              {
              swDSS = swExt.GetDisplayStateSetting((int)swDisplayStateOpts_e.swThisDisplayState);
              swDSS.Option = (int)swDisplayStateOpts_e.swSpecifyDisplayState;
            
              string[] specDSNames = new string[2];
              specDSNames[0] = "DS_1";
              specDSNames[1] = "DS_2";
              object varSpecDSNames = specDSNames;
              swDSS.Names = varSpecDSNames;
            
              AssemblyDoc swADoc;
              swADoc = (AssemblyDoc)swDoc;
              int compCnt = swADoc.GetComponentCount(true);
              Component2[] listComp = new Component2[maxEntMode];
              if (compCnt >= maxEntMode)
              {
              object[] varComp = (object[])(swADoc.GetComponents(true));
              listComp[0] = (Component2)varComp[0];
              listComp[1] = (Component2)varComp[1];
              listComp[2] = (Component2)varComp[2];
              swDSS.Entities = listComp;
              }
            
              }
            }