10 Replies Latest reply on Apr 26, 2016 11:53 AM by Kevin Chisholm

    Set the Named Display State for Drawing View

    Stephen Potter

      Hello, I am building an addin and part of it creates a new drawing with various views of a model.  When you create a drawing view, the property manager has a  "Display State" group thatlists all the available display states (as provided by the configuration).  I have scoured the API, looking especially at IDrawingDoc, IView, and IModelView but nothing allows me to specify a display state.  Please refer to the attached screenshot that highlights this in a red outline.


      I haven't found an API for this but it's easily editable in SW.  In addition to the Property Manager Page, you can also right click on a view and choose Properties, which will show a dialog box that lets you choose the Display State.


      Also, is there an API for the "High Quality" vs "Draft" setting in the Display Style group box?  It's also highlighted on the screenshot.


      Thank you!

        • Re: Set the Named Display State for Drawing View
          Kevin Chisholm

          Not sure if this can help you out...?


          2015 SOLIDWORKS API Help - Get Display State Settings Example (VBA)


          Didn't see anything about the Display Style High Quality vs Draft...


          Edit... Missed this line here!


          2014 SOLIDWORKS API Help - swDisplayMode_e Enumeration

            • Re: Set the Named Display State for Drawing View
              Stephen Potter

              Thanks Kevin, that got me on the right track.  I just recorded a macro and set the document settings and copied the results from the macro.  Here's what did it:

                          var drawingDoc = (IModelDoc2)App.NewDocument(@"C:\ProgramData\SolidWorks\SOLIDWORKS 2016\templates\Drawing.drwdot", 2, 0.2794, 0.431);

                          var drawing = (IDrawingDoc)drawingDoc;

                          drawingDoc.SetUserPreferenceIntegerValue((int)swUserPreferenceIntegerValue_e.swHiddenEdgeDisplayDefault, (int)swDisplayMode_e.swSHADED);

                          drawingDoc.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swDrawingsDefaultDisplayTypeHLREdgesWhenShaded, true);

                          drawingDoc.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swEdgeQualityShadedEdgeViews, true);

                          drawingDoc.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swDrawingsDefaultDisplayTypeHLREdgesWhenShaded, true);


              That's only part of my problem though.  The second part is setting the display state for a view.  I can get the configuration changed via ChangeRefConfigurationOfFlatPatternView, but nothing with display state. 

                • Re: Set the Named Display State for Drawing View
                  Kevin Chisholm

                  Not sure to understand your second problem...


                  You set a view to the flat pattern configuration then you want to set the display

                  state of that view?


                  Option Explicit

                  Dim swApp As SldWorks.SldWorks

                  Dim swModel As SldWorks.ModelDoc2

                  Dim swDrawing As SldWorks.DrawingDoc

                  Dim swSheet As SldWorks.Sheet

                  Dim swView As SldWorks.View

                  Dim ViewToSelect As SldWorks.View

                  Dim bRet As Boolean


                  Sub mMain()


                  Set swApp = Application.SldWorks

                  Set swModel = swApp.ActiveDoc

                  Set swDrawing = swModel


                  Set swSheet = swDrawing.GetCurrentSheet

                  Set swView = swDrawing.GetFirstView

                  Set swView = swView.GetNextView


                  While Not swView Is Nothing

                      If swView.IsFlatPatternView = True Then

                         Set ViewToSelect = swView

                     End If

                  Set swView = swView.GetNextView



                  bRet = ViewToSelect.SetDisplayMode3(False, swSHADED, True, True)


                  End Sub


                  This shades the flat pattern view...

                  Again, not sure what you are looking to do!

              • Re: Set the Named Display State for Drawing View
                Simon Turner

                'Macro to convert view to Draft quality


                Dim swApp As SldWorks.SldWorks

                Dim Part As ModelDoc2

                Dim myView As View


                Sub main()

                    Dim selMgr As SelectionMgr

                    Dim isUseParent As Boolean

                    Dim isEdges As Boolean

                    Dim j As Long


                    Set swApp = Application.SldWorks

                    Set Part = swApp.ActiveDoc

                    Set selMgr = Part.SelectionManager

                    If selMgr.GetSelectedObjectCount2(-1) = 0 Then Exit Sub


                    Set myView = selMgr.GetSelectedObjectsDrawingView2(1, -1)

                    If myView Is Nothing Then Exit Sub


                    isUseParent = myView.GetUseParentDisplayMode

                    isEdges = myView.GetDisplayEdgesInShadedMode

                    If myView.GetFacettedHlrDisplay Then

                        j = myView.GetDisplayMode2

                        myView.SetDisplayMode3 isUseParent, j, False, isEdges

                    End If


                    myView.SetDisplayMode3 False, swDisplayMode_e.swFACETED_HIDDEN, True, True

                End Sub