Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

How to use function autocomplete?

AJ_RatkovichAJ_Ratkovich Member Posts: 4

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

  • MichaelPascoeMichaelPascoe Member Posts: 2,196 PRO
    edited March 27 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);
    }
    

    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   Learn How to FeatureScript Here 🔴

Answers

  • MichaelPascoeMichaelPascoe Member Posts: 2,196 PRO
    edited March 27 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);
    }
    

    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   Learn How to FeatureScript Here 🔴
  • AJ_RatkovichAJ_Ratkovich Member Posts: 4

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

Sign In or Register to comment.