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.

Newbie: parent-child relationship in feature script?

Hi,

I'm an absolut newbie in onshape, comming from a web dev / threejs background with a little openscad experience. I try to use a script to create some primitives in onshape, rotate and translate them, and use boolean operations on them. In threejs and openscad, this is easy - each object can have many child objects, and each parent object defines a coordinate system for its children. I know how to create primitives in feature script, how to rotate them - but how can I define a parent child relationship in feature script or at least define a group of primitives that can be rotated and translated as a whole?

Best Regards,
Sebastian Baltes

Best Answers

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 4,502
    Answer ✓
    No, there is no parent-child because it is feature-based, unlike Blender. A feature only knows details about it's own geometry unless you tag with attributes then query using https://cad.onshape.com/FsDoc/library.html#qHasAttribute-string
    Director, Technical Services, EMEA
  • chadstoltzfuschadstoltzfus Member, Developers Posts: 93 PRO
    Answer ✓
    It might be adding more steps than necessary, but I find it more comfortable to work with composite parts in situations like this. A composite part can act as the "parent" body and then you can use qContainedInCompositeParts() to access the "child" elements. This would also make it possible for you to do things like transforming the composite part outside of the custom feature without needing to select each part individually. 

    I would still recommend tagging the composite part itself with an attribute though, so you can create the distinction between the table and chair composite parts. It's worth noting that you can create composite parts of composite parts, so you could start going crazy with nesting if you want to, though I would recommend setting up some kind of attribute system (or even custom data types) before doing so. 

Answers

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 4,502
    Hi @sebastian_baltes not sure what you are trying to achieve here so a little context would help.

    If all the bodies are in the same feature and of the same type, a simple loop using this id pattern:
    id + "sphere" + i
    would allow you to select them all in one go, like this:
    qCreatedBy(id + "sphere", EntityType.BODY)

    Director, Technical Services, EMEA
  • sebastian_baltessebastian_baltes Member Posts: 4
    Hi Neil, thanks! Ok, I can use a query, but is there some other way - for example, when I construct a table, I make a tabletop and attach four legs to it. I can then rotate or translate the table as a whole, and it has a local coordinate system. If I build a chair from its parts, I can translate also them as a whole. Using boolean operations, I can get the intersection of a table and a chair. Is there something similar in onshape?

    What I try to achieve is a single feature that creates an equatorial platform for a telescope. Such a platform has at minimum two coordinate systems, a horizontal and an equatorial one. I need to create primitives in both coordinate systems and use boolean operations between them so that the platform can compensate for the rotation of the earth.

    Maybe in the feature I could use something like an attribute that I set on each body of the table, "part of the table", and one on each body of the chair. If a query could ask for all "parts of the table", that would be nice, even if it is not a real parent-child relationship because it is not hierarchical. In most game engines and in blender there is the concept of a scene graph that can be manipulated programmatically. 
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 4,502
    Answer ✓
    No, there is no parent-child because it is feature-based, unlike Blender. A feature only knows details about it's own geometry unless you tag with attributes then query using https://cad.onshape.com/FsDoc/library.html#qHasAttribute-string
    Director, Technical Services, EMEA
  • chadstoltzfuschadstoltzfus Member, Developers Posts: 93 PRO
    Answer ✓
    It might be adding more steps than necessary, but I find it more comfortable to work with composite parts in situations like this. A composite part can act as the "parent" body and then you can use qContainedInCompositeParts() to access the "child" elements. This would also make it possible for you to do things like transforming the composite part outside of the custom feature without needing to select each part individually. 

    I would still recommend tagging the composite part itself with an attribute though, so you can create the distinction between the table and chair composite parts. It's worth noting that you can create composite parts of composite parts, so you could start going crazy with nesting if you want to, though I would recommend setting up some kind of attribute system (or even custom data types) before doing so. 
Sign In or Register to comment.