Taking a model to particular coordinates
-
Thanks for that.
Dear TIG, I tried your code and it's giving me this error
Error: #<NoMethodError: undefined methodinstances' for #<Array:0x7b62f2c>> C:/Program Files/Google/Google SketchUp 8/Plugins/examples/new2.rb:10 (eval):33:in
load'
(eval):33 -
@borg.stef said:
Thanks for that.
Dear TIG, I tried your code and it's giving me this error
Error: #<NoMethodError: undefined methodinstances' for #<Array:0x7b62f2c>> C:/Program Files/Google/Google SketchUp 8/Plugins/examples/new2.rb:10 (eval):33:in
load'
(eval):33My fault! Here's the corrected code!
model = Sketchup.active_model ### set x and y as needed... x=123.4 y=567.8 defs=model.definitions.to_a machine = "trial.3ds" model.import(machine, true) defa=model.definitions.to_a - defs ### what you just added defn=defa[0] ####### FIX ####### obj = defn.instances[0] ### the placed version ###pt = model.bounds.center.vector_to([x,y,0]) ### errr ??? ### do you really want to do this as this 'center' is not 'constant' ### would it be better as a 'movement' from the ### original object's origin/SKP's ORIGIN [0,0,0]... pt=Geom;;Vector3d.new(x, y, 0) tr = Geom;;Transformation.translation(pt) obj.transform!(tr)
-
still not taking the model at those coordinates after importion
-
It adds the imported object at the origin in the SKP [yes?] - this should be equivalent to the origin in the 3ds file.
The Vector3d moves the object by the given x and y values.
What values are you using for them ?
Try perhaps x=0 and y=100.m - that way if the object moves by 100m you'll know it works!
Are there any errors in the Ruby Console when you run this ?? -
no errors. its just imported in random coordinates and with the move icon pressed....
-
I don't understand you exactly.
If you make x=0 and y=0 it should then simply leave the object where it imported ??
What 'Move icon' ?
As I don't see your whole code can you check that my example code meshes with it as needed.
IF you make x=0 and y=100.m doe sit move the imported object 100m in the green axis ?? -
I copy and pasted the code that you gave me and I tried x = 0 y = 0 and even x= 0 y = 100.m but it's doing the same in both cases. Importing the model in a random location. I'm so confused.
-
So am I.
Can you attach your 3ds file to a post or a Private Message [PM] and I'll look at it... -
it shows this message: The extension 3ds is not allowed.
-
it shows this message : The extension 3ds is not allowed.
-
Don't worry about the example 3ds [but you could 'zip' that type of file]... I've found the problem. 3ds files import but expect you to pick an insertion point - some file type imports don't... I'm thinking how to circumvent this...
-
Thanks for your time...you know I'm new to ruby I don't know these details...just built programs from what i found on the net..thanks!
-
i can't seem to make this thing work
-
No problem... "God loves a trier..."
Here's a version that does work !
I've never had to do this myself and I have written hundreds of scripts - so we all have things to learn
It now imports the 3ds file and places one instance at random, then adds one at the origin [0,0,0].
It deletes the original one instances[0] and leaves the next one and then moves it by x/y values you have set at the start...model = Sketchup.active_model x=0 ### set x and y as needed... y=10.m defs=model.definitions.to_a machine = "C;\\Temp\\trial.3ds" model.import(machine,true) defa=model.definitions.to_a - defs ### what you just added defn=defa[0] defn.instances[0].erase! tr=Geom;;Transformation.new(ORIGIN) obj=model.active_entities.add_instance(defn, tr) pt=Geom;;Vector3d.new(x, y, 0) tr=Geom;;Transformation.translation(pt) obj.transform!(tr)
We all learn!
-
wow this actually worked....only that z is high up not 0..
-
Is this a 3ds importer that doesn't need you to place the model after importing? Or what is it?
-
rich, it imports a model and instantly takes it to particular coordinates dictated by you!
-
The code as it stands adds a component-instance based on the 3ds file at the origin [0,0,0]... after all of the kerfuffle.
It then moves it by the defined x & y values, the z isn't changed at all.
IF the original object is not z=0, then it simply stays where it is in the 3ds file ???
There are ways to move all of the definitions geometry to z=0 BUT that's not the original request ?
Please check the 3ds's geometry and the SKP's for similarities if x=0 & y=0... -
@unknownuser said:
Is this a 3ds importer that doesn't need you to place the model after importing? Or what is it?
This 3ds importer [built-in] DOES require you to place it BUT my cludged work-around does work... just about
-
Can it place the 3ds file by lowest point of bounding box centre at 0,0,0? I'm not at pc to check this out?
Advertisement