2015-06-15 23 views
8

Die Editor-Klasse verfügt über eine Methode namens GetString, die den Benutzer über die Befehlszeile von AutoCAD zur Eingabe eines Zeichenfolgenwerts auffordert. Ich nenne es in dieser Wrapper-Methode:Standardwert für die Zeichenfolgeneingabe festlegen

public static string PromptUserForString(string message = "Enter a string: ", string defaultAnswer = "") 
{ 
    return _editor.GetString("\n" + message).StringResult; 
} 

Das Argument Nachricht wird die Nachricht der Benutzer, wenn für eine Zeichenfolge aufgefordert sehen. Wie kann ich es so, dass der Wert der Standardantwort automatisch eingestellt wird die Antwort sein, so dass, wenn der Benutzer ENTER sofort, dass der Wert wie im Screenshot unten

enter image description here

So 1 wird wird automatisch als Antwort getippt können die Benutzer bedeutet entweder getroffen für den Wert 1 eingeben oder 1 zu antworten, was auch immer nicht-Standard ändern sie wollen

+0

Wissen Sie, ob es ein? gute API-Referenz? Ich wollte sehen, was alle Eigenschaften in der 'PromptResult'-Klasse sind und ob es Überladungen für 'GetString' gibt, aber alles, was ich finden kann, ist ein [einfaches Beispiel] (http://help.autodesk.com/view/ACD/2015/ENU /? Anleitung = GUID-203F2756-1BA6-4226-A505-B776ED8AF0FB). Es sieht so aus, als ob die JavaScript-API einige Eigenschaften für [PromptStringOptions] (http://app.autocad360.com/jsapi/v2/docs/[email protected]) hat, die Ihnen erlauben könnten, mit Standardwerten zu arbeiten. Ich habe mich gefragt, ob es da ist war eine Parallele in .NET. –

+0

Die PromptStringOptions ist definitiv das, wonach Sie suchen. Hier ist ein einführender Leitfaden für die API: http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html?url=WS1a9193826455f5ff2566ffd511ff6f8c7ca-caf7.htm,topicNumber=d0e30666 – Miiir

+0

Entschuldigung, hier ist der richtige Link: http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html?url=WS1a9193826455f5ff2566ffd511ff6f8c7ca-cf7.htm,topicNumber=d0e30666 – Miiir

Antwort

3

ich fügen Sie einen Code als Beispiel für die verschiedenen Eingabeaufforderungen:

using System; 
using System.Collections.Generic; 
using Autodesk.AutoCAD.EditorInput; 
using Autodesk.AutoCAD.Geometry; 
using Autodesk.AutoCAD.ApplicationServices; 

namespace EditorUtilities 
{ 
    /// <summary> 
    /// Prompts with the active document (MdiActiveDocument) 
    /// </summary> 
    public class EditorHelper : IEditorHelper 
    { 
     private readonly Editor _editor; 

     public EditorHelper(Document document) 
     { 
      _editor = document.Editor; 
     } 

     public PromptEntityResult PromptForObject(string promptMessage, Type allowedType, bool exactMatchOfAllowedType) 
     { 
      var polyOptions = new PromptEntityOptions(promptMessage); 
      polyOptions.SetRejectMessage("Entity is not of type " + allowedType); 
      polyOptions.AddAllowedClass(allowedType, exactMatchOfAllowedType); 
      var polyResult = _editor.GetEntity(polyOptions); 
      return polyResult; 
     } 

     public PromptPointResult PromptForPoint(string promptMessage, bool useDashedLine = false, bool useBasePoint = false, Point3d basePoint = new Point3d(),bool allowNone = true) 
     { 
      var pointOptions = new PromptPointOptions(promptMessage); 
      if (useBasePoint) 
      { 
       pointOptions.UseBasePoint = true; 
       pointOptions.BasePoint = basePoint; 
       pointOptions.AllowNone = allowNone; 
      } 

      if (useDashedLine) 
      { 
       pointOptions.UseDashedLine = true; 
      } 
      var pointResult = _editor.GetPoint(pointOptions); 
      return pointResult; 
     } 

     public PromptPointResult PromptForPoint(PromptPointOptions promptPointOptions) 
     { 
      return _editor.GetPoint(promptPointOptions); 
     } 

     public PromptDoubleResult PromptForDouble(string promptMessage, double defaultValue = 0.0) 
     { 
      var doubleOptions = new PromptDoubleOptions(promptMessage); 
      if (Math.Abs(defaultValue - 0.0) > Double.Epsilon) 
      { 
       doubleOptions.UseDefaultValue = true; 
       doubleOptions.DefaultValue = defaultValue; 
      } 
      var promptDoubleResult = _editor.GetDouble(doubleOptions); 
      return promptDoubleResult; 
     } 

     public PromptIntegerResult PromptForInteger(string promptMessage) 
     { 
      var promptIntResult = _editor.GetInteger(promptMessage); 
      return promptIntResult; 
     } 

     public PromptResult PromptForKeywordSelection(
      string promptMessage, IEnumerable<string> keywords, bool allowNone, string defaultKeyword = "") 
     { 
      var promptKeywordOptions = new PromptKeywordOptions(promptMessage) { AllowNone = allowNone }; 
      foreach (var keyword in keywords) 
      { 
       promptKeywordOptions.Keywords.Add(keyword); 
      } 
      if (defaultKeyword != "") 
      { 
       promptKeywordOptions.Keywords.Default = defaultKeyword; 
      } 
      var keywordResult = _editor.GetKeywords(promptKeywordOptions); 
      return keywordResult; 
     } 

     public Point3dCollection PromptForRectangle(out PromptStatus status, string promptMessage) 
     { 
      var resultRectanglePointCollection = new Point3dCollection(); 
      var viewCornerPointResult = PromptForPoint(promptMessage); 
      var pointPromptStatus = viewCornerPointResult.Status; 
      if (viewCornerPointResult.Status == PromptStatus.OK) 
      { 
       var rectangleJig = new RectangleJig(viewCornerPointResult.Value); 
       var jigResult = _editor.Drag(rectangleJig); 
       if (jigResult.Status == PromptStatus.OK) 
       { 
        // remove duplicate point at the end of the rectangle 
        var polyline = rectangleJig.Polyline; 
        var viewPolylinePoints = GeometryUtility.GetPointsFromPolyline(polyline); 
        if (viewPolylinePoints.Count == 5) 
        { 
         viewPolylinePoints.RemoveAt(4); // dont know why but true, probably mirror point with the last point 
        } 
       } 
       pointPromptStatus = jigResult.Status; 
      } 
      status = pointPromptStatus; 
      return resultRectanglePointCollection; 
     } 

     public PromptSelectionResult PromptForSelection(string promptMessage = null, SelectionFilter filter = null) 
     { 
      var selectionOptions = new PromptSelectionOptions { MessageForAdding = promptMessage }; 
      var selectionResult = String.IsNullOrEmpty(promptMessage) ? _editor.SelectAll(filter) : _editor.GetSelection(selectionOptions, filter); 
      return selectionResult; 
     } 

     public PromptSelectionResult PromptForSelection(PromptSelectionOptions promptSelectionOptions,SelectionFilter filter = null) 
     { 
      return _editor.GetSelection(promptSelectionOptions, filter); 
     } 

     public void WriteMessage(string message) 
     { 
      _editor.WriteMessage(message); 
     } 

     public void DrawVector(Point3d from, Point3d to, int color, bool drawHighlighted) 
     { 
      _editor.DrawVector(from, to, color, drawHighlighted); 
     } 
    } 
} 
+0

Perfekt , Vielen Dank! –

Verwandte Themen