I want to draw a line from a point. How do I add a length to a 3dpoint?
I want to add 3' in x to pte.
Dim pts As Point3d 'start point
Dim pte As Point3d 'end point
Dim prPtRes As PromptPointResult = ed.GetPoint(vbLf & "Select insertion point: ")
pts = prPtRes.Value
pts.X = pts.X + 3 'pts.x throws an error
Solved! Go to Solution.
The ordinate (X, Y, Z) properties of that struct look to be read-only. How about using the Add() method?
Yea I think I found it. This seems totally silly to me to have this sort of thing. Whats the whoop about adding a number to an x or y?
pts.Add(New Vector3d(pts.X + 3, pts.Y, pts.Z))
You can try below code. It works for me according to your requirement:
<CommandMethod("CLT")> Public Sub CreateLineTest() Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim ed As Editor = doc.Editor Dim ppo As PromptPointOptions = New PromptPointOptions("") ppo.Message = vbLf & "Pick the first point of the line: " Dim ppr As PromptPointResult = ed.GetPoint(ppo) If ppr.Status = PromptStatus.Cancel Then Return End If Dim pts As Point3d = ppr.Value Dim pte As Point3d = New Point3d(pts.X + 3, pts.Y, pts.Z) Using tx As Transaction = db.TransactionManager.StartTransaction() Dim bt As BlockTable = tx.GetObject(db.BlockTableId, OpenMode.ForRead) Dim btr As BlockTableRecord = tx.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite) Dim ln As Line = New Line(pts, pte) btr.AppendEntity(ln) tx.AddNewlyCreatedDBObject(ln, True) tx.Commit() End Using End Sub
Thanks Zakir that worked great.
Is this the best methods to write a lot of lines and texts and layers in acad is to call a seperate function each time I need to do a simple thing like create a line? Can I call a transaction to cover a lot of instructions for line layer and the like then transaction commit to write the lines layers and what not to the database? Seems like it could cause some stack space problems calling functions like this?
Can you share a function for layer and text. If not I will figure it out at some point. I have a little bit of troubles with that on the samples from autodesk that seem to have some error. I can't debug since I am compiling under dll or I could find the problems.
Thanks for helping.
It comes down to the mathematical representation of the objects and the object-oriented nature of the programming. You aren't really changing the ordinate, you are displacing a point by a vector which can be in any of the axes. It makes sense over a data-centric thought process, more so when you are dealing with very complex operations.
As for the other example, continuously creating new Point3D objects can be OK for small routines but is probably a little inelegant for mutliple loops. For example, rather than create/destruct a new Point object and/or new Vector object every time, you manipulate the Vector contents for each loop, then apply the Vector to the Point.