pjm8765 发表于 2018-12-11 09:00:57

使用AcadRegion。复制

我有一个例程,计算一个区域对象中最长直线的长度 我希望下面的代码在特定层上创建区域对象的副本,分解副本,然后在完成后删除副本,但它没有#039;t、 ..当我再次运行它时,它会同时删除副本和原始区域对象:
    Public Function GetInsituConcretePolyInsertCount(ByRef myDocuments As AcadDocumentManagerExample) As Integer
      Dim polyInsertCount As Integer = 0
      Dim filterType(1) As Short
      Dim filterData(1) As Object
      Dim selectionSet As AcadSelectionSet
      Dim i As Integer
      Dim inSituConcreteRegion As AcadRegion
      Dim copyOfInSituConcreteRegion As AcadRegion
      Dim insituLength As Double
      Dim explodedRegion As Object
      Dim j As Integer
      Dim line As AcadLine
      Dim regionLength As Double
      Try
            insituLength = 0
            selectionSet = CreateSelSet(myDocuments.ThisDrawing, "INSITUCONCRETE")
            filterType(0) = 0
            filterType(1) = 8
            filterData(0) = "REGION"
            filterData(1) = EASICAD_LAYERS.INSITU_INFILL
            selectionSet.Clear()
            selectionSet.Select(AcSelect.acSelectionSetAll, , , filterType, filterData)
            For i = 0 To selectionSet.Count - 1
                inSituConcreteRegion = TryCast(selectionSet.Item(i), AcadRegion)
                If Not IsNothing(inSituConcreteRegion) Then
                  'regionLength = GetLengthOfRegion(inSituConcreteRegion, myDocuments)
                  regionLength = 0
                  copyOfInSituConcreteRegion = TryCast(inSituConcreteRegion.Copy, AcadRegion)
                  If IsNothing(copyOfInSituConcreteRegion) Then
                        Continue For
                  End If
                  explodedRegion = copyOfInSituConcreteRegion.Explode
                  For j = 0 To UBound(explodedRegion)
                        Try
                            line = TryCast(explodedRegion(j), AcadLine)
                            If Not IsNothing(line) Then
                              If line.Length > regionLength Then
                                    regionLength = line.Length
                              End If
                              line.Delete()
                            End If
                        Catch ex As Exception
                            'Do nothing it's not a line
                        End Try
                  Next
                  copyOfInSituConcreteRegion.Delete()
                  inSituConcreteRegion.Update()
                  insituLength += regionLength
                End If
            Next
            If insituLength > 0 Then
                polyInsertCount = Math.Round(insituLength / 1200, 0, MidpointRounding.AwayFromZero)
            End If
      Catch ex As System.Exception
            MsgBox("Reusable.GetInsituConcretePolyInsertCount : " & ex.Message, MsgBoxStyle.OkOnly, EasiCADException.EasiCADErrorTitle)
      End Try
      Return polyInsertCount
    End Function

我第一次运行此例程时,它处理得很好,图形包含原始区域 但是,如果我再次运行该例程,它会删除副本和原件 如果我使用一次例程,保存图形,关闭它,重新打开它,然后再次运行例程,它就可以正常工作 It#039;s仅当例程在同一会话中背靠背运行时,无论是否保存
I'我相信有人会告诉我使用另一个人工制品,比如折线 我可以,但这需要在其他地方做大量的工作……我管理的系统的大部分都使用了埋在块中的区域,这些区域一直在爆炸(也不使用副本),这些区域是don 35; 039;不要被移除 我想我可以把这些区域埋在块里,但我'我回到了其他地方大量的工作 我只是不'不理解为什么Copy命令不#039;我不会再工作了
myDocuments对象本质上是一个AcadDocumentManager对象
保罗,你好

pjm8765 发表于 2018-12-11 11:31:18

假警报 问题是由顶部的CreateSelSet过程调用导致的,该调用错误地擦除了选择集内容,而不是清除(ed)它们。
页: [1]
查看完整版本: 使用AcadRegion。复制