0 Members and 1 Guest are viewing this topic.
// Was something selected? if (ssResult.Status != PromptStatus.OK) { ed.WriteMessage("\nNothing was selected"); } // Something was selected else { ObjectId[] objIds = ssResult.Value.GetObjectIds(); return objIds; }
Yes, but you need to have a return if nothing was selected. So either in the first portion of the if statement, or after the if statement is executed.
// Was something selected? if (ssResult.Status != PromptStatus.OK) { ed.WriteMessage("\nNothing was selected"); return new ObjectId[] {}; } // Something was selected else { ObjectId[] objIds = ssResult.Value.GetObjectIds(); return objIds; }
Assuming that your function returns an ObjectId[], then yes.
You're welcome. With C#, you have to make sure that each path the code can take will return the type defined by the function.
using Autodesk.AutoCAD.ApplicationServices;using Autodesk.AutoCAD.DatabaseServices;using Autodesk.AutoCAD.EditorInput;using Autodesk.AutoCAD.Runtime;namespace My_AutoCAD_Managed_CS_Project_Application1{ public class GetEntity { [CommandMethod("Test")] public static void Testing() { Document doc = Application.DocumentManager.MdiActiveDocument; Transaction tr = doc.TransactionManager.StartTransaction(); ObjectId entity = GetSingleEntity(); var ent = (Entity)tr.GetObject(entity, OpenMode.ForWrite); ent.ColorIndex = 1; tr.Commit(); }// end Testing [CommandMethod("GetEntity")] public static ObjectId GetSingleEntity() { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; //Create a new entity selection options object var entitySelectionOpts = new PromptEntityOptions("\nSelect Object: "); //Start the selection process PromptEntityResult entitySelectionResult = ed.GetEntity(entitySelectionOpts); // Was something selected?... if (entitySelectionResult.Status != PromptStatus.OK) { ed.WriteMessage("\nNothing was selected"); return new ObjectId(); } // Something selected, so... else { ObjectId objIds = entitySelectionResult.ObjectId; return objIds; } }// end GetSingleEntity }// end class}// end namespace
return new ObjectId();
return ObjectId.Null;