Drawing View Scaling C# Inventor API

Drawing View Scaling C# Inventor API

ianjwellings
Contributor Contributor
941 Views
2 Replies
Message 1 of 3

Drawing View Scaling C# Inventor API

ianjwellings
Contributor
Contributor

Hi,

Can anyone please help me with this?

I have a number of drawings with anything up to 4 views.

Every time I change the dimensions of the 3D models to be larger or smaller and reopen the drawings the views are either much larger than the size of the sheet or too small to be seen so I have to manually update the scale of the views.

Is there a way using C# and the Inventor API that I can automatically increase or decrease the scaling of the views to fit the drawing sheet?

0 Likes
942 Views
2 Replies
Replies (2)
Message 2 of 3

JamieVJohnson2
Collaborator
Collaborator

You may be able to get this routine I use to work for you (but I won't be sharing my FeetInchToDecimalInch conversion tool):

 Public Sub ReduceScaleToFit(ByRef view As DrawingView, ByRef strStartScale As String, Optional ByRef maxWidthInch As Double = Nothing, Optional ByRef maxHeightInch As Double = Nothing)
        Dim dwgDoc As Inventor.DrawingDocument = view.Parent.Parent
        Dim scales() As String = dwgDoc.StylesManager.ActiveStandardStyle.PresetScales
        Dim booScaleFound As Boolean = False
        If maxWidthInch <> Nothing Then
            If view.Width > maxWidthInch * 2.54 Then
                Dim modWidth As Double = view.Width / view.Scale / 2.54
                booScaleFound = False
                For i As Integer = scales.Count - 1 To 0 Step -1
                    Dim strSplit() As String = scales(i).Split("=")
                    Dim top As Double = FeetInchToDecimalInch(strSplit(0))
                    Dim bot As Double = FeetInchToDecimalInch(strSplit(1))
                    If top / bot * modWidth < maxWidthInch Then
                        strStartScale = scales(i)
                        booScaleFound = True
                        Exit For
                    End If
                Next
                If booScaleFound = False Then
                    'force a scale to fit view on page
                    Dim intBottom As Integer = CInt((modWidth / maxWidthInch) + 1)
                    strStartScale = "1/" & intBottom.ToString
                End If
            End If
        End If
        view.ScaleString = strStartScale 'set the width scale first, and then check if it is too tall second.
        If maxHeightInch <> Nothing Then
            If view.Height > maxHeightInch * 2.54 Then
                Dim modHeight As Double = view.Height / view.Scale / 2.54
                booScaleFound = False
                For i As Integer = scales.Count - 1 To 0 Step -1
                    Dim strsplit() As String = scales(i).Split("=")
                    Dim top As Double = FeetInchToDecimalInch(strsplit(0))
                    Dim bot As Double = FeetInchToDecimalInch(strsplit(1))
                    If top / bot * modHeight < maxHeightInch Then
                        strStartScale = scales(i)
                        booScaleFound = True
                        Exit For
                    End If
                Next
                If booScaleFound = False Then
                    'force a scale to fit view on page
                    Dim intBottom As Integer = CInt((modHeight / maxHeightInch) + 1)
                    strStartScale = "1/" & intBottom.ToString
                End If
            End If
        End If
        view.ScaleString = strStartScale
        If booScaleFound = False Then
            view.ShowScale = True
            view.ShowName = True
            view.ShowLabel = True
        End If
    End Sub

So I use this routine to verify if the view is within a set of space limits (inch math on our drawings so you see conversion from centimeter to inch a lot).  The FeetInch converter simply understands that 1'-0 1/4" = 12.25, but mine is custom built for the company and very complex.  This program reads the scales in the document and only uses them, but you can actually use ANY scale ratio you want.

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 3 of 3

nebi_guler
Enthusiast
Enthusiast
 Public Sub ReduceScaleToFit(ByRef view As DrawingView, ByRef strStartScale As String, Optional ByRef maxWidthInch As Double = Nothing, Optional ByRef maxHeightInch As Double = Nothing)

I didn't fully understand . Can you explain  maxWidthInch and  maxHeightInch enter information ? What information will I use for maxWidthInch and maxHeightInch?

0 Likes