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.

Instantiation within a function?

MichaelPascoeMichaelPascoe Member Posts: 1,952 PRO
edited April 2021 in FeatureScript
I'm modifying a custom feature. Instead of having the feature pattern a part, I would like it to create instantiations of a part. 

The feature uses a pattern operation inside a function. I replaced the pattern operation with an instantiator, but I get an error saying the instantiator transform needs to be a function. Usually the instantiator does not need the transform to be in function format. I'm not sure how to fix this. Can someone help explain what I'm doing wrong?

Error message:




Shortened version of the code:
function createBodyPattern(id is Id, context is Context, baseBody, mateConnector, coordMatrix, matSize, definition, cutDepth)
{
   
   //Old pattern operation

   opPattern(context, id + "pattern1", {
                "entities" : baseBody,
                "transforms" : transform,
                "instanceNames" : instanceNames
            });


    //New instantiator

    var x = .25 * inch;
    var y = .3 * inch;
    var z = .01 * inch;

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

    var queries = [];

    for (var i = 0; i < size(instancePlanes); i += 1)
    {

        var q = addInstance(instantiator, brick::build,
            { "configuration" : {
                        "width" : x,
                        "depth" : y,
                        "height" : z },
                "transform" : transform(XY_PLANE, instancePlanes[i]) //Error: Called value must be a function, value is array
            });

        queries = append(queries, q);

        q = append(queries, q);

    }

    instantiate(context, instantiator);
}






Learn more about the Gospel of Christ  ( Here )

CADSharp  -  We make custom features and integrated Onshape apps!   cadsharp.com/featurescripts 💎

Best Answers

  • MichaelPascoeMichaelPascoe Member Posts: 1,952 PRO
    edited April 2021 Answer ✓
    I think I'm on to it now. I need to make the instantiator transform match the function the old pattern was calling for. 

    Got it working, but i'm still not sure why it required the instantiation transform to be in function format.

    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   cadsharp.com/featurescripts 💎
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,210
    Answer ✓
    It's much better if you share a link to the document.  I suspect that the issue is actually in the part of the code you shortened -- you declared transform as a variable and that hid the transform function you're trying to call.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc

Answers

Sign In or Register to comment.