Jump to content

LineType Generation when creating polylines


Proctor

Recommended Posts

Hello: I'm working in AutoCad 2009 for .net api. If I draw a 2d polyline, I can use the LinetypeGenerationOn method for it to set the linetype generation = true; however, i don't know how to do this for when drawing a simple 1d polyline? (via my code). This method is not available for the simple polys.

 

Here's code that works for the 2dpoly:

 

_

PublicSharedSub drawPolyline()

Dim myTransMan As DatabaseServices.TransactionManager

Dim myTrans As DatabaseServices.Transaction

Dim myDWG As Autodesk.AutoCAD.ApplicationServices.Document

Dim myBT As DatabaseServices.BlockTable

Dim myBTR As Autodesk.AutoCAD.DatabaseServices.BlockTableRecord

Try

Dim myPoints AsNew Geometry.Point3dCollection

myPoints.Add(New Geometry.Point3d(0, 0, 0))

myPoints.Add(New Geometry.Point3d(2, 2, 0))

myPoints.Add(New Geometry.Point3d(4, 0, 0))

myPoints.Add(New Geometry.Point3d(6, 2, 0))

myPoints.Add(New Geometry.Point3d(8, 0, 0))

'Get the active document and begin a Transaction

myDWG = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

Dim docLock As DocumentLock = myDWG.LockDocument()

myTransMan = myDWG.TransactionManager

myTrans = myTransMan.StartTransaction

 

myBT = myDWG.Database.BlockTableId.GetObject(DatabaseServices.OpenMode.ForRead)

myBTR = myBT(BlockTableRecord.ModelSpace).GetObject(DatabaseServices.OpenMode.ForWrite)

Dim myOneRowPoly AsNew DatabaseServices.Polyline2d(DatabaseServices.Poly2dType.SimplePoly, myPoints, 0, False, 0, 0, Nothing)

myOneRowPoly.LinetypeGenerationOn = TruemyBTR.AppendEntity(myOneRowPoly)

myTrans.AddNewlyCreatedDBObject(myOneRowPoly, True)

myOneRowPoly.Visible = True

myOneRowPolyLength = myOneRowPoly.Length

myOneRowPolyNew = myOneRowPoly

'Commit the Transaction

myTrans.Commit()

myTrans.Dispose()

 

Catch ex As Autodesk.AutoCAD.Runtime.Exception

MsgBox(ex.Message)

Finally

'trans.Dispose()

EndTry

EndSub

 

Thank you,

Proctor

Link to comment
Share on other sites

sorry about that Lee Mac, let me try that again - previewing it, i see that doing it this way makes a big difference:

 

 

 
<CommandMethod("dp")> _
PublicSharedSub drawPolyline()
Dim myTransMan As DatabaseServices.TransactionManager
Dim myTrans As DatabaseServices.Transaction
Dim myDWG As Autodesk.AutoCAD.ApplicationServices.Document
Dim myBT As DatabaseServices.BlockTable
Dim myBTR As Autodesk.AutoCAD.DatabaseServices.BlockTableRecord
Try
Dim myPoints AsNew Geometry.Point3dCollection
myPoints.Add(New Geometry.Point3d(0, 0, 0))
myPoints.Add(New Geometry.Point3d(2, 2, 0))
myPoints.Add(New Geometry.Point3d(4, 0, 0))
myPoints.Add(New Geometry.Point3d(6, 2, 0))
myPoints.Add(New Geometry.Point3d(8, 0, 0))
'Get the active document and begin a Transaction
myDWG = Autodesk.AutoCAD.ApplicationServices.Application.D ocumentManager.MdiActiveDocument
Dim docLock As DocumentLock = myDWG.LockDocument()
myTransMan = myDWG.TransactionManager
myTrans = myTransMan.StartTransaction

myBT = myDWG.Database.BlockTableId.GetObject(DatabaseServ ices.OpenMode.ForRead)
myBTR = myBT(BlockTableRecord.ModelSpace).GetObject(Databa seServices.OpenMode.ForWrite)
Dim myOneRowPoly AsNew DatabaseServices.Polyline2d(DatabaseServices.Poly2 dType.SimplePoly, myPoints, 0, False, 0, 0, Nothing)
myOneRowPoly.LinetypeGenerationOn = TruemyBTR.AppendEntity(myOneRowPoly)
myTrans.AddNewlyCreatedDBObject(myOneRowPoly, True)
myOneRowPoly.Visible = True
myOneRowPolyLength = myOneRowPoly.Length
myOneRowPolyNew = myOneRowPoly
'Commit the Transaction
myTrans.Commit()
myTrans.Dispose()

Catch ex As Autodesk.AutoCAD.Runtime.Exception
MsgBox(ex.Message)
Finally
'trans.Dispose()
EndTry
EndSub

author: Jerry Winters

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...