Posts: 825
Registered: ‎06-08-2007
Message 1 of 2 (152 Views)

trouble convert .net polyline to com lwpolyline

152 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
            Exit Sub

            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


                        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.Tag = oPolyline
                            End If
                    End If

                End Using
            End Using
        End If
    End Sub

 and still something with the object type

Civil 3D 2012
Work: Xeon W3503, 12GB, Quadro 2000, Yamakasi Sparta 301 + Dell PH2211
Home: 3930k, 12GB, GTX 590, U3011, QX2710
Posts: 825
Registered: ‎06-08-2007
Message 2 of 2 (139 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)






Civil 3D 2012
Work: Xeon W3503, 12GB, Quadro 2000, Yamakasi Sparta 301 + Dell PH2211
Home: 3930k, 12GB, GTX 590, U3011, QX2710
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.