.NET

Reply
Valued Contributor
jaboone
Posts: 91
Registered: ‎12-05-2011
Message 1 of 9 (326 Views)
Accepted Solution

How to add length to a point3d

326 Views, 8 Replies
08-14-2013 06:44 AM

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

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

 

 

*Expert Elite*
dgorsman
Posts: 5,515
Registered: ‎10-12-2006
Message 2 of 9 (317 Views)

Re: How to add length to a point3d

08-14-2013 07:18 AM 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.
Adopt. Adapt. Overcome. Or be overcome.
A good question will be halfway to a good answer.


Valued Contributor
jaboone
Posts: 91
Registered: ‎12-05-2011
Message 3 of 9 (316 Views)

Re: How to add length to a point3d

08-14-2013 07:30 AM 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
Mentor
mzakiralam
Posts: 231
Registered: ‎11-09-2012
Message 4 of 9 (313 Views)

Re: How to add length to a point3d

08-14-2013 07:30 AM 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

 

 

Valued Contributor
jaboone
Posts: 91
Registered: ‎12-05-2011
Message 5 of 9 (301 Views)

Re: How to add length to a point3d

08-14-2013 07:51 AM 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
Mentor
mzakiralam
Posts: 231
Registered: ‎11-09-2012
Message 6 of 9 (296 Views)

Re: How to add length to a point3d

08-14-2013 08:01 AM 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.
Valued Contributor
jaboone
Posts: 91
Registered: ‎12-05-2011
Message 7 of 9 (289 Views)

Re: How to add length to a point3d

08-14-2013 08:17 AM 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
*Expert Elite*
dgorsman
Posts: 5,515
Registered: ‎10-12-2006
Message 8 of 9 (271 Views)

Re: How to add length to a point3d

08-14-2013 10:19 AM 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.
Adopt. Adapt. Overcome. Or be overcome.
A good question will be halfway to a good answer.


Mentor
mzakiralam
Posts: 231
Registered: ‎11-09-2012
Message 9 of 9 (256 Views)

Re: How to add length to a point3d

08-14-2013 02:51 PM 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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.