sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Taking a model to particular coordinates

    Scheduled Pinned Locked Moved Developers' Forum
    44 Posts 5 Posters 1.6k Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B Offline
      borg.stef
      last edited by

      and also i need to save the first line in variable machine

      1 Reply Last reply Reply Quote 0
      • B Offline
        borg.stef
        last edited by

        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
        	
        
        
        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          @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
          
          

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • TIGT Online
            TIG Moderator
            last edited by

            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'...

            TIG

            1 Reply Last reply Reply Quote 0
            • 1
            • 2
            • 3
            • 3 / 3
            • First post
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement