Changement de repere d'un composant (Move Component Origin)

Bonjour tout le monde
pouvez vous svp m’aider sur un sujet, au fait je cherche à modifier avec un code ruby le repère d’un composant d’une position initiale par défaut à une nouvelle position que je choisisse .
merci d’avance

Are you trying to move a component definition’s insertion point ?

Please add your SketchUp edition and version to your forum profile.

The answer depends upon what version you are using.


Essayez-vous de déplacer le point d’insertion d’une définition de composant?

Veuillez ajouter votre édition et version de SketchUp à votre profil de forum.

La réponse dépend de la version que vous utilisez.

1 Like

merci dan
je suis en version sketchup make 2017

I’ll reply for SketchUp 2020 and later as changing the actual insertion point has been removed.
* This should also work for older versions.

Instead you apply a transitional transformation to all the definition’s entities.

# Transforms all the entities in a component so that the origin is moved to a new point.
#
# @param comp [Sketchup::ComponentDefinition, Sketchup::ComponentInstance]
# @param to_point [Array(Length,Length,Length), Geom::Point3d, Geom::Vector3d,
#   Geom::Transformation] - The new point for the origin or vector to move the entities by.
# @param uniquify [Boolean] Default is false - only used when comp is an instance.
def move_component_origin(comp, to_point, uniquify: false)
  if uniquify # comp must be an instance
    if !comp.is_a?(Sketchup::ComponentInstance)
      fail(TypeError,"Argument(1) must be Component Instance when uniquify is true.",caller)
    end
    comp = comp.make_unique
  end
  cdef = comp.respond_to?(:definition) ? comp.definition : comp
  if !cdef.is_a?(Sketchup::ComponentDefinition)
    fail(TypeError,"Component Definition or Instance expected for argument(1).",caller)
  end
  if to_point.is_a?(Geom::Transformation)
    t = to_point
  elsif to_point.is_a?(Geom::Vector3d)
    t = Geom::Transformation.new(to_point)
  elsif to_point.is_a?(Geom::Point3d) || to_point.is_a?(Array)
    t = Geom::Transformation.new(to_point.vector_to(ORIGIN))
  else
    fail(TypeError,"Transformation, Array, Point or Vector expected for argument(2).",caller)
  end
  cdef.entities.transform_entities( t, cdef.entities.to_a )
end

EDIT: fixed two places that need the new method call. (C# thinking got me.)

1 Like

merci grand dan, je vais essayer ça et vous tiendrais au courant

milles merci

1 Like