You can instead use the IDENTITY
transform. It is referenced by a global constant, defined by the SketchUp Ruby API, during startup. So it is always available, in any scope. (I showed using it in my 1st example, above.)
Simplified example:
mod = Sketchup.active_model
def1 = mod.selection[0].definition
copy = mod.entities.add_instance( def1, IDENTITY )
You can also just use Geom::Transformation::new
in place of IDENTITY
, because the class constructor (new
,) with no arguments, creates a new identify Transformation.
See API class documentation: Geom::Transformation::new()
ADD: Simplified copy method:
def copy_selected_component()
mod = Sketchup::active_model
sel = mod.selection
ents = mod.active_entities
return false if sel.empty?
cget = sel.grep( Sketchup::ComponentInstance )
return false if cget.empty?
cmp1 = cget.first
def1 = cmp1.definition
copy = ents.add_instance( def1, IDENTITY )
if copy.is_a?(Sketchup::ComponentInstance)
return copy
else
return false
end
end # method