12 Replies Latest reply on Feb 10, 2015 1:12 PM by David Dewey

    Sheet scale from view scale macro

    David Dewey

      I would like help in developing a macro to evaluate the views on a sheet, populate the sheet scale with the most common view scale, then change those view scales to match the sheet scales.

        • Re: Sheet scale from view scale macro
          Josh Brady

          What kind of "help" would you like?  Do you know how to write any macros now?

          • Re: Sheet scale from view scale macro
            Daniel Andersson

            I would approach it like this...

             

            You will need to use the ISheet and IView interface. Put each found scale into array or a collection and use a dimension (in array) or property in the collection to count the number of views that have matching scales.

            Then evaulte the most used scale and set the scale to the sheet(s).

            And finaly loop thru all the views once again and if the scale matches the set sheet scale, set the view to have scale from sheet.


            In the interfaces you find methods that will help you to get and set the data.

            ISheet::GetViews Method

            ISheet::SetScale Method

            IView::ScaleRatio Property

            IView::UseSheetScale Property

             

            These methods together with a array or collection could get and set the scales as you like for the views and sheets.

            See this example about how to loop thru all sheets and views. Do not mind the things going on with the notes.. in your case that would be the scale of the view.


            Just let me know if you need any further guidance.

              • Re: Sheet scale from view scale macro
                David Dewey

                I do know how to write and modify basic macros I have just not done anything with arrays to get all of the views on a given sheet, then do comparisons on which of those views has the highest common view scale. I think if I got to that point, I would be able to push that to sheet scale.

                 

                Examples work better for me than looking at the documentation... the example that was posted does help but I do not know how to do the count/comparison for the view scales.

                  • Re: Sheet scale from view scale macro
                    Josh Brady

                    Is this really that good of a macro to write?  What if you have one main 1:1 drawing view on a sheet, and then two detail views that are 2:1.  Do you really want the sheet scale to be changed to 2:1? How would you then designate the main view scale as 1:1 on the drawing sheet?

                      • Re: Sheet scale from view scale macro
                        David Dewey

                        I've looked at what we are trying to accomplish and this is what our needs are. Every single drawing has at least 4 main views and none have more than 2 detail views. I realize at your company things may not be this way, but for what my company needs this is the path we are going down. This is a manual process we are trying to do right now and this would be a time saver.

                      • Re: Sheet scale from view scale macro
                        Daniel Andersson

                        I modified an previous macro I had to do this... one thing that I do know is not working properly is that you will get wrong values if you have multiple sheets and the second or next coming sheet is empty of views. Then the macro will find all views in the drawing (they will have hidden status).

                        This is a behaviour that I have seen before. In this case the API does not only get the visible views... and for some reason views from other sheets gets into the array of views for the sheet. This is sorted out by checking if the view is visible or not on the current sheet. I guess that this is due to my lack of knowledge to handle the API correctly (or an fault in the API, have not looked deeper into that yet).

                         

                        Ah, almost forgot... what is the macro doing? Well, it will print out in the immediate window the number of views with scales and also the most used scale for each sheet.

                        Note that the loops in the macro use other methods than the previous example that I referenced earlier.

                         

                        There might be easier ways but the attached example is how I would have done it with the knowledge I have. I tried to comment it as good  I could. Have a look at it and let me know if you have any questions. Any ideas or comments from anyone is most welcome to improve the code.

                          • Re: Sheet scale from view scale macro
                            David Dewey

                            Thank you Daniel! This is much more than I would have hoped someone to help me with!

                             

                            I've gone forward and tried to set the sheet scale with the following:

                              

                            Dim boolstatus As Boolean

                            Dim currentSheet As Sheet

                            Dim Part As DrawingDoc

                            Dim TopSC As String

                            Dim BottomSC As String

                             

                            Set TopSC = lViewScale(1, iPos)

                            Set BottomSC = lViewScale(2, iPos)

                            boolstatus = currentSheet.SetScale(TopSC, BottomSC, True, False)

                             

                            It is throwing up a flag that says object required when I'm setting TopSC so I'm a little stuck. Any ideas?

                             

                            A vast majority of the drawings we are doing this to only have a single sheet... I'll poke around a bit and see what it does for a second sheet, but I think this should work for me if I can get the sheet scale updated.

                              • Re: Sheet scale from view scale macro
                                Daniel Andersson

                                The values shall not be strings that you put into the method SetScale. They should be of data type Double.

                                See 2014 SolidWorks API Help - SetScale Method (ISheet)  for details.

                                 

                                Set is used to assign a reference to object(s) in VBA and not to assign values/data to variables. This is one of the differences between VBA and VB.net.

                                Variables usually assigned just with = or directly returned in a method.

                                 

                                You could also skip the step with the TopSC and BottomSC if you like. The code would look like this.

                                Dim boolstatus As Boolean

                                Dim currentSheet As Sheet

                                Dim Part As DrawingDoc

                                 

                                boolstatus = currentSheet.SetScale(lViewScale(1, iPos), lViewScale(2, iPos), True, False)

                                 

                                But if you like to keep the TopSC and BottomSC it should look like this.

                                Dim boolstatus As Boolean

                                Dim currentSheet As Sheet

                                Dim Part As DrawingDoc

                                Dim TopSC As Double

                                Dim BottomSC As Double

                                 

                                TopSC = lViewScale(1, iPos)

                                BottomSC = lViewScale(2, iPos)

                                boolstatus = currentSheet.SetScale(TopSC, BottomSC, True, False)

                                Note that you also do not have to get a new object currentSheet since the current sheet in the macro I posted is possible to access with the swSheet.

                                I would recommend that you add the code above to the section where you find...

                                        Debug.Print "Most used scale: " & lViewScale(1, iPos) & ":" & lViewScale(2, iPos) & " [" & lViewScale(0, iPos) & " views]"

                                Then you wouldn't have to think of the Sheet and DrawingDoc objects since they are already assigned in the macro.

                                 

                                Hope that this explains what you see and that it brings you forward. Just let me know if you have any further questions.

                                1 person found this helpful
                        • Re: Sheet scale from view scale macro
                          David Dewey

                          While running this macro I've run into the following issue. When the view scales and sheet scales differ, and their are annotations attached to the views the annotations move. My best guess is that the following is coming up as a default. SHEET SCALE ANNOTATION POSITION.PNG Is there anyway to control this checkbox via API and uncheck it?