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:
Dim pt As Point3d = newPl.GetPointAtDist((12 / num) * z)
Here's the code I'm running that leads up to it:
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