My_forum_space
-
SU entities include basic geometry, like lines (or edges), and faces. A SU group is a unique collection of entities. An instance is a SU component that is one copy of a component definition. Groups have instances, and have ComponentDefinitions like ComponentInstances does.
Images have component definitions as well, like Groups, SU treats them slightly different. You can see when you iterate
model.definitions
that you also get Group and Image definitions. ComponentDefinition has.image?
and.group?
that allows you to identify the type of component definition you are dealing with. This is important to check if you are processing all definitions in a model.The difference between one instance and another, is its transformation; its spatial location, scale, and rotation. Editing the entities in a component instance, edits the entities in all instances of that component. Groups are unique instances. Caveat: when you have multiple group instances of the same group definition and edit one via the ruby API they are not automatically made unique. You must call
group.make_unique
first - otherwise you edit all the group copies. Besides basic geometry (lines, surfaces, circles, arcs, etc.), entities include groups, and instances (component instances).The basic level of "collecting stuff" is an array of
entities
. The next level of collection is a group of entities,group.entities
, and*instance.definition.entitites*
. The final level is a collection of instance definitions,model.definition
. Adding entities to the basic level is byentities.add_...
where...
is aSketchup::Entity
(eg.entities.add_line
).Before adding a
Sketchup::Entity
to entities, groups, instances, and components, one must be created, or identified. Identifying the basic entities in the existing model is first by identifying the current model, bymodel = Sketchup.active_model
, and then its entities byentities = model.active_entities
. Adding new entities to the collection of entities is as previously stated,entities.add_...
where...
is aSketchup::Entity
.Adding entities to a new group, instance, or component, requires creating a new group, instance, or component by,
entities.add_group
, or [ruby:gcaqewus]entities.add_instance[/ruby:gcaqewus]. For example, [ruby:gcaqewus]my_group = entities.add_group[/ruby:gcaqewus] creates a new group, [ruby:gcaqewus]my_group[/ruby:gcaqewus]. Entities added to my_group are by [ruby:gcaqewus]my_group.entities.add_...[/ruby:gcaqewus], as noted above. The same sequence applies when adding entities to new instances.New definitions are created by identifying the current collection of definitions by [ruby:gcaqewus]definitions = model.definitions[/ruby:gcaqewus], then adding a new one by [ruby:gcaqewus]my_definition = definitions.add "Description_of_definition"[/ruby:gcaqewus]. Adding an instance to my_definition is by [ruby:gcaqewus]my_definition.entities.add_instance(my_instance.definition, my_instance.transformation)[/ruby:gcaqewus].
The following code snippet changes a group into an instance, then adds the instance to a definition:
#get current model model = Sketchup.active_model #get current entities array entities = model.active_entities #get model's definitions array definitions = model.definitions #add new empty my_definition my_definition = definitions.add "My Selection" #make my_instance out of group my_instance = my_group.to_component #add my_instance to my_definition my_definition.entities.add_instance(my_instance.definition, my_instance.transformation)
Addenda: Where the previous is italicized, it reflects corrections by tt.
-
Unfortunately you are facing a bug in Sketchup.
-
I feel your pain. It seems that there is not much one can do about it. I'm hoping for that bug to be fixed, for sure!
-
As an ancient marina, the concepts of Ruby, and OPPS originally fail to easily register on my consciousness. The following is the degree to which I currently understand them as applied to SUs Ruby API.
A class is the generic form of an object. Objects within a class share the same class characteristics, the differences between objects are found in their variable differences. A class "box", results in objects, that differ in height, width, or length.
Methods nare procedures that dertermine a variable's value. For example, the boxes height = volume/(width*length).
A SU Ruby plugin is a program that utilized the SU Ruby API to affect a SU model.
Advertisement