• Login
sketchucation logo sketchucation
  • Login
πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Taking a model to particular coordinates

Scheduled Pinned Locked Moved Developers' Forum
44 Posts 5 Posters 1.5k Views
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 18 Mar 2011, 15:48

    So I want to import a model and then take it to particular x and y coordinates in sketchup. I had to do this in 2 different programs since the model had to be selected before taken to the coordinates. The programs are shown below:

    machine = "trial.3ds"
    model = Sketchup.active_model
    show_summary = true
    status = model.import machine, show_summary


    obj = Sketchup.active_model.selection[0]
    pt = model.bounds.center.vector_to([x,y,0])
    tr = Geom::Transformation.translation(pt)
    model.transform!(tr)

    Is there a way to link these in 1 program?
    Thanks

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 18 Mar 2011, 16:06

      You'd be better posting queries about scripting in one of our specialized forums...
      Also use 'code' formating as it makes code easier to read...
      Anyway here's my ideas/help...

      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)
      defn=model.definitions.to_a - defs ### what you just added
      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) 
      

      Don't you want to transform the object not the model !?

      TIG

      1 Reply Last reply Reply Quote 0
      • G Offline
        Gaieus
        last edited by 18 Mar 2011, 16:07

        @tig said:

        You'd be better posting queries about scripting in one of our specialized forums...

        And you have all the powers to move any topic belonging there, TIG!
        πŸ˜„

        Gai...

        1 Reply Last reply Reply Quote 0
        • B Offline
          borg.stef
          last edited by 18 Mar 2011, 16:08

          yes yes that why my mistake in the last line. Thanks I will try this

          1 Reply Last reply Reply Quote 0
          • T Offline
            TIG Moderator
            last edited by 18 Mar 2011, 16:09

            @gaieus said:

            @tig said:

            You'd be better posting queries about scripting in one of our specialized forums...

            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... πŸ˜’

            TIG

            1 Reply Last reply Reply Quote 0
            • B Offline
              borg.stef
              last edited by 18 Mar 2011, 16:10

              Where are the specialized forums?? sorry I'm not very used to this site! THanks

              1 Reply Last reply Reply Quote 0
              • T Offline
                TIG Moderator
                last edited by 18 Mar 2011, 16:36

                @borg.stef said:

                Where are the specialized forums?? sorry I'm not very used to this site! Thanks

                Your post has been transferred by the ever vigilant Gaieus... We are now in the Developers' forum which discusses Ruby etc - there is also a Plugins forum for specific tools... There are many forums and sub-forums please browse them and familiarize yourself - post in the one most relevant to your problem...

                TIG

                1 Reply Last reply Reply Quote 0
                • B Offline
                  borg.stef
                  last edited by 18 Mar 2011, 16:41

                  Thanks for that.

                  Dear TIG, I tried your code and it's giving me this error
                  Error: #<NoMethodError: undefined method instances' for #<Array:0x7b62f2c>> C:/Program Files/Google/Google SketchUp 8/Plugins/examples/new2.rb:10 (eval):33:in load'
                  (eval):33

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    TIG Moderator
                    last edited by 18 Mar 2011, 16:54

                    @borg.stef said:

                    Thanks for that.

                    Dear TIG, I tried your code and it's giving me this error
                    Error: #<NoMethodError: undefined method instances' for #<Array:0x7b62f2c>> C:/Program Files/Google/Google SketchUp 8/Plugins/examples/new2.rb:10 (eval):33:in load'
                    (eval):33

                    My 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) 
                    

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • B Offline
                      borg.stef
                      last edited by 18 Mar 2011, 17:19

                      still not taking the model at those coordinates after importion πŸ˜•

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        TIG Moderator
                        last edited by 18 Mar 2011, 17:23

                        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 ??

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • B Offline
                          borg.stef
                          last edited by 18 Mar 2011, 17:29

                          no errors. its just imported in random coordinates and with the move icon pressed....

                          1 Reply Last reply Reply Quote 0
                          • T Offline
                            TIG Moderator
                            last edited by 18 Mar 2011, 17:44

                            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 ??

                            TIG

                            1 Reply Last reply Reply Quote 0
                            • B Offline
                              borg.stef
                              last edited by 18 Mar 2011, 17:50

                              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.

                              1 Reply Last reply Reply Quote 0
                              • T Offline
                                TIG Moderator
                                last edited by 18 Mar 2011, 18:11

                                So am I.
                                Can you attach your 3ds file to a post or a Private Message [PM] and I'll look at it...

                                TIG

                                1 Reply Last reply Reply Quote 0
                                • B Offline
                                  borg.stef
                                  last edited by 18 Mar 2011, 18:17

                                  it shows this message: The extension 3ds is not allowed. 😞

                                  1 Reply Last reply Reply Quote 0
                                  • B Offline
                                    borg.stef
                                    last edited by 18 Mar 2011, 18:18

                                    it shows this message : The extension 3ds is not allowed.

                                    😞

                                    1 Reply Last reply Reply Quote 0
                                    • T Offline
                                      TIG Moderator
                                      last edited by 18 Mar 2011, 18:19

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

                                      TIG

                                      1 Reply Last reply Reply Quote 0
                                      • B Offline
                                        borg.stef
                                        last edited by 18 Mar 2011, 18:21

                                        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!

                                        1 Reply Last reply Reply Quote 0
                                        • B Offline
                                          borg.stef
                                          last edited by 18 Mar 2011, 19:10

                                          i can't seem to make this thing work 😒

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

                                          Advertisement