How do I retrieve the active scale of a sheet?

Hello

Despite my various searches on the forum and on the internet I can't find what I want... hence my question

The purpose of my macro is to save a Solidworks drawing in several formats for archiving and in particular the DXF format for laser cutting.

To make sure my DXF is good, I'd like to make sure that the scale is 1:1. How to do it?

I have figured out how to change the scale but I would like to warn the user that his scale must be changed to avoid errors.

To be more precise, I would like to do a test like: if scale = 1:1 then continue or stop

Thank you for your help! The VBA programming under solidwoks is still not very readable...

Good evening

Normally by searching for swView. ScaleRatio in the API help it should meet the need.

Hello

If you generate the DXF from the 3d it always comes out at scale 1 and it's if you take your DXF out of the MEP that the scale is sometimes messed up...

Otherwise we have a great complement to output the files as laser cutting files:

https://www.youtube.com/watch?v=q9CZfkYpyE0

http://www.topsworks.de/en/why-topsworks/topsworks-and-solidworks/

http://solidworks.fr/sw/products/details.htm?productid=4329

2 Likes

Hello

Here's a macro that works smoothly. It runs from 3D and will always output a DXF at 1:1 scale

Used every day with us and no problem.

A++

 


saveas_dxf.swp
3 Likes

Hello

You have to raise the scale then, if it is different from 1:1, then stop in C# it looks like this:

            ModelDoc2 swDoc = (ModelDoc2)Program.swapp. ActiveDoc;
            DrawingDoc swDraw;
            Sheet swSheet;
            swDraw = ((DrawingDoc)(swDoc));
            swSheet = (Sheet)swDraw. GetCurrentSheet();
            object vSheetProps = null;
            double PaperSize = 0;
            double TemplateIn = 0;
            double Scale1 = 0;
            double Scale2 = 0;
            double FirstAngle = 0;
            double width = 0;
            double height = 0;

            vSheetProps = swSheet. GetProperties();
            double[] formatProp = (double[])vSheetProps;
            
            PaperSize = System. Math. Round(formatProp[0]);
            TemplateIn = formatProp[1];
            Scale1 = formatProp[2];
            Scale2 = formatProp[3];
            FirstAngle = formatProp[4];
            width = formatProp[5];
            height = formatProp[6];
            
            if ((int)Scale1 != 1 | (int) Scale2 != 1)
            {
                return;
            }

All that's left to do is translate it into VBA, a language I don't master, so I'll let you do it.

Kind regards

Hello

 

By taking pieces of the answer from each of your comments, I managed to solve my problem and thank you!

 

The corresponding part of the côde is as follows:

Dim swApp               As Object
Dim Part                As SldWorks.ModelDoc2
Dim swView              As SldWorks.View
Dim swModExt            As SldWorks.ModelDocExtension
Dim swPathDir           As String
Dim swPath              As String
Dim echf                As Variant 'The sheet scale will be stored in fraction format (a:b)
Dim echV1               As Variant 'The scale of view 1 will be stored in fraction (a:b) format
Dim Rep                 As Variant 'For MsgBox Storage

Sub RegistrationDXFPDF()

Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc


'------------ Retrieving Information (1)
    Set swModExt = Part.Extension
    Set Prop = swModExt.CustomPropertyManager("")

    Set swView = Part.GetFirstView ' the first view being the
    echf = swView.ScaleRatio ' scale retrieval
    Set swView = swView.GetNextView 'Switching to First Sight
    echV1 = swView.ScaleRatio ' Scale Retrieve
    Coin recovery
    Set swModel = swView.ReferencedDocument
    Set swModExt = swModel.Extension
   
'------------ Security Checks
    '--Checking the scale of the sheet--
    If echf(0) <> "1" Or echf(1) <> "1" Then
        Rep = MsgBox("Attention, the scale of the sheet is " & echf(0) & ":" & echf(1) & vbCrLf & _
        "Do you want to continue?", vbYesNo, "Dxf Pdf Recording")
        If Rep = vbNo Then Exit Sub
    End If
    '--Verification of the scale of the view--
    If echV1(0) <> "1" Or echV1(1) <> "1" Then
        Rep = MsgBox("Attention, the scale of the view is " & echV1(0) & ":" & echV1(1) & vbCrLf & _
        "Do you want to continue?", vbYesNo, "Dxf Pdf Recording")
        If Rep = vbNo Then Exit Sub
    End If

End Sub