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.
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
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
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
Ty for the responses,
unfortunately PEDIT does not affect lines inside a block.