Author Topic: draw poly dot net sample like vba ThisDrawing.Utility.PolarPoint  (Read 4072 times)

0 Members and 1 Guest are viewing this topic.

jcoon

  • Newt
  • Posts: 155

I'm looking for help in drawing a polyline by selecting a start point, then a direction to set my xaxis. then I want to draw a polyline box based
on the selected start points and direction.

If it's possible I'd like something that works like my old vba sample (see below). I'm just not understanding how to create the same in dot net. I've tried several times to get started in dot net over that last year but end up giving up because I can't get all the parts linked together. If I can get a working sample that reproduces drawing a ployline box by direction I might be able to get over them hill and move forward. I have tons of old vba routines that basically draw tons of geometry and finally need to convert them to dot net.

any help is welcome

Thanks
john Coon



'this is basically what I was using in vba

point1 = ThisDrawing.Utility.GetPoint(, "Pick start point,")
point2 = ThisDrawing.Utility.GetPoint(point1, "Select Direction to draw")

Dim dblRot As Double
Dim pi As Double
pi = 3.14159265358979
 
dblRot = ThisDrawing.Utility.AngleFromXAxis(pt1, pt2)

Dim worldcoords As Integer
worldcoords = -ThisDrawing.GetVariable("WORLDUCS")
If worldcoords = 0 Then
dblRot = 0
If worldcoords = 1 Then
dblRot = ThisDrawing.Utility.AngleFromXAxis(pt1, pt2)
End If
End If



Dim newpt1001 As Variant
Dim newpt1002 As Variant
Dim newpt1003 As Variant
Dim newpt1004 As Variant
Dim newpt1005 As Variant
Dim newpt1006 As Variant

'draws threshold box

newpt1001 = ThisDrawing.Utility.PolarPoint(pt1, (pi + dblRot), -0#)
newpt1002 = ThisDrawing.Utility.PolarPoint(pt1, (pi + dblRot), -10)
newpt1003 = ThisDrawing.Utility.PolarPoint(newpt1001, (1.570796327 + dblRot), -100/2) 'from newpt1001 turn 90 deg angle,  set -100'
newpt1004 = ThisDrawing.Utility.PolarPoint(newpt1001, (1.570796327 + dblRot), 100/2)  'from newpt1001 turn 90 deg angle,  set 100'
newpt1005 = ThisDrawing.Utility.PolarPoint(newpt1002, (1.570796327 + dblRot), -100/2) 'from newpt1002 turn 90 deg angle,  set -100'
newpt1006 = ThisDrawing.Utility.PolarPoint(newpt1002, (1.570796327 + dblRot), 100/2)  'from newpt1002 turn 90 deg angle,  set 100'

 ' Call checkcombo1(cboLayer1.Text)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim DRWPOLYAPPR1 As AcadLWPolyline
Dim polyponts1(11) As Double


polyponts1(0) = newpt1001(0): polyponts1(1) = newpt1001(1)
polyponts1(2) = newpt1003(0): polyponts1(3) = newpt1003(1)
polyponts1(4) = newpt1005(0): polyponts1(5) = newpt1005(1)
polyponts1(6) = newpt1006(0): polyponts1(7) = newpt1006(1)
polyponts1(8) = newpt1004(0): polyponts1(9) = newpt1004(1)
polyponts1(10) = newpt1001(0): polyponts1(11) = newpt1001(1)


Set DRWPOLYAPPR1 = ThisDrawing.ModelSpace.AddLightWeightPolyline(polyponts1)
   


Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: draw poly dot net sample like vba ThisDrawing.Utility.PolarPoint
« Reply #1 on: October 18, 2010, 05:55:21 PM »
See if this helps

Code: [Select]


        // by Tony Tanzillo
        public static Point3d PolarPoint(Point3d basepoint, double angle, double distance)
        {
            return new Point3d(
                basepoint.X + (distance * Math.Cos(angle)),
                basepoint.Y + (distance * Math.Sin(angle)),
                basepoint.Z);
        }

Welcome to theSwamp.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

jcoon

  • Newt
  • Posts: 155
Re: draw poly dot net sample like vba ThisDrawing.Utility.PolarPoint
« Reply #2 on: October 18, 2010, 07:00:26 PM »
Tony,

Thanks, I'll see if I can use this sample.


'Could you show how to set a point from the known pt1  to  pt3 without entering the coords.

john

<CommandMethod("PolarPoints")> _
    Public Sub PolarPoints()
        Dim pt1 As Point2d ' 0,0
        ' dim pt3 As Point2d  10,0
        ' 10,5
        ' 0,5
        ' 0,0

        pt1 = PolarPoints(New Point2d(0, 0), 0, 10) , set pt1 from 0,0, angle =0 for 10'
     

        Application.ShowAlertDialog(vbLf & "PolarPoint: " & _
                                    vbLf & "X = " & pt1.X & _
                                    vbLf & "Y = " & pt1.Y)

        Dim pt2 As Point3d
        pt2 = PolarPoints(New Point3d(0, 0, 0), 0, 10) , set pt1 from 0,0,0 angle =0 for 10'


        Application.ShowAlertDialog(vbLf & "PolarPoint: " & _
                                    vbLf & "X = " & pt2.X & _
                                    vbLf & "Y = " & pt2.Y & _
                                    vbLf & "Z = " & pt2.Z)
    End Sub














john

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: draw poly dot net sample like vba ThisDrawing.Utility.PolarPoint
« Reply #3 on: October 18, 2010, 07:43:55 PM »

John,
Do you want to use COM or use the .NET arx-wrapped API

if COM, the  Autodesk.AutoCAD.Interop.IAcadUtility
has
PolarPoint(object Point, double Angle, double Distance);

which you may be more comfortable with if you just want a quick translation of the VBA.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

jcoon

  • Newt
  • Posts: 155
Re: draw poly dot net sample like vba ThisDrawing.Utility.PolarPoint
« Reply #4 on: October 19, 2010, 08:53:05 AM »
Kenny,

I think COM is the best for me at this point. Kenny I'm just trying to find some success so I can start to move forward with dot net. I'm not sure why I'm having so much difficulty transitioning from vba to vb dot net but I am. 

Thanks for your help.

John

Jeff_M

  • King Gator
  • Posts: 3957
  • C3D user & customizer
Re: draw poly dot net sample like vba ThisDrawing.Utility.PolarPoint
« Reply #5 on: October 19, 2010, 09:31:53 AM »
Hey, John, that's KERRY up there..... :-)

Keep on trying, the .NET stuff will finally click at some point. Have you gone through the Labs that come with the ObjectARX SDK?

Jeff_M

  • King Gator
  • Posts: 3957
  • C3D user & customizer
Re: draw poly dot net sample like vba ThisDrawing.Utility.PolarPoint
« Reply #6 on: October 19, 2010, 10:14:17 AM »
Here's a quick example using  the .NET managed API, John.
Code: [Select]
Imports System
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime


Public Class Rectangles

    <CommandMethod("MyRectangle")> _
    Public Sub MyRectangle()
        Dim startPt As Point3d
        Dim db As Database = HostApplicationServices.WorkingDatabase
        Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
        Dim opts As PromptPointOptions = New PromptPointOptions("Select a starting point: ")
        Dim prRes As PromptPointResult = ed.GetPoint(opts)
        If prRes.Status = PromptStatus.OK Then
            startPt = prRes.Value
            Dim pi As Double = Math.PI
            Dim upperLeft As Point3d = polarpoint(startPt, pi / 2, 100)
            Dim lowerRight As Point3d = polarpoint(startPt, 0, 100)
            Dim upperRight As Point3d = polarpoint(lowerRight, pi / 2, 100)
            Dim pline As Polyline = New Polyline()
            pline.AddVertexAt(0, Convert2d(startPt), 0, 0, 0)
            pline.AddVertexAt(1, Convert2d(upperLeft), 0, 0, 0)
            pline.AddVertexAt(2, Convert2d(upperRight), 0, 0, 0)
            pline.AddVertexAt(3, Convert2d(lowerRight), 0, 0, 0)
            pline.Closed = True
            Using tr As Transaction = db.TransactionManager.StartTransaction
                Dim bt As BlockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead, False)
                Dim btr As BlockTableRecord = tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite, False)
                Dim objId As ObjectId = btr.AppendEntity(pline)
                tr.AddNewlyCreatedDBObject(pline, True)
                tr.Commit()
            End Using
        End If

    End Sub

    Private Function polarpoint(ByVal basept As Point3d, ByVal angle As Double, ByVal distance As Double) As Point3d
        Return New Point3d(basept.X + (distance * Math.Cos(angle)), _
                basept.Y + (distance * Math.Sin(angle)), _
                basept.Z)
    End Function

    Private Function Convert2d(ByVal pt As Point3d) As Point2d
        Return New Point2d(pt.X, pt.Y)
    End Function

End Class

jcoon

  • Newt
  • Posts: 155
Re: draw poly dot net sample like vba ThisDrawing.Utility.PolarPoint
« Reply #7 on: October 19, 2010, 04:20:12 PM »
Jeff,

Thanks......I'm going to get it this time.

I'll try it at home tonight.

Thank you

John

jcoon

  • Newt
  • Posts: 155
Re: draw poly dot net sample like vba ThisDrawing.Utility.PolarPoint
« Reply #8 on: October 19, 2010, 04:25:44 PM »
Kerry.

So sorry!, I guess I was a little dyslexic this morning.
 
Hey, John, that's KERRY up there.....

Keep on trying, the .NET stuff will finally click at some point. Have you gone through the Labs that come with the ObjectARX SDK?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: draw poly dot net sample like vba ThisDrawing.Utility.PolarPoint
« Reply #9 on: October 19, 2010, 07:33:22 PM »
Kerry.

So sorry!, I guess I was a little dyslexic this morning.
 

No problems John ... I've been called much worse names :)

This is worth reading a couple of times, even though is is far from complete.
http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: draw poly dot net sample like vba ThisDrawing.Utility.PolarPoint
« Reply #10 on: October 20, 2010, 09:30:34 AM »
No problems John ... I've been called much worse names :)
Made me laugh, I guess b/c I have answered to those as well
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second