Component Rotation and movement

Hi,
I have a project in which I am moving a component based on the x,y, z values that I get from socket connection. I am able to move smoothly, however, when i have to rotate the component, moving the component becomes difficult, component moves in different direction. After googling, i found that it is because the component axis changes on rotation and sketchup always refer to the original component direction. To resolve this, I created a duplicate component after rotating it and deleted the existing one. However, the new components location w.r.t origin is 0,0,0, but the component is located at the earlier components place. To solve this I first copied the location of original component before deleting it and used this location to move the new component but still my component moves to a different location after rotation.

Code used for creating duplicate(from sketchup forum):

position= @componentInstance.transformation.origin
ents = @componentInstance.parent.entities # might be nested etc, so find its parent’s entities
group = ents.add_group() # initially empty
gents = group.entities
new_instance = gents.add_instance(@componentInstance.definition, @componentInstance.transformation)
new_instance.explode
new_component = group.to_component
#new_component.definition.name = $componentInstance.definition.name # auto increments
$modelsdef.remove(@componentInstance.definition)
new_component.definition.name = “3DMan”
new_component.name = “RockStar”
$modelsdef.add “3DMan”
$modelsdef = $model.definitions
findInstance("RockStar”)#for initializing the new component
new_transformation = Geom::Transformation.new(position)
@componentInstance.move! new_transformation

Any help will be really appreciated. Any suggestion to rotate and move component without disturbing the direction or location or create a duplicate component.

Suggest you use the Animation class and the #move! method.

Also … do not use global $variables. Use @variables inside your extension module.