wow, why the heck am i adding it to the block table record? that's a very good question....
ok...also, sorry that I didn't include all the code...i'll be sure to from now on.
I remmed out the code that appends the poly to the table record, however, now it errors out on the line below:
Dim pt As Point3d = newPl.GetPointAtDist((12 / num) * z)
I'm confused as to when I need to add the poly to the block table record.
here's the full code:
Public Shared Sub OffsetMyPoly(ByVal pEstimatePolyId, ByVal dDouble)
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
Dim trans As Transaction
trans = ed.Document.TransactionManager.StartTransaction()
Dim ent As Entity = DirectCast(trans.GetObject(pEstimatePolyId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead), Entity)
Dim curves As DBObjectCollection
Dim pl As Polyline2d = DirectCast(ent, Polyline2d)
Try
curves = pl.GetOffsetCurves(dDouble)
trans.Dispose()
For i As Integer = 0 To curves.Count - 1
trans = ed.Document.TransactionManager.StartTransaction()
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)
Dim docLock As DocumentLock = doc.LockDocument()
Dim newPl As Polyline2d = DirectCast(curves.Item(i), Polyline2d)
[color=red][font=Verdana]
'remming this out now
'btr.AppendEntity(newPl)[/font][/color]
'when this line is added, it creates the offset polyline.
'trans.AddNewlyCreatedDBObject(newPl, True)
Call AddLayer()
''GET LENGTH OF NEW POLY
Dim length As Double
length = 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)
If dCount = 0 Then
dCount = noOfLeds
Else
dCount = dCount + noOfLeds
End If
Call WriteLEDCount(dCount, newPl, curves.Count, i)
For z As Integer = 0 To noOfLeds - 1
[color=red]
'erroring out on this line now
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))
blkref.Layer = myLayerName 'Derrived from sub AddLayer()
btr.AppendEntity(blkref)
blkref.Rotation = ang
trans.AddNewlyCreatedDBObject(blkref, True)
Next
ed.Regen()
trans.Commit()
trans.Dispose()
Application.DocumentManager.MdiActiveDocument.LockDocument.Dispose()
Next
curves.Dispose()
Catch ex As Autodesk.AutoCAD.Runtime.Exception
MsgBox(ex.Message)
Finally
End Try
End Sub