How to use function autocomplete?

AJ_Ratkovich
AJ_Ratkovich Member Posts: 4 PRO

I am trying to write my own functions with feature script. I want to use autocomplete the way the standard onshape functions do. The problem is I can't get it to work. I've been copying what I see in the standard library with no luck:

Here's a dummy function with what I'm trying

export function dummyFunction(id is Id) returns array{
/**
* @param id : @autocomplete `id + "dummy" (forum is doing weird formatting things when I include the closing ` but it's there in my code)
*
**/
 return [];
}

Which in theory should give me dummyFunction(id + "dummy") when I call it. But I keep getting just dummyFunction(id).

What am I doing wrong?

Best Answer

  • MichaelPascoe
    MichaelPascoe Member Posts: 2,959 PRO
    edited March 2025 Answer ✓

    Here is one of Onshape's, try this format instead:

    /**
     * Attach an attribute to one or several entities. Will overwrite any attribute previously set on the same entity
     * with the same name.
     *
     * @param definition {{
     *      @field entities {Query} : Entities to attach attribute to. Throws an error if the query resolves to nothing.
     *      @field name {string} : The name of the attribute @autocomplete `"myName"`
     *      @field attribute : The data to set. Can be any type. If `undefined` is provided, any existing attribute
     *          will be unset (and this entity will no longer resolve in [qHasAttribute] and similar functions)
     *          @autocomplete `"myValue"`
     *
     *          Legacy unnamed attributes:
     *          If name is not provided, adds an unnamed attribute to the entities. If more than one unnamed attribute
     *          with the same type is set on any entity, throws an error.
     * }}
     */
    export function setAttribute(context is Context, definition is map)
    precondition
    {
        definition.entities is Query;
        definition.name is string || definition.attribute != undefined;
    }
    {
        @setAttribute(context, definition);
    }
    

    RENDERCAD - Photorealistic product rendering.
    CADSharp - Professional CAD + software consulting.

    ▚▞▚▞▚▞▚▞▚

Answers

  • MichaelPascoe
    MichaelPascoe Member Posts: 2,959 PRO
    edited March 2025 Answer ✓

    Here is one of Onshape's, try this format instead:

    /**
     * Attach an attribute to one or several entities. Will overwrite any attribute previously set on the same entity
     * with the same name.
     *
     * @param definition {{
     *      @field entities {Query} : Entities to attach attribute to. Throws an error if the query resolves to nothing.
     *      @field name {string} : The name of the attribute @autocomplete `"myName"`
     *      @field attribute : The data to set. Can be any type. If `undefined` is provided, any existing attribute
     *          will be unset (and this entity will no longer resolve in [qHasAttribute] and similar functions)
     *          @autocomplete `"myValue"`
     *
     *          Legacy unnamed attributes:
     *          If name is not provided, adds an unnamed attribute to the entities. If more than one unnamed attribute
     *          with the same type is set on any entity, throws an error.
     * }}
     */
    export function setAttribute(context is Context, definition is map)
    precondition
    {
        definition.entities is Query;
        definition.name is string || definition.attribute != undefined;
    }
    {
        @setAttribute(context, definition);
    }
    

    RENDERCAD - Photorealistic product rendering.
    CADSharp - Professional CAD + software consulting.

    ▚▞▚▞▚▞▚▞▚
  • AJ_Ratkovich
    AJ_Ratkovich Member Posts: 4 PRO

    Ah I see, the placement is different. Thanks!!