Sheldon1874 发表于 2015-5-11 17:10:49

建议:在选择集循环中高亮显示选定的3dVertex

我所做的就是在一条多边形线上高亮显示一个3d顶点,然后我想以某种方式改变它。就像使用属性托盘来滚动顶点一样。参见代码。AutoCAD 2014、Windows 7、VB.net
    Public Sub UtilityLine()
      Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
      Dim acCurDb As Database = acDoc.Database
      Dim ed As Editor = acDoc.Editor
      Dim east, north, ele As Double
      'Dim strText As String
      '' Start a transaction
      Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
            '' Request for objects to be selected in the drawing area
            Dim acSSPrompt As PromptSelectionResult = acDoc.Editor.GetSelection()
            '' If the prompt status is OK, objects were selected
            If acSSPrompt.Status = PromptStatus.OK Then
                Dim acSSet As SelectionSet = acSSPrompt.Value
                '' Step through the objects in the selection set
                For Each acSSObj As SelectedObject In acSSet
                  '' Check to make sure a valid SelectedObject object was returned
                  If Not IsDBNull(acSSObj) Then
                        '' Open the selected object for write
                        Dim acEnt As Entity = acTrans.GetObject(acSSObj.ObjectId, _
                                                                OpenMode.ForWrite)
                        acEnt.Highlight()
                        ed.Regen()
                        If Not IsDBNull(acEnt) Then
                            Dim obj As DBObject = acTrans.GetObject(acEnt.ObjectId, OpenMode.ForWrite)
                            ' lightweight polyline
                            Dim lwp As Polyline = TryCast(obj, Polyline)
                            If lwp IsNot Nothing Then
                              ' Loop to get each vertex
                              Dim vn As Integer = lwp.NumberOfVertices
                              For i As Integer = 0 To vn - 1
                                    Dim pt As Point3d = lwp.GetPoint3dAt(i)
                                    east = pt(0)
                                    north = pt(1)
                                    ed.WriteMessage(vbLf & pt.ToString())
                              Next
                            Else
                              ' 2D polyline
                              Dim p2d As Polyline2d = TryCast(obj, Polyline2d)
                              If p2d IsNot Nothing Then
                                    ' Use foreach to get each contained vertex
                                    For Each vId As ObjectId In p2d
                                        Dim v2d As Vertex2d = DirectCast(acTrans.GetObject(vId, OpenMode.ForWrite), Vertex2d)
                                        ed.WriteMessage(vbLf & v2d.Position.ToString())
                                    Next
                              Else
                                    ' 3D polyline
                                    Dim p3d As Polyline3d = TryCast(obj, Polyline3d)
                                    If p3d IsNot Nothing Then
                                        Dim p3dColour As String = p3d.Color.ToString
                                        For Each vId As ObjectId In p3d
                                          Dim zM As New ZoomObj
                                          Dim v3d As PolylineVertex3d = DirectCast(acTrans.GetObject(vId, OpenMode.ForWrite), PolylineVertex3d)
                                          east = v3d.Position(0)
                                          north = v3d.Position(1)
                                          ele = v3d.Position(2)
                                          Dim zMax = New Point3d(east + 1, north + 1, 1)
                                          Dim zMin = New Point3d(east - 1, north - 1, 1)
                                          zM.Zoom(zMin, zMax, v3d.Position, 1)
                                          p3d.Highlight()
                                          Dim dText As New PromptEntityOptions(vbLf & "Select Depth: ")
                                          dText.SetRejectMessage("not text")
                                          dText.AddAllowedClass(GetType(DBText), False)
                                          Dim resdText As PromptEntityResult = ed.GetEntity(dText)
                                          If resdText.Status = PromptStatus.OK Then
                                                Dim depthText As DBText = DirectCast(acTrans.GetObject(resdText.ObjectId, _
                                                          OpenMode.ForRead), DBText)
                                                Dim depthLen = depthText.TextString.Length
                                                Dim dthTxt As String = depthText.TextString
                                                dthTxt = Mid(dthTxt, 3, depthLen - 1)
                                                Dim depthOff As Double = CDbl(dthTxt)
                                                v3d.Position = New Point3d(east, north, ele - depthOff)
                                                ed.WriteMessage(vbLf & "Depth= " & dthTxt)
                                          End If
                                        Next
                                    End If
                              End If
                            End If
                        End If
                  End If
                Next
                '' Save the new object to the database
                acTrans.Commit()
            End If
            '' Dispose of the transaction
      End Using
    End Sub
**** Hidden Message *****

Jeff_M 发表于 2015-5-11 18:35:19

可以使用TransientGraphics创建标记,就像使用特性选项板选择顶点时使用的标记一样。下面是一些执行此操作的示例代码(抱歉,在c#中)。aGi正在引用以下内容:
使用aGi=Autodesk.AutoCAD。图形界面
在每个顶点的代码中使用:
showX(pt,7)
并在转到下一个顶点之前删除它们:
removeMarkers()
私有静态DBObjectCollection m_mrkers=new dbobjectcolcollection()
私有静态整数集合intColl=new IntegerCollection()
私有void showX(Point3d pt,int-color)
{
//使用指定颜色的两行临时显示“X”的代码。使用简单的颜色索引1-255。
双倍大小=2//对于该示例,此代码是硬编码的。应使用基于屏幕大小的值。
双x=pt.x
双y=pt.y
Point3d pt1=新的Point3d(-0.5*size)+x、(-0.5*size)+y,0
Point3d:pt2=新的Point3d((0.5*size)+x,(0.5*size)+y,0)
行line1=新行(pt1,pt2)
line1.ColorIndex=颜色
行line2=新行(line1.StartPoint,line1.EndPoint)
line2.ColorIndex=颜色
//我们在与第1行相同的位置创建了第2行,让我们将其旋转90度以创建“X”
line2.TransformBy(矩阵3d.Rotation(Math.PI*0.5,Vector3d.ZAxis,pt))
aGi.TransientManager.CurrentTransientManager。AddTransient(第1行,aGi.TransientDrawingMode.DirectTopmost,128,intColl)
aGi.TransientManager.CurrentTransientManager。AddTransient(第2行,aGi.TransientDrawingMode.DirectTopmost,128,intColl)
m_ mrkers.Add(第1行)
m_ mrkers.Add(第2行)
}
私有void removeMarkers()
{
//完成后将它们全部移除……不要让屏幕杂乱无章
用于(int i=0;i
{
aGi.TransientManager.CurrentTransientManager。擦除瞬态(m_mrkers,intColl)
m_mrkers.Dispose()
}
m_mrkers.Clear()
}

Sheldon1874 发表于 2015-5-11 18:51:11

Ta Jeff_M看起来是一个很好的地方。 是一种享受。实际上,一开始从未注意到您的代码。因此,在查看代码之前研究瞬态图形的好处是不会懒惰于旧的Ctrl-C;Ctrl-V 组合。
再次感谢。
页: [1]
查看完整版本: 建议:在选择集循环中高亮显示选定的3dVertex