Edit Segment of line or shape using VBA

I'm trying to modify the elevation of  a single segment of a linestring any suggestion will be helpful

Thanks in advance

Parents Reply Children
  • Hi

    Here is the current working code for vertex

    Here is the code generated to edit the vertex to change the elevation of line string.

    Option Explicit
    
    
    Implements IPrimitiveCommandEvents
    
    Dim Myline As LineElement
    Dim MyVertex As VertexList
    Dim MyVerlist() As Point3d
    Dim VerNum As Long
    Dim MVerCound As Long
    Dim MvPoint As Point3d
    Dim NwPoint As Point3d
    Dim OrPoint As Point3d
    Dim FxyPoint As Point3d
    Dim mdone As Boolean
    
    
    Private Function LocateLine(pnt As Point3d, View As View) As LineElement
    
    On Error GoTo NoElement
                Set LocateLine = CommandState.LocateElement(pnt, View, True)
    NoElement:
            
    End Function
    
    Private Sub IPrimitiveCommandEvents_Cleanup()
    
    End Sub
    
    Private Sub IPrimitiveCommandEvents_DataPoint(Point As Point3d, ByVal View As View)
    
        If Myline Is Nothing Then
            Set Myline = LocateLine(Point, View)
                If Myline Is Nothing Then
                    ShowError "No Line Found"
                    Exit Sub
                End If
            If MyVertex Is Nothing Then
                
                    With Myline.AsVertexList
                        Set MyVertex = Myline
                            MyVerlist = MyVertex.GetVertices
                            VerNum = .GetClosestVertex(Point)
                            MvPoint = MyVerlist(VerNum)
                            OrPoint = MyVerlist(VerNum)
                            mdone = False
                            CommandState.StartDynamics
                    End With
            End If
            ElseIf Not MyVertex Is Nothing Then
                Myline.ModifyVertex VerNum, NwPoint
                Myline.Redraw msdDrawingModeNormal
                Myline.Rewrite
                mdone = True
                CommandState.StopDynamics
                Set Myline = Nothing
                Set MyVertex = Nothing
                
                CommandState.DisableAccuSnap
                CadInputQueue.SendKeyin "LOCK axis off"
                
            End If
        
    End Sub
    
    Private Sub IPrimitiveCommandEvents_Dynamics(Point As Point3d, ByVal View As View, ByVal DrawMode As MsdDrawingMode)
        If Myline Is Nothing Then
            Exit Sub
        End If
            'CommandState.EnableAccuSnap
           'CadInputQueue.SendKeyin "LOCK axis on"
           'CadInputQueue.SendKeyin "ACCUDRAW LOCK X"
        FxyPoint = Point3dFromXYZ(MvPoint.X, MvPoint.Y, Point.Z)
        Myline.Redraw msdDrawingModeTemporary
        
        Myline.ModifyVertex VerNum, FxyPoint
        NwPoint = FxyPoint
    
    End Sub
    
    Private Sub IPrimitiveCommandEvents_Keyin(ByVal Keyin As String)
    
    End Sub
    
    Private Sub IPrimitiveCommandEvents_Reset()
        
        If Myline Is Nothing Then
            CommandState.StartDefaultCommand
        Else
            If mdone = True Then
                Set Myline = Nothing
                CommandState.SetLocateCursor
                CommandState.StartPrimitive Me
            Else
                Myline.ModifyVertex VerNum, OrPoint
                Myline.Redraw msdDrawingModeNormal
                Myline.Rewrite
                Set Myline = Nothing
            End If
        End If
    End Sub
    
    Private Sub IPrimitiveCommandEvents_Start()
       ' Set MyLine = Nothing
        CommandState.SetLocateCursor
    End Sub
    

    Here is the code generated to edit the vertex to change the elevation of line shape.

    Option Explicit
    
    
    Implements IPrimitiveCommandEvents
    
    Dim Myline As ShapeElement
    Dim MyVertex As VertexList
    Dim MyVerlist() As Point3d
    Dim VerNum As Integer
    Dim SegNum As Integer
    Dim MVerCound As Long
    Dim MvPoint As Point3d
    Dim NwPoint As Point3d
    Dim OrPoint As Point3d
    Dim FxyPoint As Point3d
    Dim mdone As Boolean
    
    
    Private Function Locateshape(pnt As Point3d, View As View) As ShapeElement
    
    On Error GoTo NoElement
                Set Locateshape = CommandState.LocateElement(pnt, View, True)
    NoElement:
            
    End Function
    
    Private Sub IPrimitiveCommandEvents_Cleanup()
    
    End Sub
    
    Private Sub IPrimitiveCommandEvents_DataPoint(Point As Point3d, ByVal View As View)
    
        If Myline Is Nothing Then
            Set Myline = Locateshape(Point, View)
                If Myline Is Nothing Then
                    ShowError "No Line Found"
                    Exit Sub
                End If
            If MyVertex Is Nothing Then
                
                    With Myline.AsVertexList
                        Set MyVertex = Myline
                            MyVerlist = MyVertex.GetVertices
                            VerNum = .GetClosestVertex(Point)
                            SegNum = .GetClosestSegment(Point)
                            MvPoint = MyVerlist(VerNum)
                            OrPoint = MyVerlist(VerNum)
                            mdone = False
                            CommandState.StartDynamics
                    End With
            End If
            ElseIf Not MyVertex Is Nothing Then
                Myline.ModifyVertex VerNum, NwPoint
                Myline.Redraw msdDrawingModeNormal
                Myline.Rewrite
                mdone = True
                CommandState.StopDynamics
                Set Myline = Nothing
                Set MyVertex = Nothing
                
                CommandState.DisableAccuSnap
                CadInputQueue.SendKeyin "LOCK axis off"
                
            End If
        
    End Sub
    
    Private Sub IPrimitiveCommandEvents_Dynamics(Point As Point3d, ByVal View As View, ByVal DrawMode As MsdDrawingMode)
        If Myline Is Nothing Then
            Exit Sub
        End If
            'CommandState.EnableAccuSnap
           'CadInputQueue.SendKeyin "LOCK axis on"
           'CadInputQueue.SendKeyin "ACCUDRAW LOCK X"
        FxyPoint = Point3dFromXYZ(MvPoint.X, MvPoint.Y, Point.Z)
        Myline.Redraw msdDrawingModeTemporary
        
        Myline.ModifyVertex VerNum, FxyPoint
        NwPoint = FxyPoint
    
    End Sub
    
    Private Sub IPrimitiveCommandEvents_Keyin(ByVal Keyin As String)
    
    End Sub
    
    Private Sub IPrimitiveCommandEvents_Reset()
        
        If Myline Is Nothing Then
            CommandState.StartDefaultCommand
        Else
            If mdone = True Then
                Set Myline = Nothing
                CommandState.SetLocateCursor
                CommandState.StartPrimitive Me
            Else
                Myline.ModifyVertex VerNum, OrPoint
                Myline.Redraw msdDrawingModeNormal
                Myline.Rewrite
                Set Myline = Nothing
            End If
        End If
    End Sub
    
    Private Sub IPrimitiveCommandEvents_Start()
       ' Set MyLine = Nothing
        CommandState.SetLocateCursor
    End Sub
    
    

    Now working on a process to combine both to a single code and 

    add segment method 

    Thanks for any suggestion and help in advance.

    Kind regards

    Arun Pradhad.Hariharan