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.

Help with instantiation

Dylan_TobeyDylan_Tobey Member Posts: 4

I'm a new FeatureScript user working to develop a custom feature which will allow a user to select a part studio containing one part and bring it into the a new document. However, I've run into some issues with the instantiation module, receiving the error below:

image.png

I've already looked at the standard documentation and tried to follow along with this post:

But I haven't had any luck resolving the error on my own. Any chance someone could point out where I'm going wrong?

FeatureScript 2641;
import(path : "onshape/std/common.fs", version : "2641.0");


annotation { "Feature Type Name" : "Add thing" }
export const addThing = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        annotation { "Name" : "Mounting mate connector", "Filter" : BodyType.MATE_CONNECTOR, "MaxNumberOfPicks" : 1 }
        definition.mountingConnector is Query;

        annotation { "Name" : "Choose part to import" }
        definition.partChoice is PartStudioData;
    }
    {

        const instantiator = newInstantiator(id + "inst", {});

        const toPlane = evMateConnector(context, { "mateConnector" : definition.mountingConnector })->plane();

        var toInstantiate = definition.partChoice;

        const instance = addInstance(instantiator, toInstantiate, { "transform" : transform(XY_PLANE, toPlane) });

        instantiate(context, instantiator);
        
        const instantiatedBodies = qCreatedBy(id + "inst", EntityType.BODY);
        const instantiatedFaces = qCreatedBy(id + "inst", EntityType.FACE);


    });

Comments

  • GregBrownGregBrown Member, Onshape Employees, csevp, pcbaevp Posts: 307

    Your code seems to be working fine… https://cad.onshape.com/documents/dfc1499f6151bb475715b537/w/ebf804f2164f2b92444e9890/e/0a5e680b4892d4d039632ffd

  • Dylan_TobeyDylan_Tobey Member Posts: 4

    Thanks for confirming the code itself was right. I figured out what I was doing wrong:

    image.png

    I was selecting "Part Studio 1" in the image without clicking the "Create version" button, first. Creating the version first resolves the issue and lets me bring in the part.

Sign In or Register to comment.