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 find the id of several bodies in "Query" with several mouse Picks

FdaFda Member Posts: 42 ✭✭
I am trying to pass the body id to rename solids with a string + i (1,2,3 ...... etc)
annotation { "Feature Type Name" : "Name my_Part" }
export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        // Define the parameters of the feature type
        annotation { "Name" : "Nome", "Default" : "Part_" }
        definition.Name_Part  is string;

        annotation { "Name" : "My Query", "Filter" : EntityType.BODY, "MaxNumberOfPicks" : 20 }
        definition.parts is Query;


    }
    {
        // Define the function's action
        var myString = definition.Name_Part;

        var parts is array = evaluateQuery(context, definition.parts);

        //println(parts[1]);

        for (var i = 0; i < size(definition.Name_Part); i += 1)
        {

            //println(someString~i);
            setProperty(context, {
                        "entities" : definition.parts,
                        "propertyType" : PropertyType.NAME,
                        "value" : myString ~ i
                    });


        }
    });


Best Answer

Answers

  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    edited March 2020
    for (var i = 0; i < size(definition.Name_Part); i += 1)
            {
    setProperty(context, { "entities" : parts[i], "propertyType" : PropertyType.NAME, "value" : myString ~ i });
    }
    this should work, but you may need to reset part studio properties first, if you renamed parts manually.


  • FdaFda Member Posts: 42 ✭✭
    Thanks konstantin_shiriazdanov, but it doesn't work.
    I need to find a way to go to
     "entities":
    The id one of each "body"

    But I am somewhat lost.

    for (var i = 0; i < size(definition.Name_Part); i += 1)
            {
    setProperty(context, { "entities" : parts[i], "propertyType" : PropertyType.NAME, "value" : myString ~ i });
    }
    this should work, but you may need to reset part studio properties first, if you renamed parts manually.




  • FdaFda Member Posts: 42 ✭✭
    This code works :)
    Thanks konstantin_shiriazdanov
    I leave it in the forum in case someone can help you.
    annotation { "Feature Type Name" : "Name myPart" }
    export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            // Define the parameters of the feature type
            annotation { "Name" : "Nome", "Default" : "Part_" }
            definition.Name_Part is string;
    
            annotation { "Name" : "My Query", "Filter" : EntityType.BODY}
            definition.parts is Query;
    
    
        }
        {
            // Define the function's action
            var myString = definition.Name_Part;
            var parts is array = evaluateQuery(context, definition.parts);
    
            for (var i = 0; i < size(parts); i += 1)
            {
                setProperty(context, {
                            "entities" :parts[i],
                            "propertyType" : PropertyType.NAME,
                            "value" : myString ~ i
                        });
    
                
            }
        });

Sign In or Register to comment.