.NET

Reply
Valued Contributor
Ertqwa
Posts: 98
Registered: ‎10-03-2011
Message 1 of 6 (1,229 Views)

Convert line to polyline

1229 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
Balaji_Ram
Posts: 702
Registered: ‎03-21-2011
Message 2 of 6 (1,119 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. _
            Application.DocumentManager.MdiActiveDocument.Editor
            ' 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
                Next
                ' 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
                acedCmd(rbCommand.UnmanagedObject)
            End If
        End Sub

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 3 of 6 (1,092 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:

 

     http://www.theswamp.org/index.php?topic=43113.msg483306#msg483306

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 6 (1,066 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.

 

        [CommandMethod("tsend")]
        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")
            {
                Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(
                    "\nCommand {0} ended...",e.GlobalCommandName
                    );
               
            }
        }

 Regards, friend

 

Oleg

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Contributor
Ertqwa
Posts: 98
Registered: ‎10-03-2011
Message 5 of 6 (966 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
Ertqwa
Posts: 98
Registered: ‎10-03-2011
Message 6 of 6 (965 Views)

Re: Convert line to polyline

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

That is a nice tip, ty!

Need installation help?

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