Taking a model to particular coordinates
-
and also i need to save the first line in variable machine
-
this is how i did it.....
model = Sketchup.active_model a = [] counter = 0 file = File.new("trial.txt", "r") while (line = file.gets) a[counter] = line if counter % 4 == 0.0 # lines 0 , 4, 8 etc machine = "#{a[counter].strip}.3ds" elsif counter % 4 == 1.0 # lines 1 , 5, 9 etc x = a[counter].to_f elsif counter % 4 == 2.0 # lines 2 , 6, 10 etc y = a[counter].to_f elsif counter % 4 == 3.0 # lines 3 , 7, 11 etc rot = a[counter].to_i ### processing end counter = counter + 1 end -
@borg.stef said:
and also i need to save the first line in variable machine
so... modify TIG's example, thus:
SUMMARY = true model = Sketchup.active_model dir = Dir.getwd # save current working dir path = File.expand_path("absolute path to 3ds import dir") lines = IO.readlines(filepath) i=0 ### always the first element in array 'lines' (lines.length/4).times{ machine = lines[i].strip + '.3ds' ### the '.strip' ### removes '\n'; does it need +'.3ds' ??? x=lines[i+1].strip.to_f y=lines[i+2].strip.to_f r=lines[i+3].strip.to_f ### success = model.import( File.join(path,machine), SUMMARY ) if success ### place it at 'x' & 'y' with rotation 'r' etc... else puts("Error at line #{i}, importing file; #{machine}\n") end ### i=i+4 ### do next 4 lines etc etc... } Dir.chdir = dir # reset working dir -
Thanks Dan.
As explained my example is just an example - you need to tailor it to you needs so 'f' >>> 'machine' with the .3ds added etc...
In you example it much more difficult to read than mine.
Your 'processing' is inside the if...end test when rotation is set, BUT my way will work with less likelihood of massing up - you simply gather the 4 lines of data as I show and use the references you set from them to do your processing for each 'machine'...
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better đź’—
Register LoginAdvertisement