Interactive input and selection

ICadInputApi returns user input without launching a standard drawing command. Await GetPointAsync or another input method, check Accepted, then use Point or Entities to create/edit geometry. Never use .Wait()/.Result on the UI thread. Carry the returned Document into the next request.

Esc returns cancelled; explicitly permitted empty input returns none. CancellationToken cancellation throws OperationCanceledException. CursorPoint is provisional. Changing the document, view or geometry cancels input. Transient previews are not saved and create no Undo entry.

Coordinates are WCS millimetres and angles are degrees. Angles and rectangles use the current drawing plane. Drag left-to-right for window selection and right-to-left for crossing selection. Type/layer lists use OR within each list and AND across lists. Refresh face/edge references after geometry changes.

Complete projects are in ApiExamples/InputCS and InputVB, and Customization/SDK/Samples/Customization.InputCS and Customization.InputVB. They provide two-point lines, circle previews and selection-copy commands. Loading custom DLLs requires STD/Pro.

Methods and results

MethodUse
GetPointAsyncPick a point; passing a base point enables rubber-band feedback. Uses current snapping.
GetCornerAsyncPreview a rectangle in the current drawing plane and return its opposite corner.
GetDistanceAsync / GetAngleAsyncUse a base point and cursor, or numeric entry. Number is in mm/degrees.
GetIntegerAsync / GetDoubleAsyncEnter integer/real values with defaults and optional bounds.
GetStringAsync / GetKeywordsAsyncEnter text/a keyword. Text contains the result; keywords allow unique prefixes.
GetEntityAsync / GetSelectionAsyncPick one/multiple entities. Enter accepts; Kinds/Layers filter results.
GetSubentityAsyncPick face/edge; Subobjects contains topology references.
SelectRegionAsyncall/window/crossing selection; observe visibility and locking options.
DragAsync / UpdateInputPreviewAsyncPreview up to 256 lines/circles from the provisional cursor position.
StartInputAsync / GetInputAsync / CancelInputAsyncSeparate start, poll and cancel calls for MCP and other clients.

Two-point line

The following code implements IAddinCommand. In C#, import System, System.Threading, System.Threading.Tasks and JDesignCAD.Api with using; in VB.NET, use Imports for the same namespaces. The supplied projects contain the complete namespace, registration code and addin.json.

C#

public sealed class TwoPointLineCommand : IAddinCommand
{
    public async Task<CommandResult> ExecuteAsync(ICadApi api,CancellationToken cancellationToken)
    {
        var input=(ICadInputApi)api;
        var doc=await api.GetDocumentAsync(cancellationToken);

        // 1点目をユーザーが指示するまで待つ。
        var first=await input.GetPointAsync(doc,"1点目を指示してください",cancellationToken:cancellationToken);
        if(!first.Accepted)return new CommandResult("");

        // 1点目からマウス位置へラバーバンドを表示し、2点目を待つ。
        var second=await input.GetPointAsync(first.Document,"2点目を指示してください",
            basePoint:first.Point,cancellationToken:cancellationToken);
        if(!second.Accepted)return new CommandResult("");

        var a=first.Point!;var b=second.Point!;
        if(Math.Sqrt(Math.Pow(b.X-a.X,2)+Math.Pow(b.Y-a.Y,2)+Math.Pow(b.Z-a.Z,2))<=1e-6)
            return new CommandResult("異なる2点を指示してください。");

        // ここからが自作の作図処理。標準の線分コマンドは呼ばない。
        await api.CreateGeometryAsync(new CreateGeometryRequest(
            second.Document.Id,second.Document.Revision,Guid.NewGuid().ToString("D"),
            new[]{new LineDefinition(a,b)},Array.Empty<CircleDefinition>()),cancellationToken);
        return new CommandResult("");
    }
}

VB.NET

Public NotInheritable Class TwoPointLineCommand
        Implements IAddinCommand
        Public Async Function ExecuteAsync(api As ICadApi, cancellationToken As CancellationToken) As Task(Of CommandResult) Implements IAddinCommand.ExecuteAsync
            Dim input = DirectCast(api, ICadInputApi)
            Dim doc = Await api.GetDocumentAsync(cancellationToken)

            ' 1点目をユーザーが指示するまで待つ。
            Dim first = Await input.GetPointAsync(doc, "1点目を指示してください", cancellationToken:=cancellationToken)
            If Not first.Accepted Then Return New CommandResult("")

            ' 1点目からマウス位置へラバーバンドを表示し、2点目を待つ。
            Dim second = Await input.GetPointAsync(first.Document, "2点目を指示してください", basePoint:=first.Point, cancellationToken:=cancellationToken)
            If Not second.Accepted Then Return New CommandResult("")
            Dim a = first.Point
            Dim b = second.Point
            If Math.Sqrt((b.X - a.X) ^ 2 + (b.Y - a.Y) ^ 2 + (b.Z - a.Z) ^ 2) <= 0.000001 Then Return New CommandResult("異なる2点を指示してください。")

            ' ここからが自作の作図処理。標準の線分コマンドは呼ばない。
            Await api.CreateGeometryAsync(New CreateGeometryRequest(
                second.Document.Id, second.Document.Revision, Guid.NewGuid().ToString("D"),
                New LineDefinition() {New LineDefinition(a, b)}, Array.Empty(Of CircleDefinition)()), cancellationToken)
            Return New CommandResult("")
        End Function
    End Class

Nested block picks, fence/polygon selection, keyword branching during point input and arbitrary 3D-geometry Jigs are not exposed. This is not a binary-compatible AutoCAD API.

MCP input lifecycle

cad_start_input begins a request; cad_get_input polls its state; cad_cancel_input cancels it. cad_update_input_preview changes transient lines/circles. cad_select_region performs filtered region selection. Waiting is not acceptance: only an accepted result contains confirmed user input.