Code:
Option Strict OnImports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Public Class Class7
<CommandMethod("ErstelleRegionen")> _
Public Sub ErstelleRegionen()
Dim acDocEd As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Try
Dim acBlkTbl As BlockTable
acBlkTbl = CType(acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead), BlockTable)
Dim acTypValAr(1) As TypedValue
acTypValAr.SetValue(New TypedValue(DxfCode.Start, "LINE"), 0)
acTypValAr.SetValue(New TypedValue(DxfCode.LayerName, "GEB_HAUPT"), 1)
Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr)
Dim acSSPromt As PromptSelectionResult
acSSPromt = acDocEd.SelectAll(acSelFtr)
Dim acObjIdColl As ObjectIdCollection = New ObjectIdCollection()
Dim acSSet As SelectionSet
If acSSPromt.Status = PromptStatus.OK Then
acSSet = acSSPromt.Value
acObjIdColl = New ObjectIdCollection(acSSet.GetObjectIds)
End If
Dim acBlkTblRec As BlockTableRecord
acBlkTblRec = CType(acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)
Dim acDBObjColl As DBObjectCollection = New DBObjectCollection()
For Each acObjId1 In acObjIdColl
If Not IsDBNull(acObjId1) Then
Dim acCurLine As Line = CType(acTrans.GetObject(CType(acObjId1, ObjectId), OpenMode.ForWrite), Line)
If Not IsDBNull(acCurLine) Then
acDBObjColl.Add(acCurLine)
End If
End If
Next
Dim myRegionColl As DBObjectCollection = New DBObjectCollection()
Dim areaList As ArrayList = New ArrayList()
myRegionColl = Region.CreateFromCurves(acDBObjColl)
' Erstellen aller theoretisch größtmöglichen Flächen.
Dim m, n As Integer
For m = 0 To myRegionColl.Count - 1
For n = 0 To myRegionColl.Count - 1
Dim acRegion1 As Region = CType(myRegionColl(m), Region)
Dim acRegion2 As Region = CType(myRegionColl(n), Region)
areaList.Add(acRegion1.Area + acRegion2.Area)
Next
Next
' Filtern der Flächen. Wenn Fläche nicht enthalten, dann wird sie gezeichnet!
Dim j As Integer
For j = 0 To myRegionColl.Count - 1
Dim acRegion As Region = CType(myRegionColl(j), Region)
If areaList.Contains(acRegion.Area) = False Then
acBlkTblRec.AppendEntity(acRegion)
acTrans.AddNewlyCreatedDBObject(acRegion, True)
End If
Next
acTrans.Commit()
Catch ex As Exception
Application.ShowAlertDialog("Folgender Fehler ist aufgetreten:" & vbLf & ex.Message)
Finally
acTrans.Dispose()
End Try
End Using
End Sub
End Class