Hi guys,
Me, with help from a friend, wrote this code. it’s a simple one. just to copy an entity in specific coordination (X, Y, Z). it was working well. now I’m trying to use it. but unfortunately, it gives no result. its working without giving any error. but there is no output. any help would be appreciated fixing it. thank you in advance. this is the code. ( list.txt containes the coordinations in this formate
[495987.623129000010000,4218018.181710000100000,0.4100620]
[495987.624541000000000,4218018.111150000200000,0.4195090]
)
class Array
def multiply_by(x)
collect { |n| n * x }
end
end
def self.copy_entities(tr, entarray)
Copies and transforms an array of entities
mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
tempgroup = ent.add_group entarray
temptrans = tempgroup.transformation
tempdef = tempgroup.definition
newgroup = ent.add_instance tempdef, temptrans
ent.transform_entities(tr, newgroup)
newgroup.explode
tempgroup.explode
end #def
#test using selection entities
myfile = File.open(“C:\Program Files\SketchUp\SketchUp 2018\Tools\list.txt”)
myfile.each {|line|
if line =~ /[(.),(.),(.*)]/
mod = Sketchup.active_model # Open model
ent = mod.entities[-1] # All entities in model
sel = mod.selection
sel.add(ent)
tr1 =Geom::Transformation.new([$1.to_f,$2.to_f,$3.to_f].multiply_by(39.37007874))
result1 = self.copy_entities(tr1, sel)
end
}