How to transform lines and faces inside a component


Im struggling with this issue how to transform lines or faces inside a component. The code looks something like this:

model = Sketchup.active_model
ents = model.active_entities
defs = model.definitions 

wallcomponent_def = defs.add "YVWall"
wallcomponent_layer1_def = defs.add "YVWall_layer_1"

  t = [0,0,0]
  wallcomponent_def.entities.add_instance(wallcomponent_layer1_def, t)
  pts1 = []
  pts1[0] = [0,0,0]
  pts1[1] = [x_len,0,0]
  pts1[2] = [x_len,0,z]
  pts1[3] = [0,0,z]
  pts1b = []
  pts1b[0] = [layer_width,layer_width,0]
  pts1b[1] = [x_len-layer_width,layer_width,0]
  pts1b[2] = [x_len-layer_width,layer_width,z]
  pts1b[3] = [layer_width,layer_width,z]			

  front_base_line_1 = wallcomponent_layer1_def.entities.add_line pts1[0],pts1[1]
  front_top_line_1 = wallcomponent_layer1_def.entities.add_line pts1[2],pts1[3]

This is what I have tried which don’t work:

entities_to_transform = []


transform =[1000,0,0])
ents.transform_entities(transform, entities_to_transform)

Any help is appreciated

You are applying the ‘transform_entities’ to the model.active_entities [aka ‘ents’]
BUT the entities you pass are NOT in that entities collection… but in…
So the transformation will not work !
if you used:
wallcomponent_layer1_def.entities.transform_entities(transform, entities_to_transform)
the two newly added edges would transform 1000 inches east along the red-axis - however, perhaps not as you had hoped ??

In your last line, ents is referencing model.active_entities but you want to transform the Definition’s entities.


wallcomponent_layer1_def.entities.transform_entities(transform, entities_to_transform)

amazing! thanks both of you :slight_smile:

FYI: In SketchUp component definitions do not have a layer property, so associating a definition with a layer is pointless. Any instance of any definition, can be associated or re-associated, with any layer at any time, either manually or via code.

The end-goal is something like this:

YVWall # Main Component
| > YVWall_layer_1 # Component, and member of YVWall. Eg bricks
| > YVWall_layer_2 # Component, and member of YVWall. Eg insulation
| > YVWall_layer_3 # Component, and member of YVWall. Eg concrete

In each YVWall_layer_x there will be set an attribute to a face

The confusion arises from your use of the word ‘layer’ in the naming convention…
In SketchUp it’s assigned to an entity and is used to control visibility.

If you substituted another word for ‘layer’, then the confusion would be avoided, e.g.



ok I understand. The word layer is what we would use in my own language about different parts of a wall.

I might well use ‘layer’ too.:wink:
But for the avoidance of doubt / confusion, perhaps a non-sketchup sensitive word would be better.