Multiple polylines as separate entities

Multiple polylines as separate entities

Anonymous
Not applicable
1,094 Views
4 Replies
Message 1 of 5

Multiple polylines as separate entities

Anonymous
Not applicable

Hi People,

     Is it possible to create several 3Dpolylines in one transaction without them being joined up? I'm attempting to do this in VB.NET

 

I've managed to put four start and and end co-ordinates in but they all join together.

 

It feels wrong to do them as seperate transactions.....but I've been wrong before 😄

 

All comments appreciated.

 

Regards

Les

 

0 Likes
Accepted solutions (1)
1,095 Views
4 Replies
Replies (4)
Message 2 of 5

norman.yuan
Mentor
Mentor

Of course you can start a Transaction and add many Entities into database and commit the Transaction at once. Something like (Pseudo-code):

 

using (var tran=TheDB.TransactionManager.StartTransaction())

{

    var space=(BlockTableRecord)tran.GetObject(TheDb.CurrentSpaceId,OpenMode.ForWriet);

 

    //Assume you have a few sets of points for building polylines, each set is a Point3dCollection

    for (Point3dCollection pointSet in MyPointsSets) 

    {

        var poly=new Point3d(PolyLineType.SimplePoly, pointSet, true);

        poly.SetDatabaseDefault();

        //Set other entity properties, if necessary

        space.Append(poly);

        tran.AddNewlyCreatedObject(poly, true);

    }

 

    tran.Commit();

}

 

As you can see you can create as many entities in one transaction and only commit it once (well, you may not want to do hundreds of thousands at once, though).

 

Even you add one entity to database with each time opening a transaction/commit, you may not notice much different by doing for quite a few entities. It is certainly "OK", if not a best practice.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 5

Anonymous
Not applicable

Well... I'm using a 3D point collection....and appending each pair of co-ordinates for the polyline seperately but they all tend to join up?

 

                ' Create 3D polylines ( points)

                Dim acPoly3d As Polyline3d = New Polyline3d()

                acPoly3d.SetDatabaseDefaults()

                'acPoly3d.ColorIndex = 5  'Blue
                'acPoly3d.Layer = 0

                ' Add the new polyline object to the block table record and the transaction
                acBlkTblRec.AppendEntity(acPoly3d)
                acTrans.AddNewlyCreatedDBObject(acPoly3d, True)

                ' Before adding vertexes, the polyline must be in the drawing
                'Create a pts collection
                Dim acPts3dPoly1 As Point3dCollection = New Point3dCollection()
                acPts3dPoly1.Add(New Point3d(douBP_PointXA1, douBP_PointYA1, 0)) 'Start of first line
                acPts3dPoly1.Add(New Point3d(douBP_PointXA2, douBP_PointYA2, 0)) 'End of first line
                'Add vertices
                For Each acPt3d As Point3d In acPts3dPoly1
                    Dim acPolVer3d As PolylineVertex3d = New PolylineVertex3d(acPt3d)
                    acPoly3d.AppendVertex(acPolVer3d)
                    acTrans.AddNewlyCreatedDBObject(acPolVer3d, True)
                Next

                'Create a pts collection
                Dim acPts3dPoly2 As Point3dCollection = New Point3dCollection()
                acPts3dPoly2.Add(New Point3d(douBP_PointXA3, douBP_PointYA3, 0)) 'Start of second line
                acPts3dPoly2.Add(New Point3d(douBP_PointXA4, douBP_PointYA4, 0)) 'End of second line
                'Add vertices
                For Each acPt3d As Point3d In acPts3dPoly2
                    Dim acPolVer3d As PolylineVertex3d = New PolylineVertex3d(acPt3d)
                    acPoly3d.AppendVertex(acPolVer3d)
                    acTrans.AddNewlyCreatedDBObject(acPolVer3d, True)
                Next
                'Create a pts collection
                Dim acPts3dPoly3 As Point3dCollection = New Point3dCollection()
                acPts3dPoly3.Add(New Point3d(douBP_PointXA5, douBP_PointYA5, 0)) 'Start of second line
                acPts3dPoly3.Add(New Point3d(douBP_PointXA6, douBP_PointYA6, 0)) 'End of second line
                'Add vertices
                For Each acPt3d As Point3d In acPts3dPoly3
                    Dim acPolVer3d As PolylineVertex3d = New PolylineVertex3d(acPt3d)
                    acPoly3d.AppendVertex(acPolVer3d)
                    acTrans.AddNewlyCreatedDBObject(acPolVer3d, True)
                Next
                'Create a pts collection
                Dim acPts3dPoly4 As Point3dCollection = New Point3dCollection()
                acPts3dPoly4.Add(New Point3d(douBP_PointXA7, douBP_PointYA7, 0)) 'Start of second line
                acPts3dPoly4.Add(New Point3d(douBP_PointXA8, douBP_PointYA8, 0)) 'End of second line
                'Add vertices
                For Each acPt3d As Point3d In acPts3dPoly4
                    Dim acPolVer3d As PolylineVertex3d = New PolylineVertex3d(acPt3d)
                    acPoly3d.AppendVertex(acPolVer3d)
                    acTrans.AddNewlyCreatedDBObject(acPolVer3d, True)
                Next

                ' Save the new objects to the database

                acTrans.Commit()

            End Using
        End If
        Me.Close()

Is it possible to get them as single lines without changing the type of line?

 

Regards

Les

0 Likes
Message 4 of 5

norman.yuan
Mentor
Mentor
Accepted solution

 

My code clearly shows to create multiple/individual polyline3d entities and add them into current space. However, your code CLEARLY only creates ONE polyline3d entity, and then your code keeps APPENDING vertices to the SAME/SINGLE polyline3d, thus you get what you want: SINGLE polyline3d is created.

 

If you want multiple polyline3d for each group of points, you need to create Polyline3d for each group of point, not append point to the only Polyline3d as vertex.

 

I am not sure what else I can say.

Norman Yuan

Drive CAD With Code

EESignature

Message 5 of 5

Anonymous
Not applicable

Ok, I'll have a look to see....... thank you .

 

 

UPDATE:-

That worked a treat. As suggested I added a polyline for each set of points and THEN added the vertices. Did it for each polyline.

 

Many Thanks

Regards

Les

 

Starting to look messy though, maybe I need to break it into functions, but that another story 😄

Here's the code to help other that might be doing similar.

 

            Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

                ' Open the Block TABLE for read

                Dim acBlkTbl As BlockTable
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)

                ' Open the Blocktable RECORD in Model space for write

                Dim acBlkTblRec As BlockTableRecord
                acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)

                ' Create arc Co-ords...

                Dim acArc1 As Arc = New Arc(New Point3d(douBP_PointXA2, (douBP_PointYA3), 0),
                                     dou_BP_Radius, douBP_RadStartAngle1, douBP_RadEndAngle1) ' In Radians
                acBlkTblRec.AppendEntity(acArc1)
                acTrans.AddNewlyCreatedDBObject(acArc1, True)

                Dim acArc2 As Arc = New Arc(New Point3d(douBP_PointXA5, douBP_PointYA4, 0),
                                     dou_BP_Radius, douBP_RadStartAngle2, douBP_RadEndAngle2) ' In Radians
                acBlkTblRec.AppendEntity(acArc2)
                acTrans.AddNewlyCreatedDBObject(acArc2, True)

                Dim acArc3 As Arc = New Arc(New Point3d(douBP_PointXA6, (douBP_PointYA7), 0),
                                     dou_BP_Radius, douBP_RadStartAngle3, douBP_RadEndAngle3) ' In Radians
                acBlkTblRec.AppendEntity(acArc3)
                acTrans.AddNewlyCreatedDBObject(acArc3, True)

                Dim acArc4 As Arc = New Arc(New Point3d(douBP_PointXA1, douBP_PointYA8, 0),
                                     dou_BP_Radius, douBP_RadStartAngle4, douBP_RadEndAngle4) ' In Radians
                acBlkTblRec.AppendEntity(acArc4)
                acTrans.AddNewlyCreatedDBObject(acArc4, True)


                ' Create 3D polylines
                Dim acPoly3d1 As Polyline3d = New Polyline3d()
                acPoly3d1.SetDatabaseDefaults()

                'acPoly3d.ColorIndex = 5  'Blue
                'acPoly3d.Layer = 0
                ' Add the new polyline object to the block table record and the transaction
                acBlkTblRec.AppendEntity(acPoly3d1)
                acTrans.AddNewlyCreatedDBObject(acPoly3d1, True)

                ' Before adding vertexes, the polyline must be in the drawing
                'Create a pts collection
                Dim acPts3dPoly1 As Point3dCollection = New Point3dCollection()
                acPts3dPoly1.Add(New Point3d(douBP_PointXA1, douBP_PointYA1, 0)) 'Start of first line
                acPts3dPoly1.Add(New Point3d(douBP_PointXA2, douBP_PointYA2, 0)) 'End of first line

                'Add vertices
                For Each acPt3d As Point3d In acPts3dPoly1
                    Dim acPolVer3d As PolylineVertex3d = New PolylineVertex3d(acPt3d)
                    acPoly3d1.AppendVertex(acPolVer3d)
                    acTrans.AddNewlyCreatedDBObject(acPolVer3d, True)
                Next


                Dim acPoly3d2 As Polyline3d = New Polyline3d()
                acPoly3d2.SetDatabaseDefaults()

                'acPoly3d.ColorIndex = 5  'Blue
                'acPoly3d.Layer = 0

                ' Add the new polyline object to the block table record and the transaction
                acBlkTblRec.AppendEntity(acPoly3d2)
                acTrans.AddNewlyCreatedDBObject(acPoly3d2, True)
                'Create a pts collection
                Dim acPts3dPoly2 As Point3dCollection = New Point3dCollection()
                acPts3dPoly2.Add(New Point3d(douBP_PointXA3, douBP_PointYA3, 0)) 'Start of second line
                acPts3dPoly2.Add(New Point3d(douBP_PointXA4, douBP_PointYA4, 0)) 'End of second line
                'Add vertices
                For Each acPt3d As Point3d In acPts3dPoly2
                    Dim acPolVer3d As PolylineVertex3d = New PolylineVertex3d(acPt3d)
                    acPoly3d2.AppendVertex(acPolVer3d)
                    acTrans.AddNewlyCreatedDBObject(acPolVer3d, True)
                Next


                Dim acPoly3d3 As Polyline3d = New Polyline3d()
                acPoly3d3.SetDatabaseDefaults()

                'acPoly3d.ColorIndex = 5  'Blue
                'acPoly3d.Layer = 0

                ' Add the new polyline object to the block table record and the transaction
                acBlkTblRec.AppendEntity(acPoly3d3)
                acTrans.AddNewlyCreatedDBObject(acPoly3d3, True)

                'Create a pts collection
                Dim acPts3dPoly3 As Point3dCollection = New Point3dCollection()
                acPts3dPoly3.Add(New Point3d(douBP_PointXA5, douBP_PointYA5, 0)) 'Start of second line
                acPts3dPoly3.Add(New Point3d(douBP_PointXA6, douBP_PointYA6, 0)) 'End of second line
                'Add vertices
                For Each acPt3d As Point3d In acPts3dPoly3
                    Dim acPolVer3d As PolylineVertex3d = New PolylineVertex3d(acPt3d)
                    acPoly3d3.AppendVertex(acPolVer3d)
                    acTrans.AddNewlyCreatedDBObject(acPolVer3d, True)
                Next


                Dim acPoly3d4 As Polyline3d = New Polyline3d()
                acPoly3d4.SetDatabaseDefaults()

                'acPoly3d.ColorIndex = 5  'Blue
                'acPoly3d.Layer = 0

                ' Add the new polyline object to the block table record and the transaction
                acBlkTblRec.AppendEntity(acPoly3d4)
                acTrans.AddNewlyCreatedDBObject(acPoly3d4, True)
                'Create a pts collection
                Dim acPts3dPoly4 As Point3dCollection = New Point3dCollection()
                acPts3dPoly4.Add(New Point3d(douBP_PointXA7, douBP_PointYA7, 0)) 'Start of second line
                acPts3dPoly4.Add(New Point3d(douBP_PointXA8, douBP_PointYA8, 0)) 'End of second line
                'Add vertices

                For Each acPt3d As Point3d In acPts3dPoly4
                    Dim acPolVer3d As PolylineVertex3d = New PolylineVertex3d(acPt3d)
                    acPoly3d4.AppendVertex(acPolVer3d)
                    acTrans.AddNewlyCreatedDBObject(acPolVer3d, True)
                Next

                ' Save the new objects to the database

                acTrans.Commit()

            End Using

 

0 Likes