Valued Contributor
Posts: 99
Registered: ‎10-03-2011
Message 1 of 6 (1,350 Views)

Convert line to polyline

1350 Views, 5 Replies
10-28-2012 10:51 AM

Hello Forum,


I want to convert a line (Autodesk.AutoCAD.DatabaseServices.Line) to a polyline (Autodesk.AutoCAD.DatabaseServices.Polyline).


Currently I get all the properties from the line, create a new polyline with it and delete the line. I fear data may get lost this way. What is the best way to convert a line to a polyline?


// Line properties:
// Color.
// Layer.
// Linetype.
// Linetype scale.
// Plot style.
// Lineweight.
// Hyperlink.
// Thickness.
// Material.
// Start X.
// Start Y.
// Start Z.
// End X.
// End Y.
// End Z.
// Start point.
// End point.

 Thank you.

ADN Support Specialist
Posts: 749
Registered: ‎03-21-2011
Message 2 of 6 (1,240 Views)

Re: Convert line to polyline

11-04-2012 09:48 PM in reply to: Ertqwa

Here is a sample code that sends a PEDIT command using acedCmd :


        <DllImport("acad.exe", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Cdecl, EntryPoint:="acedCmd")> _
        Private Shared Function acedCmd(ByVal vlist As System.IntPtr) As Integer
        End Function

        <CommandMethod("L2PL")> _
        Public Sub Line2Pline()
            ' get the autocad editor instance
            Dim ed As Autodesk.AutoCAD.EditorInput.Editor = _
            Autodesk.AutoCAD.ApplicationServices. _
            ' get a select set of entities in the dwg window
            Dim selection As PromptSelectionResult = ed.GetSelection()
            ' if the selection was successful
            If selection.Status = PromptStatus.OK Then
                ' create a new .NET resbuf struct
                Dim rbCommand As New Autodesk.AutoCAD.DatabaseServices.ResultBuffer
                ' create the buildlist
                rbCommand.Add( _
                New Autodesk.AutoCAD.DatabaseServices.TypedValue(5005, "_PEDIT")) ' RTSTR
                Dim id As ObjectId
                For Each id In selection.Value.GetObjectIds()
                    rbCommand.Add( _
                    New Autodesk.AutoCAD.DatabaseServices.TypedValue(5006, id)) ' RTENAME
                ' exit out of entity selection
                rbCommand.Add( _
                New Autodesk.AutoCAD.DatabaseServices.TypedValue(5005, "Yes")) ' RTSTR

                rbCommand.Add( _
                New Autodesk.AutoCAD.DatabaseServices.TypedValue(5005, "")) ' RTSTR
                ' now call the zoom to objects command
            End If
        End Sub



Developer Technical Services
Autodesk Developer Network

Valued Mentor
Posts: 370
Registered: ‎05-06-2012
Message 3 of 6 (1,213 Views)

Re: Convert line to polyline

11-05-2012 07:42 PM in reply to: Ertqwa

You don't really need to do the nitty-gritty work related to P/Invok'ing acedCmd() in releases of AutoCAD later than 2009. You can use the non-public RunCommand method of the Editor ciass via reflection to do it much more easily.


See this swamp post for the code:



*Expert Elite*
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 6 (1,187 Views)

Re: Convert line to polyline

11-06-2012 01:49 PM in reply to: DiningPhilosopher

I used your suggestion about using SendStringToExecute in other topic,

seems to me it will work nice, perhaps I mised something oot not sure, i.e.


        public  void testSendStringToExecute()
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            doc.CommandWillStart += new CommandEventHandler(doc_CommandWillStart);
           // doc.SendStringToExecute("PEDIT M (SSGET \"P\")  J   ",true,false,false);//ok           
           // doc.SendStringToExecute("_CIRCLE PAUSE PAUSE ", true, false, false);//ok
            doc.SendStringToExecute("FILLET R 10 P PAUSE ", true, false, false);//ok
        void doc_CommandWillStart(object sender, CommandEventArgs e)
            ((Document)sender).CommandWillStart -= doc_CommandWillStart;
            ((Document)sender).CommandEnded+=new CommandEventHandler(doc_CommandEnded);
            ((Document)sender).CommandFailed += new CommandEventHandler(doc_CommandEnded);
            ((Document)sender).CommandCancelled += new CommandEventHandler(doc_CommandEnded);
        void doc_CommandEnded(object sender, CommandEventArgs e)
            // if (e.GlobalCommandName.ToUpper()=="PEDIT")
            // if (e.GlobalCommandName.ToUpper()=="CIRCLE")
                if (e.GlobalCommandName.ToUpper()=="FILLET")
                    "\nCommand {0} ended...",e.GlobalCommandName

 Regards, friend



Valued Contributor
Posts: 99
Registered: ‎10-03-2011
Message 5 of 6 (1,087 Views)

Re: Convert line to polyline

12-08-2012 11:37 PM in reply to: Balaji_Ram

Ty for the responses,


unfortunately PEDIT does not affect lines inside a block.

Valued Contributor
Posts: 99
Registered: ‎10-03-2011
Message 6 of 6 (1,086 Views)

Re: Convert line to polyline

12-08-2012 11:38 PM in reply to: DiningPhilosopher

That is a nice tip, ty!

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
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.