Author Topic: eInvalidInput when trying to offset Polyline2d  (Read 3005 times)

0 Members and 1 Guest are viewing this topic.

Proctor

  • Guest
eInvalidInput when trying to offset Polyline2d
« on: April 15, 2008, 06:35:06 PM »
Hello: I'm working w/ the curves class - offsetting polylines and inserting blocks along the offset curves. This works great for simple polys; however, when i try to run it on a polyline2d type, it bombs on the following line:

Code: [Select]
Dim pt As Point3d = newPl.GetPointAtDist((12 / num) * z)
Here's the code I'm running that leads up to it:

Code: [Select]
Sub OffsetMyPoly(ByVal pEstimatePolyId, ByVal dDouble)
        Try
            Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
            Dim num As Double = iModulesPerUnit 'this number represents the distance between the leds given the product chosen
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database

            Using trans As Transaction = ed.Document.TransactionManager.StartTransaction()
                Dim ent As Entity = DirectCast(trans.GetObject(pEstimatePolyId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead), Entity)
              [color=red]'Was using this line and changed it to the line below it.
                Dim pl As Polyline = DirectCast(ent, Polyline) [/color]
                [color=red]Dim pl As Polyline2d = DirectCast(ent, Polyline2d)[/color]

                Dim curves As DBObjectCollection = pl.GetOffsetCurves(-dDouble)
                Dim bt As BlockTable = doc.Database.BlockTableId.GetObject(Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead)
                Dim btr As BlockTableRecord = bt(BlockTableRecord.ModelSpace).GetObject(Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite)
                Dim blkdef As BlockTableRecord = bt(sBlockName).GetObject(Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead)

                For i As Integer = 0 To curves.Count - 1
                   [color=red]'Was using this line and changed it to the line below it
                     Dim newPl As Polyline = DirectCast(curves.Item(i), Polyline)[/color]
                   [color=red] Dim newPl As Polyline2d = DirectCast(curves.Item(i), Polyline2d)[/color]
                    'GET LENGTH OF NEW POLY
                    Dim length As Double = newPl.Length
                    'use the length of the poly chosen to tell us how many leds(blocks) to insert
                    Dim noOfLeds As Integer = CInt((length / 12) * num)
                    'MEASURE
                    For z As Integer = 0 To noOfLeds - 1
                       [color=red] 'bombs on this line:
                        Dim pt As Point3d = newPl.GetPointAtDist((12 / num) * z)[/color]                       
                        Dim endPoint As Point3d = newPl.GetPointAtDist(((12 / num) * z) + 0.1)
                        Dim v As Vector3d = endPoint - pt
                        Dim plane As New Plane(New Point3d(0, 0, 0), New Vector3d(0, 0, 1))
                        Dim ang As Double = v.AngleOnPlane(plane)
                        Dim blkref As New BlockReference(pt, bt(sBlockName))
                        btr.AppendEntity(blkref)
                        blkref.Rotation = ang
                        trans.AddNewlyCreatedDBObject(blkref, True)
                    Next
                    ed.Regen()
                    trans.Commit()
                    '/MEASURE
                Next
                curves.Dispose()

            End Using
        Catch ex As Autodesk.AutoCAD.Runtime.Exception
            MsgBox(ex.Message)
        Finally
            'trans.Dispose()
        End Try
    End Sub

Does anyone have any idea what I'm doing wrong?

Thanks for your help,
Proctor

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: eInvalidInput when trying to offset Polyline2d
« Reply #1 on: April 15, 2008, 08:12:27 PM »
Hi Proctor,
I believe that you must add the newly offset pline to a block (ModelSpace being a block) before you can query for the point. This allowed the code to run without failing (I did comment out irrelevant portions):
Code: [Select]
                    Dim newPl As Polyline2d = DirectCast(curves.Item(i), Polyline2d)
                    btr.AppendEntity(newPl)
but the Offset pline was not in the drawing still. Changing it to this did so....
Code: [Select]
                    Dim newPl As Polyline2d = DirectCast(curves.Item(i), Polyline2d)
                    btr.AppendEntity(newPl)
                    trans.AddNewlyCreatedDBObject(newPl, True)
If this worked on LWPlines, did you have similar code that was skipped over in creating this one for the 2d plines?

Proctor

  • Guest
Re: eInvalidInput when trying to offset Polyline2d
« Reply #2 on: April 16, 2008, 11:26:22 AM »
Boy...do I have a lot to learn. That makes sense...and it's working now!!! Thank you so much.

I'm not sure why it was working for the LWPline? I didn't create the new poly in modelspace ....

Anyway, thanks again for your help!!!
Proctor