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

How to add length to a point3d

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
jaboone
830 Views, 8 Replies

How to add length to a point3d

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

 

Learning as I go
8 REPLIES 8
Message 2 of 9
dgorsman
in reply to: jaboone

The ordinate (X, Y, Z) properties of that struct look to be read-only.  How about using the Add() method?

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 3 of 9
jaboone
in reply to: dgorsman

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))

Learning as I go
Message 4 of 9
mzakiralam
in reply to: jaboone

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

 regards

Zakir

 

 

Message 5 of 9
jaboone
in reply to: mzakiralam

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?

Learning as I go
Message 6 of 9
mzakiralam
in reply to: jaboone

I am not so much expert so I can not tell you that this is the best method. What I have experienced, if you add an geometric entity and a text entity in same transaction it took a bit time to execute the code. Otherwise, in a single transaction you can add as much as entity you can, there is no problem. Normally I try to add text entity with different transaction.
Message 7 of 9
jaboone
in reply to: mzakiralam

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.

Learning as I go
Message 8 of 9
dgorsman
in reply to: jaboone

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.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 9 of 9
mzakiralam
in reply to: jaboone

I can write some codes for you if you really want. Just tell me a spec. so that that could be helpful for you

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