Non associative hatches not returning object for GetLoopAt method

Non associative hatches not returning object for GetLoopAt method

Thomas.Long
Advocate Advocate
1,303 Views
1 Reply
Message 1 of 2

Non associative hatches not returning object for GetLoopAt method

Thomas.Long
Advocate
Advocate

I have a program that gets a selection of hatches and writes information about them to a list in excel. The point is to generate a list of parts and create them in inventor from the information I'm generating in autocad. From what I can tell my difficulty is coming from non associative hatches, where the GetLoopMethod doesn't return an object. I'm looking at either a way to find the boundaries for each loop of the hatch (I need its total size and location) or else a way to redefine the boundaries on the fly and make it associative.

 

Function ExportHatches(oSheet As Object)

    'Declaring Excel Row
    Dim Row As Integer
    
    'Declaring holder variables for individual hatch values
    Dim HatchLStart As Double
    Dim HatchLEnd As Double
    Dim HatchWStart As Double
    Dim HatchWEnd As Double
    Dim Length As Double
    Dim Width As Double

    'Declaring Hatch holder
    Dim oHatch As AcadHatch
    
    'Declaring Selection Set Variables
    Dim SSObj As AcadSelectionSet
    Dim FilterType(0) As Integer
    Dim FilterData(0) As Variant
    
    'Declaring points
    Dim EndPoint As Variant
    Dim LoopObjs As Variant
    Dim StartPoint As Variant
    Dim UpdatedPoint As Variant
    Dim UpdatedStartPoint As Variant
    Dim UpdatedEndPoint As Variant
    
    
    'Initializing Variables
    Row = 1
    FilterType(0) = 0
    FilterData(0) = "Hatch"

    
    Set SSObj = ThisDrawing.ActiveSelectionSet
    SSObj.Clear
    SSObj.SelectOnScreen FilterType, FilterData

    'Iterate Through Selection Set and write out data
    With oSheet
        .Cells.Clear
        
        For Each oHatch In SSObj
            MsgBox (oHatch.AssociativeHatch)
            If UCase(oHatch.PatternName) = "ANSI31" Or UCase(oHatch.PatternName) = "ANSI37" Or UCase(oHatch.PatternName) = "HONEY" Then
                
                oHatch.GetBoundingBox StartPoint, EndPoint
                For i = 0 To oHatch.NumberOfLoops - 1
                
                    'Set Hatch initialization values
                    HatchLStart = 100000
                    HatchLEnd = -100000
                    HatchWStart = 100000
                    HatchWEnd = -100000
                
                    oHatch.GetLoopAt i, LoopObjs
                    
                    If IsObject(LoopObjs) Then
                        For j = LBound(LoopObjs) To UBound(LoopObjs)
                            LoopObjs(j).GetBoundingBox StartPoint, EndPoint
                            UpdatedStartPoint = ThisDrawing.Utility.TranslateCoordinates(StartPoint, acWorld, acUCS, False)
                            UpdatedEndPoint = ThisDrawing.Utility.TranslateCoordinates(EndPoint, acWorld, acUCS, False)
                            
                            'Check that values are lowest and
                            If UpdatedStartPoint(0) < HatchLStart Then HatchLStart = UpdatedStartPoint(0)
                            If UpdatedEndPoint(0) > HatchLEnd Then HatchLEnd = UpdatedEndPoint(0)
                            If UpdatedStartPoint(1) < HatchWStart Then HatchWStart = UpdatedStartPoint(1)
                            If UpdatedEndPoint(1) > HatchWEnd Then HatchWEnd = UpdatedEndPoint(1)
                        Next
                        
                        Length = Abs(HatchLEnd - HatchLStart)
                        Width = Abs(HatchWEnd - HatchWStart)
                        
                        If UCase(oHatch.PatternName) = "ANSI31" Then .Cells(Row, 1) = "Surface"
                        If UCase(oHatch.PatternName) = "ANSI37" Then .Cells(Row, 1) = "Flush"
                        If UCase(oHatch.PatternName) = "HONEY" Then .Cells(Row, 1) = "Bottom"
                        .Cells(Row, 2) = Length
                        .Cells(Row, 3) = Width
                        .Cells(Row, 4) = HatchLStart
                        .Cells(Row, 5) = HatchWStart
                        
                        Row = Row + 1
                    End If
                Next
            End If
        Next
    End With
End Function
0 Likes
1,304 Views
1 Reply
Reply (1)
Message 2 of 2

Thomas.Long
Advocate
Advocate

So I found a way, not in VBA, to make the hatches associative again. It requires Hatch Edit -> Recreate Boundary -> Yes -> Polyline and that recreates the hatch as an associative hatch. My hope is someone knows a way to do this in VBA but it is workable doing it manually. 

 

Edit: I would try the appendOuterLoop Method but this way doesn't require that I select the boundaries for each hatch, something I'm hopeful to have in the final code.

0 Likes