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.

Transfer queries across different featurescripts

Federico_CasariniFederico_Casarini Member Posts: 9 PRO
edited May 2020 in FeatureScript
Hello everyone! Time for another super newbie questions, sorry in advance. I am trying to do something but I am struggling to find a way.

I have the following problem: I created a feature which runs a number of different operations. One of them is an opboolean subtraction of two intersecting  3D geometries. Now I want to query all the faces generated from this subtraction from another featurescript.  Is there a way to do it? I tried by creating a function which returns a query but it doesn't work. 

The code looks something like this (this is only for example):

FeatureScript 1287;
import(path : "onshape/std/geometry.fs", version : "1287.0");
import(path : pathtofirstfeaturescript, version : "1287.0"); annotation { "Feature Type Name" : "second_operation" }
export const second_operation = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
    }
    {
        var onlybooleanfaces = hollow_faces(context, id + "boolean1");
        //highlight only the faces created by the opboolean on the first featurescript
        debug(context, onlybooleanfaces);
    }); </code><span>FeatureScript 1287; </span><span>import(path : "onshape/std/geometry.fs", version : "1287.0"); </span>annotation { "Feature Type Name" : "first_operation" }<br>export const first_operation = defineFeature(function(context is Context, id is Id, definition is map)<br><span>&nbsp; &nbsp; precondition </span>&nbsp; &nbsp; {<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp;fCuboid(context, id + "cuboid1", {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"corner1" : vector(0, 0, 0) * inch,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"corner2" : vector(1, 1, 1) * inch<br>&nbsp; &nbsp; &nbsp; &nbsp;});<br>&nbsp; &nbsp; &nbsp; &nbsp;fCuboid(context, id + "cuboid2", {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"corner1" : vector(0, 0, 0) * inch,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"corner2" : vector(2, 2, 2) * inch<br>&nbsp; &nbsp; &nbsp; &nbsp;});<br>&nbsp; &nbsp; &nbsp; &nbsp;var allsolids = qAllModifiableSolidBodies();<br>&nbsp; &nbsp; &nbsp; &nbsp;var smallcube = qNthElement(allsolids, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp;var bigcube = qNthElement(allsolids, 1);<br>&nbsp; &nbsp; &nbsp; &nbsp;opBoolean(context, id + "boolean1", {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"tools" : smallcube,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"targets": bigcube,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"operationType" : BooleanOperationType.SUBTRACTION<br><span>&nbsp; &nbsp; &nbsp; &nbsp;}); </span>&nbsp; &nbsp; });<br>export function hollow_faces(context is Context, id is Id) returns Query<br>{<br>return qCreatedBy(id, EntityType.FACE);<br>} </pre><br>Second featurescript on different tab:<br><br><pre class="CodeBlock"><code>

Thanks in advance!

Fed

Comments

  • Federico_CasariniFederico_Casarini Member Posts: 9 PRO
    Also, somehow when I posted this question with the code formatted I could only see the first line. Is there anything in particular I need to do to show the full size code with the correct format?   
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,684
    For the code format, set the format first, then past your code into it, not the other way around (crazy I know).

    The only way I can think of "transferring" data from one feature to another is to use attributes to tag the faces. See setAttribute / getAttribute.
    Senior Director, Technical Services, EMEAI
  • lemon1324lemon1324 Member, Developers Posts: 225 EDU
    +1 on setting attributes, it's pretty easy to deal with.  You can check out Auto Layout for an example of using attributes to tag parts that have had a feature interact with them.  Note that I'm "namespacing" the attribute name to reduce the chances someone else's attribute would interfere. You could do something similar to make sure different copies of your feature don't interact in a way you don't want.
    Arul Suresh
    PhD, Mechanical Engineering, Stanford University
  • Federico_CasariniFederico_Casarini Member Posts: 9 PRO
    That worked perfectly, thanks Neil and Arul for your help! Really appreciated it.

    Fed


Sign In or Register to comment.