Scale inventor drawing views automaticly and ISO views specifly

Scale inventor drawing views automaticly and ISO views specifly

morrenengineering
Contributor Contributor
452 Views
2 Replies
Message 1 of 3

Scale inventor drawing views automaticly and ISO views specifly

morrenengineering
Contributor
Contributor

Hi,

 

The code below, I have made to make al the drawing views at an fittable scale. In another code it works, but I want the ISO view about half the scale of the normal views. The code below gives a fault, can someone help me to fix it?

 

 

Dim oDrawingDoc As DrawingDocument = ThisApplication.ActiveDocument 
Dim oSheet As Sheet = oDrawingDoc.Sheets.Item(1)
Dim oView As DrawingView = oSheet.DrawingViews.Item(1)	
Dim oDMDef As ComponentDefinition = oView.ReferencedDocumentDescriptor.ReferencedDocument.ComponentDefinition
Dim oWidth As Double =Abs(oDMDef.RangeBox.MaxPoint.Y - oDMDef.RangeBox.MinPoint.Y)*10
Dim oLength As Double= Abs(oDMDef.RangeBox.MaxPoint.X - oDMDef.RangeBox.MinPoint.X)*10
Dim oHeight As Double=Abs(oDMDef.RangeBox.MaxPoint.Z - oDMDef.RangeBox.MinPoint.Z) * 10
Dim oMaxLength As Double= Max(Max(oLength,oWidth),oHeight)
Dim oScale As String

Dim oView As DrawingView
For Each oView In oViews

If oMaxLength < 5000 Then
	Dim orientype As ViewOrientationTypeEnum
	orientype = oView.Camera.ViewOrientationType
	If  orientype = 10756 Or orientype = 10757 Or orientype = 10764 Or orientype = 10758 Or orientype = 10755 Or orientype = 10754 Then
	oScale = "1 : 50"
	End If
	If orientype = 10763 Or orientype = 10762 Or orientype = 10761 Or orientype = 10760 Or orientype = 10759  Then
	oScale = "1 : 100"
	End If
End If

If oMaxLength < 2500 Then
	Dim orientype As ViewOrientationTypeEnum
	orientype = oView.Camera.ViewOrientationType
	If  orientype = 10756 Or orientype = 10757 Or orientype = 10764 Or orientype = 10758 Or orientype = 10755 Or orientype = 10754 Then
	oScale = "1 : 20"
	End If
	If orientype = 10763 Or orientype = 10762 Or orientype = 10761 Or orientype = 10760 Or orientype = 10759  Then
	oScale = "1 : 50"
	End If
End If

If oMaxLength < 2500 Then
	Dim orientype As ViewOrientationTypeEnum
	orientype = oView.Camera.ViewOrientationType
	If  orientype = 10756 Or orientype = 10757 Or orientype = 10764 Or orientype = 10758 Or orientype = 10755 Or orientype = 10754 Then
	oScale = "1 : 10"
	End If
	If orientype = 10763 Or orientype = 10762 Or orientype = 10761 Or orientype = 10760 Or orientype = 10759  Then
	oScale = "1 : 20"
	End If
End If

If oMaxLength < 1250 Then
	Dim orientype As ViewOrientationTypeEnum
	orientype = oView.Camera.ViewOrientationType
	If  orientype = 10756 Or orientype = 10757 Or orientype = 10764 Or orientype = 10758 Or orientype = 10755 Or orientype = 10754 Then
	oScale = "1 : 5"
	End If
	If orientype = 10763 Or orientype = 10762 Or orientype = 10761 Or orientype = 10760 Or orientype = 10759  Then
	oScale = "1 : 2"
	End If
End If

If oMaxLength < 625 Then
	Dim orientype As ViewOrientationTypeEnum
	orientype = oView.Camera.ViewOrientationType
	If  orientype = 10756 Or orientype = 10757 Or orientype = 10764 Or orientype = 10758 Or orientype = 10755 Or orientype = 10754 Then
	oScale = "1 : 2.5"
	End If
	If orientype = 10763 Or orientype = 10762 Or orientype = 10761 Or orientype = 10760 Or orientype = 10759  Then
	oScale = "1 : 5"
	End If
End If

If oMaxLength < 500 Then
	Dim orientype As ViewOrientationTypeEnum
	orientype = oView.Camera.ViewOrientationType
	If  orientype = 10756 Or orientype = 10757 Or orientype = 10764 Or orientype = 10758 Or orientype = 10755 Or orientype = 10754 Then
	oScale = "1 : 2"
	End If
	If orientype = 10763 Or orientype = 10762 Or orientype = 10761 Or orientype = 10760 Or orientype = 10759  Then
	oScale = "1 : 5"
	End If
End If

Next

 

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

Michael.Navara
Advisor
Advisor

The first bug is syntax error. You declare variable oView twice and don't set value for For Each statement.

 

Dim oView As DrawingView = oSheet.DrawingViews.Item(1)	

....

Dim oView As DrawingView
For Each oView In oViews

....

 

I look at your code soon

0 Likes
Message 3 of 3

Michael.Navara
Advisor
Advisor

You miss to set drawing view scale

 

Here is reworked rule with fixed bugs. In my opinion it is more readable and maintainable. 

  • Please check the values for max length 2500. It is defined twice with different scale values.
  • It is much better for readability of your code, when you use enum values instead of its integer alternatives

 

Sub Main()
    SetDrawingViewScales()
End Sub

Sub SetDrawingViewScales()
    Dim oDrawingDoc As DrawingDocument = ThisApplication.ActiveDocument
    Dim oSheet As Sheet = oDrawingDoc.Sheets.Item(1)
    Dim oView As DrawingView = oSheet.DrawingViews.Item(1)
    Dim oDMDef As ComponentDefinition = oView.ReferencedDocumentDescriptor.ReferencedDocument.ComponentDefinition
    Dim oWidth As Double = Abs(oDMDef.RangeBox.MaxPoint.Y - oDMDef.RangeBox.MinPoint.Y) * 10
    Dim oLength As Double = Abs(oDMDef.RangeBox.MaxPoint.X - oDMDef.RangeBox.MinPoint.X) * 10
    Dim oHeight As Double = Abs(oDMDef.RangeBox.MaxPoint.Z - oDMDef.RangeBox.MinPoint.Z) * 10
    Dim oMaxLength As Double = Max(Max(oLength, oWidth), oHeight)

    'Set scale to all drawing views
    For Each drawingView In oSheet.DrawingViews
        SetScale(drawingView, oMaxLength)
    Next
End Sub

Sub SetScale(oView As DrawingView, maxLength As Double)
    'Define max length and scales (maxLength, isoScale, orthoScale)
    Dim lengthAndScales = {
        New LengthAndScale(5000, "1 : 50", "1 : 100"),
        New LengthAndScale(2500, "1 : 20", "1 : 50"),
        New LengthAndScale(2500, "1 : 10", "1 : 20"),
        New LengthAndScale(1250, "1 : 5", "1 : 2"),
        New LengthAndScale(625, "1 : 2.5", "1 : 5"),
        New LengthAndScale(500, "1 : 2", "1 : 5")
    }

    Dim oScale As String = "1 : 5"

    'Select scales by max length
    For Each lengthAndScale In lengthAndScales
        If maxLength < lengthAndScale.MaxLength Then
            Dim orientType = oView.Camera.ViewOrientationType
            If IsIsoView(orientType) Then oScale = lengthAndScale.IsoScale
            If IsOrthoView(orientType) Then oScale = lengthAndScale.OrthoScale
        End If
    Next

    'Set view scale
    If Not oView.ScaleFromBase Then
        oView.ScaleString = oScale
    End If
End Sub

Private Function IsIsoView(viewOrientationType As ViewOrientationTypeEnum) As Boolean
    Select Case viewOrientationType
        Case ViewOrientationTypeEnum.kArbitraryViewOrientation,
         ViewOrientationTypeEnum.kIsoBottomLeftViewOrientation,
         ViewOrientationTypeEnum.kIsoBottomRightViewOrientation,
         ViewOrientationTypeEnum.kIsoTopLeftViewOrientation,
         ViewOrientationTypeEnum.kIsoTopRightViewOrientation
            Return True
        Case Else
            Return False
    End Select
End Function

Private Function IsOrthoView(viewOrientationType As ViewOrientationTypeEnum) As Boolean
    Select Case viewOrientationType
        Case ViewOrientationTypeEnum.kFrontViewOrientation,
        ViewOrientationTypeEnum.kBackViewOrientation,
        ViewOrientationTypeEnum.kLeftViewOrientation,
        ViewOrientationTypeEnum.kRightViewOrientation,
        ViewOrientationTypeEnum.kTopViewOrientation,
        ViewOrientationTypeEnum.kBottomViewOrientation
            Return True
        Case Else
            Return False
    End Select
End Function

Class LengthAndScale
    Sub New(maxLength As Double, isoScale As String, orthoScale As String)
        Me.MaxLength = maxLength
        Me.IsoScale = isoScale
        Me.OrthoScale = orthoScale
    End Sub

    Public Property MaxLength As Double
    Public Property IsoScale As String
    Public Property OrthoScale As String
End Class