Nesting a component in a selected component

Greetings, advise on the implementation of a solution.

For example, there is an empty box - 20,20,20 and need to put a cube 15,15,15.

There is an idea that would get the selected component, there seems to be no problem here, take the selections method and insert into it. But at the time of the insertion I can not think of how, that is, no special requirements, there is a box and in the void to insert a cube, unless, except that the cube does not need to draw, and just take the saved skp. I hope you can tell me what methods to do this, dug through the help, but I can not pick up.

You put this in both Ruby API and dynamic components categories, which require very different programming, so I don’t know which you mean. But I’ll write about Ruby since I don’t do much with DCs.

You need to get the Entities collection for the ComponentDefinition of which the selected object is an instance. Then you can add_group to nest it inside the Entities and subsequently add the required edges and faces to the nested group’s Entities. You can convert the nested Group to a Component if you need.

I’m on my phone now, so can’t post a code example.

Thank you, yes I put it in both categories since the question is more about components, but on the Ruby side. And just the same, then found the answer to my question, in part.

There is a method for adding a component to the project, everything is OK. It is possible to place it at specified coordinates, and here I have difficulties.

It turns out that since the nested component has its own coordinates xyz, you must first find it, find out its coordinates and only then insert it. From here, there is an idea. Isn’t there something in the methods for replacing, in fact, what the menu item “swap component” does. Searched through the documentation, but found nothing yet, on the search some discussions are, but not a method.

That menu command is on the Dynamic Components submenu so it is part of Trimble proprietary extension code.

But you can do what it does as it is programmed in Ruby.

That’s the thing, I understand that the function used by the Trimble is explicitly described in the api. But I can’t find the method to replace the component in the documentation. Maybe someone on the forum can tell me.

The ComponentInstance#definition= (definition) instance_method is used to set the component definition for this component.

This method causes the instance to use a different definition, but it will use the same transformation to position it in the Model.

1 Like

Well that method is only part of what the DC swap component command does.

I suggest you run the command and write down the steps that happen. These steps will be the thing your code will also need to accomplish. It will take several methods and some looping statements(s).