How to check if a dimension is vertical or horizontal?

How to check if a dimension is vertical or horizontal?

inulobo
Advocate Advocate
805 Views
2 Replies
Message 1 of 3

How to check if a dimension is vertical or horizontal?

inulobo
Advocate
Advocate

I am trying to automatically arrange dimensions on a sheet using different spacing based on whether the dimension is a vertical or horizontal one. How do you determine if the dimension is vertical or horizontal? Please see the code below.

 

Sub AutoDimArrange()
    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    ' Set a reference to the active sheet
    Dim oSheet As Sheet
    Set oSheet = oDoc.ActiveSheet

    Dim oDrawingDim As DrawingDimension
    Dim oDrawingDimensions As DrawingDimensions
    Set oDrawingDimensions = oSheet.DrawingDimensions
    
    Dim oDimsToBeArrangedVertical As ObjectCollection
    Dim oDimsToBeArrangedHorizontal As ObjectCollection
    Set oDimsToBeArrangedVertical = ThisApplication.TransientObjects.CreateObjectCollection
    Set oDimsToBeArrangedHorizontal = ThisApplication.TransientObjects.CreateObjectCollection
    
    Dim oStyle As DimensionStyle
    Set oStyle = oDoc.StylesManager.DimensionStyles.Item("MRK")
    
    Dim oScale As Double
    oScale = 2.54
    
    For Each oDrawingDim In oDrawingDimensions
        If TypeOf oDrawingDim Is LinearGeneralDimension Or TypeOf oDrawingDim Is AngularGeneralDimension Then
            'If oDrawingDim.DimensionLine Then
            '    oDrawingDim.CenterText
            '    Call oDimsToBeArrangedVertical.Add(oDrawingDim)
            'ElseIf oDrawingDim Then
                oDrawingDim.CenterText
                Call oDimsToBeArrangedHorizontal.Add(oDrawingDim)

            'End If
        End If
    Next
    
    'oStyle.Extension = 0.125 * oScale
    'oStyle.OriginOffset = 0.063 * oScale
    'oStyle.Gap = 0.031 * oScale
    'oStyle.spacing = 0.25 * oScale
    'oStyle.PartOffset = 0.125 * oScale
    'Call oDrawingDimensions.Arrange(oDimsToBeArrangedVertical)
    
    
    oStyle.Extension = 0.125 * oScale
    oStyle.OriginOffset = 0.063 * oScale
    oStyle.Gap = 0.031 * oScale
    oStyle.spacing = 0.375 * oScale
    oStyle.PartOffset = 0.125 * oScale
    Call oDrawingDimensions.Arrange(oDimsToBeArrangedHorizontal)
    
    
    
End Sub

0 Likes
Accepted solutions (1)
806 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Accepted solution

After this line:

If TypeOf oDrawingDim Is LinearGeneralDimension Or TypeOf oDrawingDim Is AngularGeneralDimension Then

Add another line:

If oDrawingDim.DimensionType = kHorizontalDimensionType Then

And version for the varticals:

If oDrawingDim.DimensionType = kVerticalDimensionType Then

Don't forget to add End If before Next

Message 3 of 3

inulobo
Advocate
Advocate

Thank you. I tried that previously but it did not work. I must have made a syntax error. Thank you again! This worked perfectly.

0 Likes