8 Replies Latest reply on Oct 11, 2016 9:37 AM by Daniel Nesthus

    API to rescale entire drawing according to a view for 1:1 export

    Daniel Nesthus

      I have some great API examples to export a Solidworks drawing to dxf or dwg files which I use a lot of; however I sometimes need to export so the model itself is 1:1.

       

      I have the code to select a specific view and read it's scale (say 1:3).  What I want to do is to either set the export options to 1:1 and use the proper drawing view scale (like the manual method in the picture) or somehow scale the entire sheet UP to effectively make the main view at 1:1.  Is this a pipe dream or are there some methods I can't find?

       

      API Export Options.jpg

        • Re: API to rescale entire drawing according to a view for 1:1 export
          Deepak Gupta

          Sorry no API for setting base scale, vote for SPR # 190359

           

          Create a new sheet and paste that view on that sheet with scale set to 1:1 and export DXF. And then delete that sheet. All this can be done via macro.

            • Re: API to rescale entire drawing according to a view for 1:1 export
              Daniel Nesthus

              Thanks Deepak, I hadn't thought of that.  I will work on it.

                • Re: API to rescale entire drawing according to a view for 1:1 export
                  Dariusz Karcz

                  Although I'm a great fan of Deepak work, hes answer is not right.

                   

                  There is no need to have base scale, there is no need to insert new sheet with 1:1 scale !!

                   

                  Thru simple calculation, you can make that exported drawing view(s) will be always in 1:1 scale . Base idea is:

                   

                  dDXFScaleFactor = SwViewScale * (scale1 / scale2) * (1 / (SwViewScale * (scale1 / scale2))) * (1 / SwViewScale)

                   

                  where:

                  scale1 and scale2 are sheet properties (sheet scale)

                  SwViewScale is view scale in decimal setting

                   

                  Then you need to set:

                  swApp.SetUserPreferenceDoubleValue(swDxfOutputScaleFactor, dDXFScaleFactor)

                   

                  All Views that have the same scale as the one used for calcucation of formula above will be exported in 1:1 rest of it will be exported in other scales.

                  I am just adding note to DXF that only main views are scaled 1:1, others should be checked before use by autocad user.

                   

                  Some time ago, I did have same problem as you, I've looked for few days in different forums about answer and nothing, and it was so simple!!

                  You need to have number that multiplied by sheetscale * viewscale will give you 1. Then just some tool to set dxfoutputscale, and because SW is using one in window that you showed us in your print screen, there should be some kind of settings to set is, and voila. Its the Answer.

                    • Re: API to rescale entire drawing according to a view for 1:1 export
                      Deepak Gupta

                      Dariusz there can be various ways to do a same. I just added the suggestion/idea that I had used already and was working perfectly.

                      • Re: API to rescale entire drawing according to a view for 1:1 export
                        Daniel Nesthus

                        Dariusz,

                         

                        So close!  I can set the Output Scale (and read it back) however all of the save types I have tried don't result in an actual 1:1 scaled dwg.

                         

                        What save style have you used?

                          • Re: API to rescale entire drawing according to a view for 1:1 export
                            Dariusz Karcz

                            Daniel,

                            last two lines of code:

                             

                            bool = swApp.SetUserPreferenceDoubleValue(swDxfOutputScaleFactor, dDXFScaleFactor)

                            bool = swModel.SaveAs4(SwOpenPath & ".dxf", 0, 1, errors, Warnings)

                             

                            where

                             

                            SwOpenPath = Left(swModel.GetPathName, InStr(swModel.GetPathName, ".") - 1)  'Set Path before ".extension in file name"

                             

                            BTW: you will have 1:1 scale in views that have same scale as one selected for whole process, rest of views will have different scales (for example, your main views are front, bottom and top view + detail view (with different scale), you are probing first view in drawing sheet, then its your base scale (front in this example), all three main views will be exported in 1:1 (detail view will be exported in different scale).

                             

                            =======================

                            I see now, that initially I was wrong, whole calculation line can be written as 1/SwViewScale. So there is no number that makes 1 in dDXFScaleFactor, just some other number that comes from 1/SwViewScale.

                            =======================

                            Set you view scale to 0.25

                            Set you sheetScale to 0.2

                            dDXFScaleFactor should be 4

                             

                            All views with scale 0.25 will be exported as 1:1, other view will have own scale. Try it, tell me please whats the result.

                            ======

                            Sorry for the confusion, i written this macro 6 months ago, did forget some of it already

                              • Re: API to rescale entire drawing according to a view for 1:1 export
                                Daniel Nesthus

                                Ok, I found the problem. The 'Scale Output 1:1' HAS to be enabled in the Export Options to force the SaveAs to use ANY revised scaling.

                                 

                                I did notice the first part of the calculation line always resolved to 1.  I am going to add a message box to my macro to choose to use a 1:1 scale based on the view or to use whatever the sheet scale is.  That way we either get 1:1 models or we get the standard sheet size that has been set up.

                                 

                                Thanks for the help!

                                 

                                For future reference...

                                 

                                SwViewScale = swView.ScaleDecimal

                                dDXFScaleFactor = (1 / SwViewScale)

                                 

                                swApp.SetUserPreferenceDoubleValue(swDxfOutputScaleFactor, dDXFScaleFactor)

                                swModel.SaveAs4(NewFilePath, swSaveAsCurrentVersion, swSaveAsOptions_Silent, 0, 0)

                                 

                                where NewFilePath includes the .DWG or .DXF extension.

                                 

                                Like you said, this will only produce a 1:1 for the views that match the SwViewScale, which, in this case for us, will always be the same.