VBA: Change hatch scale using the DrawingViewHatchRegion Object

VBA: Change hatch scale using the DrawingViewHatchRegion Object

mr_ensing
Advocate Advocate
275 Views
2 Replies
Message 1 of 3

VBA: Change hatch scale using the DrawingViewHatchRegion Object

mr_ensing
Advocate
Advocate

The picture below pretty much sums it up:

 

Untitled.png

 

I'm using Inventor 2023. I've used another property (ByMaterial) of DrawingViewHatchRegion with great success.

 

The description for the Scale property tells me it is a Double and:

Read-write property that specifies the scale of the distance between lines.

 

Why does the compiler tell me it expects a '('?

 

 

Private Sub Test()
    Dim iDoc As DrawingDocument:    Set iDoc = ThisApplication.ActiveDocument
    Dim oSheet As Sheet:            Set oSheet = iDoc.ActiveSheet
    Dim oView As DrawingView
    For Each oView In oSheet.DrawingViews
        Dim oHatch As DrawingViewHatchRegion
        For Each oHatch In oView.HatchRegions
            oHatch.Scale = 0.2
        Next oHatch
    Next oView
End Sub

 

 

Accepted solutions (1)
276 Views
2 Replies
Replies (2)
Message 2 of 3

Michael.Navara
Advisor
Advisor
Accepted solution

This looks like a specific issue in VBA. Word "Scale" is reserved keyword in VBA. This post on StackOverflow discuss it. It looks like a bug in parsing of source code. The same issue I get when I try to set any Scale property on different object (DrawingView.Scale for example). Also, you can't declare method or function with the name "Scale".

 

Solution is to enclose the name of property to square brackets.

 

 

 

Private Sub Test()
    Dim iDoc As DrawingDocument:    Set iDoc = ThisApplication.ActiveDocument
    Dim oSheet As Sheet:            Set oSheet = iDoc.ActiveSheet
    Dim oView As DrawingView
    For Each oView In oSheet.DrawingViews
        Dim oHatch As DrawingViewHatchRegion
        For Each oHatch In oView.HatchRegions
            oHatch.[Scale] = 0.2
        Next oHatch
    Next oView
End Sub

 

 

 

 

NOTE:

This is not necessary in iLogic, VB.NET or C#. There it works without any workaround.

Message 3 of 3

mr_ensing
Advocate
Advocate

Thanks a bunch, works like a charm!

0 Likes