I’m new to Dynamo and have been working on a script to get the centroid of solids. I’ve run into a problem where when a “void” is cut from a solid my script doesn’t seem to account for the cut-out in the solid.
Also, this is my first post. - I apologize if the images don’t come through correctly.
I’d appreciate any help. Thanks!
Have a look at the ‘surface inner centroid’ nodes from either the Genius Loci or Sparrow package. These use an algorithm to find the centroid of a form inside the form itself. You would need to generate a surface at the centre of the solid perpendicular to it I think though in order to get that surface, that part is likely tricky. Probably involves assessing the directionality of all the edges of the shape to determine the most common vector directions.
I’m not sure if you have an error in your script.
You can use the “Element.Solids” to extract the solids information from the element. (Will save you some filtering on the back-end.)
You are unioning the solids…which may result in the union of the cutting element (if you have, for example a collision-body.) I see from your input that you are collecting two elements and I assume you are joining two elements, which is why you get the centroid of the “uncut” element.
It is hard to tell exactly what you are doing, but I did this on a wall, using the profile functiion to get similar L-shaped geometry, and it worked just fine.
Thank you for the reply m.owens!
I think my issue has to do specifically with voids. - If I model a simple L shaped extrusion so that it is one solid, I can indeed get the correct centroid. - However if a void is used to cut out a portion of a simple rectangular extrusion to get the L shape, I am not able to get the correct centroid. - If I select the base solid, if doesn’t seem to recognize it has been cut. - If I select both the base extrusion and the void extrusion, it doesn’t seem to recognize the geometry has been cut either. - I need to ensure that my team can use voids as part of our modeling. - I tried using your Element.Solids but ended up getting independent centroids of the base extrusion and the void extrusion. - I created the filtering and union to exclude things like model lines, and other junk that is likely to end up in the selected geometry, and end up with the one solid to get the centroid of. - The pieces that this script will eventually be used on get quite complicated. I envision a window selection of a significant number of solid and void elements making up quite complex 3d panels.
Of interesting note. - The solid and void are inside of a Generic Model family where I am running the script. - if I leave the family editor and run the script on the family that has been inserted into a project, I do get the correct centroid. The final cut geometry is recognized. - That is good, however, I would like to be able to run the script within the family and insert a marker for the centroid there… Perhaps there is some way to run it at the project level, find the centroid, and then insert the centroid marker into the family in the correct location in the background? - That would perhaps be even better, but I was trying to take baby steps… I would actually like to account for materials too as some solids might be concrete, some steel, and some insulation, or other materials, all with very different densities. - some will be nested families too… again down the road, just trying to figure out what is going on with voids would be enough for now.