Valued Contributor
99 Posts
4 Kudos
Registered: ‎10-03-2011
Post 1 of 6

Convert line to polyline

1384 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
762 Posts
100 Kudos
Registered: ‎03-21-2011
Post 2 of 6

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
370 Posts
175 Kudos
Registered: ‎05-06-2012
Post 3 of 6

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*
1,569 Posts
171 Kudos
Registered: ‎10-08-2008
Post 4 of 6

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
99 Posts
4 Kudos
Registered: ‎10-03-2011
Post 5 of 6

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
99 Posts
4 Kudos
Registered: ‎10-03-2011
Post 6 of 6

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
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!