.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Convert line to polyline

5 REPLIES 5
Reply
Message 1 of 6
Ertqwa
3524 Views, 5 Replies

Convert line to polyline

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.

5 REPLIES 5
Message 2 of 6
Balaji_Ram
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

Message 3 of 6
DiningPhilosopher
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

Message 4 of 6
Hallex
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
Message 5 of 6
Ertqwa
in reply to: Balaji_Ram

Ty for the responses,

 

unfortunately PEDIT does not affect lines inside a block.

Message 6 of 6
Ertqwa
in reply to: DiningPhilosopher

That is a nice tip, ty!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost