I would like to append the instance field as in the attached image


#1

comp_example_instancia.rb (425 Bytes)
new_comp_def = Sketchup.active_model.definitions.add(“MyCube”)
points = Array.new ;
points[0] = ORIGIN ;
points[1] = [100, 0 , 0] ;
points[2] = [100, 100, 0] ;
points[3] = [0 , 100, 0] ;
newface = new_comp_def.entities.add_face(points)
newface.reverse! if newface.normal.z < 0
newface.pushpull(100)
trans = Geom::Transformation.new
Sketchup.active_model.active_entities.add_instance(new_comp_def, trans)


#2
instance = Sketchup.active_model.active_entities.add_instance(new_comp_def, trans)
instance.name = "test"

#3

This reinserts the component.
I want to add in the exponent component created


#4

You misunderstood my post. I meant the first line to replace your last line with the sole purpose of capturing the reference to the new instance so you can give it a name in the next line. It wasn’t meant simply to append both lines to your code - which will indeed create a second instance!


#5

now I understand .
Thanks a lot for the help
Slbaumgartner
My native language is portuguese from Brazil because of this the misunderstanding

new_comp_def = Sketchup.active_model.definitions.add(“MyCube”)
points = Array.new ;
points[0] = ORIGIN ;
points[1] = [100, 0 , 0] ;
points[2] = [100, 100, 0] ;
points[3] = [0 , 100, 0] ;
newface = new_comp_def.entities.add_face(points)
newface.reverse! if newface.normal.z < 0
newface.pushpull(100)
trans = Geom::Transformation.new
instance = Sketchup.active_model.definitions
instance = Sketchup.active_model.active_entities.add_instance(new_comp_def, trans)
instance.name = “test”


#6

Not exactly.

You added a frivolous line of code, which I have commented out below:

new_comp_def = Sketchup.active_model.definitions.add("MyCube")
points = Array.new ; 
points[0] = ORIGIN ; 
points[1] = [100, 0 , 0] ; 
points[2] = [100, 100, 0] ; 
points[3] = [0 , 100, 0] ; 
newface = new_comp_def.entities.add_face(points)
newface.reverse! if newface.normal.z < 0 
newface.pushpull(100)
trans = Geom::Transformation.new
# instance = Sketchup.active_model.definitions
instance = Sketchup.active_model.active_entities.add_instance(new_comp_def, trans)
instance.name = "test"

Please put code in between code delimiter lines:

```ruby
# code goes here
```

(The code language can be: ruby, xml,c,javascript,html …)


#7

DanRathbun

How do I add this up in this code?

~ruby

group = entities.add_group face[0].faces[1].all_connected
group.layer = @layer 
componente = group.to_component
componente = componente.definition
componente.name = "C#1"
componente.description = "A36"

#8

You must use backtick characters (not # characters!)
The backtick is just above the TAB key. It has the tilde (~) on the key also.

Also, please start another topic thread for a different coding problem.
And, if this one has been answered, mark the post that solved it as the solution.
(Use the :heavy_check_mark: icon at the bottom of the post that you think is the soultion.)


#9

I showed you above, let me show you again (for the last time.)

Please put code in BETWEEN code delimiter lines:

```ruby
# code goes here
```


#10

This topic was automatically closed after 91 days. New replies are no longer allowed.