8 Replies Latest reply on Mar 28, 2017 8:04 AM by Nick Gvk

    feature manager drawwing renaming macro

    Nick Gvk

      so i have been doing allot of work trying to convert drawwings

       

      the problem lays withing a few things

      i get drawings from china germany france and spain

      they all use their own language

       

      but the staff we work with dont speak any of these languages

      so they cant work with the drawings that are provided

      my job isnt converting every single file but desing new products

      unfortunaly converting these drawings has become a full time job

      as often the changes in my master drawwings that i send to these  company`s makes the "models items" button obsolete

      because most of the time they use and imported file instead of the .sldprt

       

       

      the problem :

      i get sldprt files in 3 different languages

      i get slddrw files in 3 different languages

       

       

      the solution i have so far :

       

      i run my lanuage change macro on the  .sldprt

      so  99% of all forgein language becomes english

       

      then i open the .slddrw

      and run this macro

       

      ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

      Dim swApp As Object

      Dim Part As Object

      Dim boolstatus As Boolean

      Dim longstatus As Long, longwarnings As Long

      Sub main()

      Set Part = swApp.ActiveDoc

      Set swApp = Application.SldWorks

      Set swModel = swApp.ActiveDoc

      If swModel Is Nothing Then

              MsgBox " Warning! No active drawing ! Select your drawing and try again"

              Exit Sub

      End If   

      If swModel.GetType <> swDocDRAWING Then

              MsgBox "Warning! No drawing Loaded ! Load / Open an drawing and try again"

              Exit Sub

      End If

      boolstatus = Part.SetupSheet5("Sheet1", 12, 12, 1, 1, False, "c:\programdata\solidworks\solidworks 2014\lang\english\sheetformat\A3FabricationSheet.slddrt", 0, 0, "Default", True)

      MsgBox "Successfully Changed the sheet format ! "

      End Sub

       

      ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

       

       

       

      after that i go and clean the drawwing up some more by removing actual text in the drawwing ( in the picture the nite with A-A)

       

      GqHAAJf.png

       

      what i like the macro to do is also change the names in the feauture manager

      to anything preferebly the normal names

      i tried running the macro to change the language

      but it only change the first 2

      and the macro above here already changes the second on to sheet1

       

       

       

      here is another example on the .sldprt

      multi language  with a ton of mistakes in it

      before

      WlS4CP9.png

      after

      8h4kdhw.png

       

       

      can anyone help me a little ? with doing the same thing but then for drawwings

        • Re: feature manager drawwing renaming macro
          Deepak Gupta

          Nick, just replied to your email.

           

          Replacing sheet format would be easy but would have to check for drawing feature manager. Could you share one file as example. May be you can email.

          • Re: feature manager drawwing renaming macro
            Nick Gvk

            so i have made some progress with some code

             

            here is what i have so far that seems to work

            i need to find out how to increment this instead of having it like this

            but it works kinda  as long as it does not have have less then 4 views

            anything over wont be incremented as of yet

             

            this macro wil also change the sheet format for u

            to the desired sheet of your choosing

            in future i wil make a check for it so it can find out wich size is being used on the sheet

             

            ' ******************************************************************************

            ' Macro to Load a Specified Sheet format writting by zundappchef on 22-9-2016

            ' Edited on 27-3-2017 it works much better now and u can choose your file location

            ' Also i started some code to change the drawing view names  it stil does not increment but its better then doing all of em by hand so far

            ' Change the file location name to your desired sheet format

            ' If the right conditions are not met the macro wil throw an error

            ' USE AT OWN RISK .Date loss or anything that might happen when using this macro we are not lyable for

            ' This Script/Macro is open source as long as u give us Credit www.zundappchef.com

            ' ******************************************************************************

             

             

            Dim swApp As Object

            Dim Part As Object

            Dim boolstatus As Boolean

            Dim longstatus As Long, longwarnings As Long

            Dim swDraw As SldWorks.DrawingDoc

            Dim swFeat As SldWorks.Feature

            Dim swView As SldWorks.View

            Dim SetNewName As String

            Dim IncrementCount As Object

            Dim FeatureTreeNames As Object

            Dim DrawingTreeNames As Object

             

             

            Sub main()

             

             

                Set IncrementCount = CreateObject("Scripting.Dictionary")

                Set FeatureTreeNames = CreateObject("Scripting.Dictionary")

                Set swApp = Application.SldWorks

                Set Part = swApp.ActiveDoc

                Set swApp = Application.SldWorks

                Set swModel = swApp.ActiveDoc

                Set swDraw = swApp.ActiveDoc

                Set swView = swDraw.GetFirstView

                Set swFeat = swDraw.FirstFeature

              

              

              

             

             

             

             

            ' This wil check if there is an drawing loaded and set as active

            ' It wil give u an error if any of these requirements isnt met

                If swModel Is Nothing Then

                    MsgBox " Warning! No active drawing ! Select your drawing and try again"

                    Exit Sub

                End If

              

                If swModel.GetType <> swDocDRAWING Then

                    MsgBox "Warning! No drawing Loaded ! Load / Open an drawing and try again"

                    Exit Sub

                End If

             

             

             

             

            ' this wil rename the feature manager

             

                While Not swFeat Is Nothing

                  

                    If IncrementCount.exists(swFeat.GetTypeName2()) Then

                        IncrementCount.Item(swFeat.GetTypeName2()) = IncrementCount.Item(swFeat.GetTypeName2()) + 1

                    Else

                        IncrementCount.Add swFeat.GetTypeName2(), 1

                    End If

                  

                    If FeatureTreeNames.exists(swFeat.GetTypeName2()) Then

                        SetNewName = FeatureTreeNames.Item(swFeat.GetTypeName2())

                    Else

                        SetNewName = swFeat.GetTypeName2()

                    End If

                  

                    SetNewName = SetNewName & IncrementCount.Item(swFeat.GetTypeName2())

                  

                    swFeat.Name = SetNewName

                  

                    Set swFeat = swFeat.GetNextFeature

                  

                Wend

            'this wil rename the feature tree drawing vieuws i stil need to make this increment

             

             

                swView.SetName2 ("Drawing View 0")

                Set swView = swView.GetNextView

                swView.SetName2 ("Drawing View 1")

                Set swView = swView.GetNextView

                swView.SetName2 ("Drawing View 2")

                Set swView = swView.GetNextView

                swView.SetName2 ("Drawing View 3")

                Set swView = swView.GetNextView

                swView.SetName2 ("Drawing View 4")

              

            ' i stil need to make and check to see what the original size of the sheet is

            ' or im going to make it so it wil give an warning and wil just close when its not the same size and i need to select another macro , for now im verry happen with this as its more easy then go and select it myself

             

            boolstatus = Part.SetupSheet5("Sheet1", 12, 12, 1, 1, False, "c:\programdata\solidworks\solidworks 2014\lang\english\sheetformat\a2nickgvk.slddrt", 0, 0, "Default", True)

             

            MsgBox "Successfully Changed Drawing View Names And The Sheet Format !"

            End Sub

             

             

            so far its already pretty user friendly but it can stil be improved allot

             

             

            if someone can improve or add code to this please go ahead

            but please leave some notes so i can see what i did wrong or why and how u did it  better

              • Re: feature manager drawwing renaming macro
                Peter Brinkhuis

                That's what loops are for This works for renaming all drawing views:

                 

                Dim i As Integer

                i = 1

                 

                Set swView = swDraw.GetFirstView

                'First view is sheet format

                Set swView = swView.GetNextView

                 

                While Not swView Is Nothing

                    swView.SetName2 ("Drawing View " & i)

                    Set swView = swView.GetNextView

                    i = i + 1

                Wend

                 

                The feature manager section of the code, that isn't necessary for drawings, is it? At the start you could check if a part or a drawing is open and then run the correct section.

                 

                I also suggest you add the Option Explicit line at the top to make sure all of your variables are defined and set the object types instead of just using objects. This will help you get the available methods for each type when you are typing and prevents incorrect assignments.

                 

                Option Explicit

                Dim swApp As SldWorks.SldWorks

                Dim Part As ModelDoc2

                Dim swModel As ModelDoc2

                  • Re: feature manager drawwing renaming macro
                    Nick Gvk

                    bedankt / thank u peter for your reply

                     

                    il go implement that code  after i understand why that works

                    and sofar it seems rather easy so i should be able to put my head around it pretty quick

                    the feature manager  code is neccesary

                    the first option called annotations need to be renamed

                    as wel as the material table if it has a assinged  material in the sldprt

                     

                    and  im making this macro so it wil only work for drawwings

                    but mayby in the feature ill make an if else statement

                    at this moment it checks if there is a drawing open and active if not it throws and error

                    is there something in this code that wil make it jump or jumpfalse like in assambly ?

                    so if the statement is met i can jump to code section 1 and if its false jump to code section 2

                     

                    i dont understand the importance of the option explicit yet

                     

                     

                     

                     

                    anyway this is what i have sofar

                    it renames everything in the feature manager

                    the only thing thats left to do is make it check what size the original size of the sheet is and then point it to the right one in the macro

                     

                    ' ******************************************************************************

                    ' Macro to Load a Specified Sheet format writting by zundappchef on 22-9-2016

                    ' Edited on 27-3-2017 it works much better now and u can choose your file location

                    ' Edited on 28-3-2017 it wil now rename the Feature tree manager

                    ' It wil aslo rename all drawing views and increment them , also it removes the sheet format and reload it

                    ' Change the file location name to your desired sheet format the code is all the way in the bottom

                    ' If the right conditions are not met the macro wil throw an error

                    ' USE AT OWN RISK .Date loss or anything that might happen when using this macro we are not lyable for

                    ' This Script/Macro is open source as long as u give us Credit www.zundappchef.com

                    ' ******************************************************************************

                     

                     

                    Dim swApp As Object

                    Dim Part As Object

                    Dim boolstatus As Boolean

                    Dim longstatus As Long

                    Dim longwarnings As Long

                    Dim Delete As Long

                    Dim swDraw As SldWorks.DrawingDoc

                    Dim swFeat As SldWorks.Feature

                    Dim swView As SldWorks.View

                    Dim Sheet As SldWorks.Sheet

                    Dim DrwFormat As Feature

                    Dim SetNewName As String

                    Dim IncrementCount As Object

                    Dim FeatureTreeNames As Object

                    Dim DrawingTreeNames As Object

                     

                    Sub main()

                        Set IncrementCount = CreateObject("Scripting.Dictionary")

                        Set FeatureTreeNames = CreateObject("Scripting.Dictionary")

                        Set swApp = Application.SldWorks

                        Set Part = swApp.ActiveDoc

                        Set swApp = Application.SldWorks

                        Set swModel = swApp.ActiveDoc

                        Set swDraw = swApp.ActiveDoc

                        Set swView = swDraw.GetFirstView

                        Set swFeat = swDraw.FirstFeature

                        Set swView = swView.GetNextView

                        Set swForm = Part.FirstFeature

                       

                        Dim i As Integer

                        i = 1

                       

                    ' This wil check if there is an drawing loaded and set as active

                    ' It wil give u an error if any of these requirements isnt met

                        If swModel Is Nothing Then

                            MsgBox " Warning! No active drawing ! Select your drawing and try again"

                            Exit Sub

                        End If   

                        If swModel.GetType <> swDocDRAWING Then

                            MsgBox "Warning! No drawing Loaded ! Load / Open an drawing and try again"

                            Exit Sub

                        End If

                    ' This wil remove the sheet format so it can reload the sheet at the end of the macro

                        Do

                        If swForm.GetTypeName = "DrSheet" Then

                        Set Sheet = swForm.GetSpecificFeature2

                        Set DrwFormat = Part.FeatureByName(Sheet.GetSheetFormatName)

                        If Not DrwFormat Is Nothing Then

                            DrwFormat.Select (False)

                            Delete = Part.DeleteSelection(False)

                        End If

                        End If

                        Set swForm = swForm.GetNextFeature

                        Loop While Not swForm Is Nothing

                     

                    ' This wil rename the feature manager to original names

                      

                        While Not swFeat Is Nothing       

                            If IncrementCount.exists(swFeat.GetTypeName2()) Then

                                IncrementCount.Item(swFeat.GetTypeName2()) = IncrementCount.Item(swFeat.GetTypeName2()) + 1

                            Else

                                IncrementCount.Add swFeat.GetTypeName2(), 1

                            End If       

                            If FeatureTreeNames.exists(swFeat.GetTypeName2()) Then

                                SetNewName = FeatureTreeNames.Item(swFeat.GetTypeName2())

                            Else

                                SetNewName = swFeat.GetTypeName2()

                            End If       

                            SetNewName = SetNewName & IncrementCount.Item(swFeat.GetTypeName2())       

                            swFeat.Name = SetNewName       

                            Set swFeat = swFeat.GetNextFeature       

                        Wend   

                    ' This wil rename the  Drawing View`s in the Feature Tree and increments them until there are no more view`s in the loop

                        While Not swView Is Nothing   

                            swView.SetName2 ("Drawing View " & i)

                            Set swView = swView.GetNextView

                            i = i + 1       

                        Wend 

                     

                    ' i stil need to make and check to see what the original size of the sheet is

                    ' or im going to make it so it wil give an warning and wil just close when its not the same size and i need to select another macro , for now im verry happen with this as its more easy then go and select it myself

                     

                    boolstatus = Part.SetupSheet5("Sheet1", 12, 12, 1, 1, False, "c:\programdata\solidworks\solidworks 2014\lang\english\sheetformat\a2nickgvk.slddrt", 0, 0, "Default", True)

                     

                    MsgBox "Successfully Reloaded the Feature Tree Manager Names and The Sheet Format ! Compliments of Zundappchef"

                     

                    End Sub