3 Replies Latest reply on Dec 1, 2017 3:16 AM by Fatih Mehmet Ozcan

    Macro for instance scale and lineweight

    Harry Butler

      Hi all,

      I'll be honest up front and confess that I know little about Macros other than using them. We get a reasonable amount of laser cutting and water jet cutting done and like most, our drawings are sent in DXF format at 1:1. I currently use a macro that creates a scan sheet and populates it with all the items from the detailing sheet that are destined for the cutting process, the only gripe I have is that the imported instances do not re-scale to the scan sheet scale (1:1) but rather they come in with the scale of the detailing sheet where they were detected ,i.e. 1:5 or 1:10 etc etc. I've attached the aforementioned macro in the hope that one of you learned folk might be kind enough to examine and update to include the scale adoption and line weight change. The desired line weight is 1/10 or .1mm. I've also attaché a screen shot of my scan page to show the as created instance (left) and the desired result after scaling and line weight changes (right).

       

      rgds

       

      Harry  

        • Re: Macro for instance scale and lineweight
          Fatih Mehmet Ozcan

          I don't have too much time so this is about only changing scale of a view.

          I tried change a view's scale with this macro. It searches for every sheet and multiple every views' scale by 2. This isn't complete but you can manipulate variables and produce different results

           

          Dim swApp As Object

          Sub main()

          Dim swmodel As SldWorks.ModelDoc2

          Dim swdraw As SldWrosk.DrawingDoc

           

          Set swApp = Application.SldWorks

          Set swmodel = swApp.ActiveDoc

          Set swdraw = swmodel

           

          Dim sh As SldWorks.Sheet

          Dim vi As SldWorks.View

          Dim vivs As Variant

          Dim shnames As Variant

           

          shnames = swdraw.GetSheetNames

           

          Dim say

          say = 0

           

          For i = 0 To UBound(shnames)

               vivs = swdraw.Sheet(shnames(i)).GetViews

              

          If say >= 1 Then GoTo saygec

          say = say + 1

           

               On Error Resume Next

               For k = 0 To UBound(vivs)

               Set vi = vivs(k)

               MsgBox vi.Name

               vi.ScaleDecimal = vi.ScaleDecimal * 2#

          Next

          saygec:

          Next

          End Sub

            • Re: Macro for instance scale and lineweight
              Harry Butler

              Thanks Fatih,

              Essentially I only need the views on the sheets named SCAN to the be re-scaled. Actually, to go back a step, it would be ideal if the views that are created on the SCAN sheet inherit the sheet scale which is 1:1 by default.

                • Re: Macro for instance scale and lineweight
                  Fatih Mehmet Ozcan

                  I made some changes

                  Only sheet with name "Scan" will be used and scale of views are update to be 1:1

                  You still you need to work on lineweight

                   

                  Dim swApp As Object

                  Sub main()

                  Dim swmodel As SldWorks.ModelDoc2

                  Dim swdraw As SldWrosk.DrawingDoc

                   

                  Set swApp = Application.SldWorks

                  Set swmodel = swApp.ActiveDoc

                  Set swdraw = swmodel

                   

                  Dim sh As SldWorks.Sheet

                  Dim vi As SldWorks.View

                  Dim vivs As Variant

                  Dim shnames As Variant

                   

                  shnames = swdraw.GetSheetNames

                   

                  Dim say

                  say = 0

                   

                  For i = 0 To UBound(shnames)

                      vivs = swdraw.Sheet(shnames(i)).GetViews

                   

                  If say >= 1 Then GoTo saygec

                  say = say + 1

                   

                  For i = 0 to UBound(shnames)

                   

                  If shnames(i) = "Scan" Then

                  vivs = swdraw.Sheet(shnames(i)).GetViews

                  If say>=1 Then GoTo saygec

                  say = say + 1

                   

                  For k = 0 To UBound(vivs)

                   

                  Set vi = vivs(k)

                  MsgBox vi.Name

                  vi.ScaleDecimal = 1

                  swmodel.EditRebuild3

                  swmodel.ForcaRebuild3 True

                  Next

                   

                  End If

                   

                  saygec:

                   

                  Next

                   

                  End Sub