.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Changing a vertex

4 REPLIES 4
Reply
Message 1 of 5
ahmed.felix
325 Views, 4 Replies

Changing a vertex

How can I change the coordinates of a single vertex in a polyline3d?
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: ahmed.felix

Seems to be worked for me many times
with no any problems (A2007 only)
Give this a shot

~'J'~

Imports System
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.DatabaseServices

Namespace Polyline.CommonUtils
Public Class PolylineManipulation
_
Public Sub GetEntity()
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor()
Dim selopts As PromptEntityOptions = New PromptEntityOptions(vbCr & "Select 3DPolyline: ")
selopts.SetRejectMessage(vbCr & "3DPolyline may be selected only!")
selopts.AddAllowedClass(GetType(Polyline3d), True)
Dim entres As PromptEntityResult = ed.GetEntity(selopts)
If entres.Status = PromptStatus.OK Then
Move3DPolyVertex(entres.ObjectId)
End If
End Sub


Private Sub Move3DPolyVertex(ByVal polyID As ObjectId)
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim docLock As DocumentLock = doc.LockDocument()
Dim ed As Editor = doc.Editor
Dim db As Database = doc.Database
Using trans As Transaction = ed.Document.TransactionManager.StartTransaction()

Dim objPline As Polyline3d = CType(trans.GetObject(polyID, OpenMode.ForWrite), Polyline3d)
Dim osm As Integer = Application.GetSystemVariable("OSMODE")
Application.SetSystemVariable("OSMODE", 1)
Dim opts As New PromptPointOptions(vbCr & "Select vertex :")
opts.AllowNone = False
opts.UseBasePoint = False

Dim res As PromptPointResult = ed.GetPoint(opts)
If res.Status = PromptStatus.OK Then
Dim pfrom As Point3d = res.Value
opts.UseBasePoint = True
opts.BasePoint = pfrom
opts.Message = vbCr & "Pick destination point to move vertext at:"
Dim nres As PromptPointResult = ed.GetPoint(opts)
If nres.Status = PromptStatus.OK Then
Dim pto As Point3d = nres.Value
Dim btr As BlockTableRecord = DirectCast(trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite),

BlockTableRecord)
Dim desVex As PolylineVertex3d = New PolylineVertex3d
Dim viter As IEnumerator = objPline.GetEnumerator
While viter.MoveNext
Dim newVex As PolylineVertex3d = DirectCast(trans.GetObject(viter.Current, OpenMode.ForWrite),

PolylineVertex3d)
Dim pt As Point3d = newVex.Position
If pt.X.Equals(pfrom.X) And _
pt.Y.Equals(pfrom.Y) And _
pt.Z.Equals(pfrom.Z) Then
desVex = newVex
End If
End While
desVex.Position = New Point3d(pto.X, pto.Y, pto.Z)
Application.SetSystemVariable("OSMODE", osm)
ed.Regen()
trans.Commit()
End If
End If
docLock.Dispose()
End Using
End Sub

End Class

End Namespace
Message 3 of 5
Anonymous
in reply to: ahmed.felix

Agrhhh, forgot about bad formatting on this NG
pages
Try attached instead

~'J'~
Message 4 of 5
Ed.Jobe
in reply to: ahmed.felix

Use code tags. At the beginning of your code, use "code" surrounded by sqare brackets. At the end of your code, use "/code" surrounded by sqare brackets.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 5 of 5
Anonymous
in reply to: ahmed.felix

Dear Ed,
My personal question for you
Please, try this code and send feedback how
it will works for you

Regards

OLeg

~'J'~

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost