Import model.skp loop

Im having trouble importing more than one model into my scetchup file.

This works fine:

mod = Sketchup::active_model
path='D:/Desktop/DroneRelated/SketchUp/FPVR.skp
cdef = mod.definitions.load(path)
Sketchup.active_model.place_component(cdef)
point = Geom::Point3d::new( 0, 0, 0 )
cinst = mod.active_entities.add_instance(
cdef,
Geom::Transformation::new( point )
)

But when i put it inside a loop it wont work like this:

track_file.each_with_index{|val, index| 

track_file[index].to_s if val.include?("test")
{
mod = Sketchup::active_model
path='D:/Desktop/DroneRelated/SketchUp/FPVR.skp
cdef = mod.definitions.load(path)
Sketchup.active_model.place_component(cdef)
point = Geom::Point3d::new( 0, 0, 0 )
cinst = mod.active_entities.add_instance(
cdef,
Geom::Transformation::new( point )
)

}
}

Any help would be greatly appreciated.
Cheers

Why are you calling Sketchup.active_model.place_component(cdef) when you then afterwards use entities.add_instance?

place_component is intended to hand over control to the user to make the placement of the component.

It’d help if you elaborated on what you observe and what you expected to happen. That makes it easier to provide a solution.

Sorry for the vague question.

What I would like to happen is that every time I find a specific word in my loop, in this case “test”, have my script insert a model at a set location.(Could be multiple times like 10-20, I’m yet to set the desired locations)… It does not need to give the user control like it appears to be doing.

I was calling Sketchup.active_model.place_component(cdef) because I read it on a forum, I didn’t realise it gave user control.

Sorry again should I update the first post?
Thanks Blaine

Sure it helps for readers new to the thread. Also …

Always refer to the API documents. In this case, the doc for that method is a bit vague. It should also warn you that it causes a undo commit, so it will disrupt a coder’s undo operation blocks.

If your code working as you expect when you remove place_component?