9 Replies Latest reply on Dec 4, 2015 12:17 PM by Viswa Bhuvan

    Rename drawing views

    Hrituc Alexandru

      Hi,

           I try to create a macro to rename drawing views but not anyway...

      If a drawing view contain a front view, the drawing view name = FRONT and so on...

      1.jpg

      If a drawing views contain flat pattern view then drawing view name = UNFOLDED;

      2.jpg

      and result:

      2.jpg

      or if it's not possible, even for unfolded view:

      2.jpg

                     Thanks

        • Re: Rename drawing views
          Deepak Gupta

          I'm not sure or don't thin it is possible about the other views, specially projected views as how to get information if they're left or right side views but for Flat Pattern view, try the attached macro.

            • Re: Rename drawing views
              Hrituc Alexandru

              i write this but work only in first page...

              how can make it to run in all pages?

              '''''''''''''''''''''''

              Option Explicit

              Dim swApp As SldWorks.SldWorks

              Dim swModel As SldWorks.ModelDoc2

              Dim swView As SldWorks.View

              Dim swDrwDoc As SldWorks.DrawingDoc

              Dim swsheet As SldWorks.Sheet

              Dim shtname(100) As Variant 'SHEET NAMES

              Dim a, shno, i As Integer

              Dim retval As Boolean

              Dim Drawview(100) As String

               

               

              Sub main()

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Set swDrwDoc = swModel

               

               

              shno = 0

              i = 0

              shno = swDrwDoc.GetSheetCount

               

               

              For a = 0 To (shno - 1) Step 1

              shtname(a) = swDrwDoc.GetSheetNames(a)

              Next

               

               

              For a = 0 To (shno - 1) Step 1

              retval = swDrwDoc.ActivateSheet(shtname(a))

              Set swsheet = swDrwDoc.GetCurrentSheet

               

               

              Set swView = swDrwDoc.GetFirstView

              Set swView = swView.GetNextView

              i = 1

              Do While Not swView Is Nothing

              Drawview(i) = "View " & i

              retval = swView.SetName2(Drawview(i))

              i = i + 1

              Set swView = swView.GetNextView

              Loop

               

               

                  Set swView = swModel.GetFirstView

                  Set swView = swView.GetNextView

              While (Not swView Is Nothing)

                      If swView.IsFlatPatternView Then

                          swModel.Extension.SelectByID2 swView.GetName2, "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0

                          swView.SetName2 ("Unfolded")

                          swModel.ClearSelection2 True

                      End If

                      Set swView = swView.GetNextView

                Wend

              Next

              End Sub

              '''''''''''''''''''''''''''''''''''''''''''''''''

                • Re: Rename drawing views
                  Digvijay Taunk
                  Sub main()
                      Set swApp = Application.SldWorks
                      Set swModel = swApp.ActiveDoc
                      Set swDrwDoc = swModel
                      
                      
                      shno = 0
                      i = 0
                      shno = swDrwDoc.GetSheetCount
                      
                      
                      For a = 0 To (shno - 1) Step 1
                          shtname(a) = swDrwDoc.GetSheetNames(a)
                      Next
                      
                      i = 1
                      For a = 0 To (shno - 1) Step 1
                          retval = swDrwDoc.ActivateSheet(shtname(a))
                          Set swsheet = swDrwDoc.GetCurrentSheet
                          
                          
                          Set swView = swDrwDoc.GetFirstView
                          Set swView = swView.GetNextView
                         
                          Do While Not swView Is Nothing
                              Drawview(i) = "View " & i
                              Debug.Print swView.Name
                              retval = swView.SetName2(Drawview(i))
                              i = i + 1
                              Set swView = swView.GetNextView
                          Loop
                          
                          
                          Set swView = swModel.GetFirstView
                          Set swView = swView.GetNextView
                          While (Not swView Is Nothing)
                              If swView.IsFlatPatternView Then
                                  swModel.Extension.SelectByID2 swView.GetName2, "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0
                                  swView.SetName2 ("Unfolded")
                                  swModel.ClearSelection2 True
                              End If
                              Set swView = swView.GetNextView
                          Wend
                      Next
                  End Sub
                  

                   

                  Just moved i=1 from line no.24 to line 16. Reason is the drawing view name should be unique throughout drawing file. Same view name should not be used in different sheets.

                   

                  So I guess your main purpose of renaming views as per there orientation is not possible as 2 "Front View" name is not possible in each sheet.

                    • Re: Rename drawing views
                      Hrituc Alexandru

                      If I consider that on each page is one view with flat pattern, where should be introduced:

                      1.   While (Not swView Is Nothing) 
                      2.             If swView.IsFlatPatternView Then 
                      3.                 swModel.Extension.SelectByID2 swView.GetName2, "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0 
                      4.                 swView.SetName2 ("Unfolded") 
                      5.                 swModel.ClearSelection2 True

                      ???

                       

                          • Re: Rename drawing views
                            Hrituc Alexandru

                            Thanks    Digvijay Taunk 

                            Thanks    Deepak Gupta

                             

                            It goes perfectly with your help...

                             

                            Option Explicit

                            Dim swApp As SldWorks.SldWorks

                            Dim swModel As SldWorks.ModelDoc2

                            Dim swView As SldWorks.View

                            Dim swDrwDoc As SldWorks.DrawingDoc

                            Dim swsheet As SldWorks.Sheet

                            Dim shtname(100) As Variant 'SHEET NAMES

                            Dim a, shno, i As Integer

                            Dim retval As Boolean

                            Dim Drawview(100) As String

                             

                             

                             

                             

                            Sub main()

                                Set swApp = Application.SldWorks

                                Set swModel = swApp.ActiveDoc

                                Set swDrwDoc = swModel

                                 

                                 

                                shno = 0

                                i = 0

                                shno = swDrwDoc.GetSheetCount

                                 

                                 

                                For a = 0 To (shno - 1) Step 1

                                    shtname(a) = swDrwDoc.GetSheetNames(a)

                                Next

                                 

                                i = 1

                                For a = 0 To (shno - 1) Step 1

                                    retval = swDrwDoc.ActivateSheet(shtname(a))

                                    Set swsheet = swDrwDoc.GetCurrentSheet

                                   

                                        Set swView = swDrwDoc.GetFirstView

                                        Set swView = swView.GetNextView

                                    Do While Not swView Is Nothing

                                        Drawview(i) = "View " & i

                                        Debug.Print swView.Name

                                        retval = swView.SetName2(Drawview(i))

                                        i = i + 1

                                        Set swView = swView.GetNextView

                                   Loop

                               

                            Next

                             

                             

                            FlatPattern

                             

                             

                            End Sub

                             

                             

                             

                             

                            Private Sub FlatPattern()

                             

                             

                                Dim swApp                   As SldWorks.SldWorks

                                Dim swModel                 As SldWorks.ModelDoc2

                                Dim swDraw                  As SldWorks.DrawingDoc

                                Dim swView                  As SldWorks.View

                                Dim i                       As Integer

                                Dim j                       As Integer

                                Dim vSheetName              As Variant

                             

                             

                             

                             

                                Set swApp = Application.SldWorks

                                Set swModel = swApp.ActiveDoc

                               

                                If swModel Is Nothing Then

                                MsgBox "Open a Drawing with Flat Pattern View"

                                End

                                End If

                               

                                If swModel.GetType <> 3 Then

                                MsgBox "Open a Drawing with Flat Pattern View"

                                End

                                End If

                               

                                Set swDraw = swModel

                                vSheetName = swDraw.GetSheetNames

                                swDraw.ActivateSheet (vSheetName(0))

                               

                                i = 1

                               

                                For j = 0 To UBound(vSheetName)

                                swDraw.ActivateSheet (vSheetName(j))

                              

                                Set swView = swDraw.GetFirstView

                                Set swView = swView.GetNextView

                               

                                While (Not swView Is Nothing)

                                    If swView.IsFlatPatternView Then

                                        swModel.Extension.SelectByID2 swView.GetName2, "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0

                                        swView.SetName2 ("UNFOLDED-" & i)

                                        swModel.ClearSelection2 True

                                    End If

                                    Set swView = swView.GetNextView

                                Wend

                               

                                i = i + 1

                              

                                Next j

                               

                               

                            End Sub

                  • Re: Rename drawing views
                    Digvijay Taunk

                    From View.Type you can get whether it is a Named view(Standard view) or Projected view. For Named view you can use GetOrientationName method to get the predefined name(e.g. *Front, *Top, etc.). but it return blank for projected or unfolded view.

                     

                    IsFlatPatternView will give you if it is a flat pattern.

                    • Re: Rename drawing views
                      Viswa Bhuvan

                      Sir,

                       

                      Can i have your suggestion of how to convert solidworks sheetmetal 2012 to dxf