Extract 3D information to regenerate the shape
-
Hi,
I am going to expand a piece of software that calculates radiation in a 3D environment. For now we create the 3D environment by using simple basic shapes like boxes,spheres,cylinders,... . All those different shapes which form the complete 3D environment are listed in a database. This database saves which kind of shape it is and some parameters to determine the size, place and rotation in the coordinate system.
For example if I want to create a simple box I insert following in the database:
- type:Box* First corner coordinates (X,Y,Z)* Width,Length and Heigth* Rotation from X-,Y- or Z-axis
We want to expand our software so we don't have to insert every shape in the database, but can draw those shapes in a CAD program. My plan is to find a CAD program that's able to draw a 3D sketch with basic shapes and can give me the parameters according it's geometrical position in the coordinate system. I was wondering if this is possible with Sketchup (Pro)?
Once I can retrieve the parameters of the shapes I can create a little program that translates those parameters into the parameters that our piece of software understands.
Kind regards
Ruts -
You can use ruby scripting for this. For instance, if I make a cube of 1m by 1m, and group it, I can print the dimensions to the console by selecting it and using this:
grp = Sketchup.active_model.selection[0]; puts "Width; #{grp.local_bounds.width}\nDepth; #{grp.local_bounds.depth}\nHeight #{grp.local_bounds.height}";
The API can be found here: http://www.sketchup.com/intl/en/developer/index
-
Thanks for your respons oceanembers,
So let's say I have drawn a cube with a random rotation somewhere in the coordinate system. Is it possible to extract all the information like centeroid of the cube, width/length/heigth and rotation matrix or angles with ruby scripting? If this is the case this seems very intresting.
It would also be nice if it detects which space figure it is by itself.
Kind regards
Ruts -
SketchUp is a surface modeler. Everything in SketchUp is basically made up of edges, vertices, and faces.
There are no complex built-in 3D shape classes in the SketchUp Ruby API.
Instead primitives are either grouped into
Group
class instances, orComponentInstance
class instances. (Each have a definingComponentDefinition
class instance.)These mentioned classes are all sub-classes of
Entity
, and inherit it's functionality (as well as the intermediateDrawingelement
class functionality.)Any
Entity
subclass instance can have any number ofAttributeDictionary
instances attached to them. You can put whatever custom data you wish into attributes in a custom dictionary, usually named the same as your plugin. (Ex: "Ruts_Shaper_Properties")Back to the grouped 3D shape. Groups and components have a built-in definition name and each instance of them can have a separate more unique instance name. Group and component instances have built-in transformation property, from which you can query all the translational, rotational, scaling and axial subproperties. See the
Geom::Transformation
class.All
Drawingelement
subclasses (the objects that can be seen in the model,) have an invisible boundingbox, from which you can get the corners and the center. See theGeom::BoundingBox
class.It would be more efficient to create the basic shapes as an external SKP component library, and insert them into the model, rather than draw each using code, but drawing them adhoc can be done.
You should most likely install the SketchUp Team's example Shapes plugin, and study the code.
http://extensions.sketchup.com/en/search/site/Shapes
Advertisement