Hi. Can I help you ?
Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
š£ļø Road Profile Builder | Generate roads, curbs and pavements easily Download
P
Offline
Latest posts made by PRBO
-
RE: Looking for a developer to help create a custom Component im
-
How to copy a hole component inside to another component ?
I would like to know how to copy a hole-type component (for carpentry work) into an MDF-type component. The basic idea is: I have a hole-type component that, when applied to a surface, makes the cutout correctly. I copy it from the environment and paste it into the MDF component. However, when I do this, it does not cut via script. I have to go inside the MDF component and move the hole so that it makes the cutout. I would like to know if my scripting approach is wrong, if there is another easier way. I would like your help.
# Default code, use or delete... mod = Sketchup.active_model # Open model ent = mod.entities # All entities in model sel = mod.selection # Current selection def find_subentity_by_name(parent_instance, subentity_name) #p parent_instance.definition.name if parent_instance.is_a?(Sketchup::ComponentInstance) p "é uma instância" parent_instance.definition.entities.each do |entity| if entity.is_a?(Sketchup::ComponentInstance) if entity.definition.name == subentity_name return entity end subentity = find_subentity_by_name(entity, subentity_name) return subentity if subentity # Retorna se encontrado. end end end return nil end def copy_component_into(component_instance, target_instance, transformation_array) component_definition = component_instance.definition target_entities = target_instance.definition.entities transformation = Geom::Transformation.new(transformation_array) new_instance = target_entities.add_instance(component_definition, transformation) puts "Component copied successfully into target component." return new_instance end def mm_p(medida) return medida / 25.4 end def findInstanceByName(selecao, nome) selecao.each do |entity| #p entity.definition.name if (entity.definition.name == nome) return entity end end end p sel.to_a destino = findInstanceByName(sel, "p_r_horizontal") p "destino " + destino.definition.name origem = findInstanceByName(sel, "quadradao_v2") p "origem " + origem.definition.name p_r = find_subentity_by_name(destino, "p_r") mdf_r = find_subentity_by_name(p_r, "mdf_r") component_instance = origem target_instance = mdf_r if component_instance.is_a?(Sketchup::ComponentInstance) && target_instance.is_a?(Sketchup::ComponentInstance) transformation_array = [ 1, 0, 0, 50, # Primeira linha (sem rotação, translação em X) 0, 1, 0, -50, # Segunda linha (sem rotação, translação em Y) 0, 0, 1, 0, # Terceira linha (sem rotação, sem translação em Z) 0, 0, 0, 1 # Linha de identidade (para compatibilidade) ] #This transformation its not working newInstance = copy_component_into(component_instance, target_instance, transformation_array) sleep(2) ents = Sketchup.active_model.entities tr = Geom::Transformation.translation [50, -40, 15.mm] ents.transform_entities tr, newInstance newInstance.transform! () else puts "Ensure both selected entities are component instances." end
](image url)