.NET

.NET

Reply
Mentor
wang890
Posts: 831
Registered: ‎06-08-2007
Message 1 of 2 (159 Views)

trouble convert .net polyline to com lwpolyline

159 Views, 1 Replies
10-08-2013 11:28 AM

i used .net selection and selected a few polylines in modelspace. but i need to convert it to acadobject lwpolyline or 2 whatever in order to feed it to civil 3d volume surface boundary but that's another story i am not quite there yet. just having trouble getting the polyline acadobject. there is one website showed up on google but company blocked it.

 

originally i just use the

 

ob = oAcadDB.ObjectIdToObject(prEntityRes.ObjectId.OldIdPtr)

then used the ctype lwpolyline but didn't work.

 

which worked for my other objects like points. guess i haven't tried polylines yet.

 

then i used this:

 

 Private Sub btnSelPoly_Click(sender As System.Object, e As System.EventArgs) Handles btnSelPoly.Click


        Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor

        Dim prSelectionOptions As PromptSelectionOptions = New PromptSelectionOptions
        Dim prSelectionRes As PromptSelectionResult = ed.GetSelection(prSelectionOptions)

        If prSelectionRes.Status = PromptStatus.Error Then
            Me.Show()
            Exit Sub
        Else

            Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim acCurDb As Database = acDoc.Database
            Using lock As DocumentLock = acDoc.LockDocument
                Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
                    Dim acDocEd As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor

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

                    Dim obj As DBObject
                    If prSelectionRes.Value.Count <> 0 Then

                        lvwPolyline.Items.Clear()

                        For i As Integer = 0 To prSelectionRes.Value.Count - 1
                            obj = acTrans.GetObject(prSelectionRes.Value.Item(i).ObjectId, OpenMode.ForWrite)
                            If TypeOf obj Is Polyline Then

                                Dim oPolylineNet As Polyline = CType(obj, Polyline)
                                Dim oPolyline As AcadPolyline = oPolylineNet.AcadObject
                                Dim lvwItem As ListViewItem = lvwPolyline.Items.Add(oPolyline.ObjectID)
                                lvwItem.SubItems.Add(oPolyline.Layer)
                                lvwItem.Tag = oPolyline
                            End If
                        Next
                    End If


                    acTrans.Commit()
                End Using
            End Using
        End If
    End Sub

 and still something with the object type

Civil 3D 2014
Work: i7 4770, SSD, 16GB, K2000, Dell PH2414H
Home: i7 3930k, SSD, 16GB, GTX 590, U3011
Mentor
wang890
Posts: 831
Registered: ‎06-08-2007
Message 2 of 2 (146 Views)

Re: trouble convert .net polyline to com lwpolyline

10-08-2013 12:24 PM in reply to: wang890

ah never mind. this worked fine. maybe i had a typo when typing acadlwpolyline into acadpolyine.

 

    

For i AsInteger = 0 To prSelectionRes.Value.Count - 1

                obj = oAeccDb.ObjectIdToObject(prSelectionRes.Value.Item(i).ObjectId.OldIdPtr)

               

Dim oPolyline AsAcadLWPolyline = CType(obj, AcadLWPolyline)

                MsgBox(oPolyline.Coordinate(0).ToString)

           

Next

 

 

Civil 3D 2014
Work: i7 4770, SSD, 16GB, K2000, Dell PH2414H
Home: i7 3930k, SSD, 16GB, GTX 590, U3011
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.