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

      How can the model alwayx go to z = 0?

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

        First off... do the code as before, but leave x=0 and y=0.
        What is the z ?
        If that's known then add the -z in Vector3d.new(x, y, -z)
        It should fix it.
        BUT IF it's not easily known then perhaps use z=obj.bounds.min.z
        and then re-transform! the obj using a new vector of (0,0,-z)...........

        TIG

        1 Reply Last reply Reply Quote 0
        • Rich O BrienR Offline
          Rich O Brien Moderator
          last edited by

          @unknownuser said:

          If I'm asked the right questions I might give the right answers

          Audible sigh.....

          Download the free D'oh Book for SketchUp πŸ“–

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

            @unknownuser said:

            @unknownuser said:

            If I'm asked the right questions I might give the right answers

            Audible sigh.....
            BUT we will sort this out [eventually... πŸ˜’ ]

            TIG

            1 Reply Last reply Reply Quote 0
            • GaieusG Offline
              Gaieus
              last edited by

              @tig said:

              @gaieus said:

              And you have all the powers to move any topic belonging there, TIG!
              πŸ˜„
              I know but hopefully, this is now 'dead' so moving it now seems a waste of time... πŸ˜’

              Ah yes, so the topic has grown to 3 pages ever since.
              πŸ˜‰
              Anyway, looking forward to the "doh" moment (not as if I understood any of the discussion here - maybe except for Rich's gibbering)
              πŸ˜’

              Gai...

              1 Reply Last reply Reply Quote 0
              • Rich O BrienR Offline
                Rich O Brien Moderator
                last edited by

                Aaah, look who's cheered up. Did you find your little unwelcome friend?

                Download the free D'oh Book for SketchUp πŸ“–

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

                  @gaieus said:

                  @tig said:

                  @gaieus said:

                  And you have all the powers to move any topic belonging there, TIG!
                  πŸ˜„
                  I know but hopefully, this is now 'dead' so moving it now seems a waste of time... πŸ˜’

                  Ah yes, so the topic has grown to 3 pages ever since.
                  πŸ˜‰
                  Anyway, looking forward to the "doh" moment (not as if I understood any of the discussion here - maybe except for Rich's gibbering)
                  πŸ˜’

                  The announcement of the demise of the topic was a little premature [to paraphrase Mark Twain [again]]...
                  There's also the PMing that you don't see πŸ˜’

                  TIG

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

                    This programm is actually making me crazy. What I am doing is that Matlab gives me a list example like this in a text file.
                    milling
                    500 (x axis)
                    400 (y axis)
                    0 (rot)
                    drilling
                    600
                    .....etc
                    and then I use this text file in the program above. However it gives me an error: Failed import. strangely enough when I remove the first name and its coordinates and rotation and moves the second one in its place, it works. Do you think this is a problem about the matlab code or sketchup?

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

                      You give us no real example but expect us to help you...
                      Can you attach a typical file so we can understand what you are trying to extract from the file...
                      IF the format is as your post suggests...

                      milling
                      500 (x axis)
                      400 (y axis)
                      0 (rot)
                      drilling
                      600 THEN your code needs to find 'milling' and then after that the next two lines are X, Y & the third line 'rot' give your values '.to_f'; when you meet another 'milling' you stop and start again. If you meet another 'drilling' you stop and take a value '.to_f' from the drilling [whatever that is?] etc...
                      IF you give us an example of the file you are wanting to read in, and what you hope to get out of it to put into your SKP THEN we might be better placed to help you - rather than this current 'bits & bobs' approach which isn't getting anyone anywhere... πŸ˜’

                      TIG

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

                        ok sorry so let me explain better. So I did a text file containing the following:
                        milling
                        500
                        400
                        0
                        drilling
                        650
                        100
                        90
                        etc....
                        then the sketchup plugin opens this text file and read line by line. the first line is the name of a .3ds file and it is imported. 500 and 400 are the x and y coordinates where the model will be taken and 0 is the rotation of the model. then it starts again..imports the file drilling.3ds and takes it at 650, 100 and rotates it by 90 degrees.
                        Till then it's ok.
                        Now what i had to do is generate the text file using Mathlab and I managed to do that. However when I load this file (generated by matlab) in sketchup it tells me import failed. Then, if I delete the name of the first model, it's x and y coordinates and the rotation ie as below

                        drilling
                        650
                        100
                        90
                        etc

                        It imports al the models correctly.. I don't know if the error is from matlab's side or sketchup's. I hope i explained myself wel now...

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

                          So...
                          You have data in a file that always has 4 lines for each 'thing'.
                          The first line is the file-name.
                          The second line is the X.
                          The third line is the Y.
                          The fourth line is the Rotation.
                          So you need to read the file in steps of four...

                          lines=IO.readlines(filepath)
                          i=0 ### always the first element in array 'lines'
                          (lines.length/4).times{
                            f=lines[i].strip
                            ###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
                            ### now do what you want with file 'f',
                            ### placing it at 'x' & 'y' with rotation 'r' etc...
                          
                            ###
                            i=i+4 ### do next 4 lines etc etc...
                          }
                          

                          I suspect that you might not be doing the import successfully ???

                          TIG

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

                            and where do i write the name of hte file?

                            1 Reply Last reply Reply Quote 0
                            • 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 Offline
                                    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
                                    • 2 / 3
                                    • First post
                                      Last post
                                    Buy SketchPlus
                                    Buy SUbD
                                    Buy WrapR
                                    Buy eBook
                                    Buy Modelur
                                    Buy Vertex Tools
                                    Buy SketchCuisine
                                    Buy FormFonts

                                    Advertisement