sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Load & Put Components Together

    Scheduled Pinned Locked Moved Plugins
    5 Posts 2 Posters 429 Views 2 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.
    • C Offline
      Chris88
      last edited by

      Hey,
      I want to put 2 - 4 componentes together, without hardcoding the
      coordinates of the componentes.

      For example:
      so i show you what i've programmed:

      driller= Sketchup.active_model.definitions.load("\\driller.skp") pos_driller =Geom::Point3d.new 47,32,25<- that's the problem
      ` set_driller= Geom::Transformation.new pos_driller
      instance1 = entities.add_instance driller, set_driller

      cuboid_wood = Sketchup.active_model.definitions.load("\Cuboid_wood.skp")
      pos_cuboid = Geom::Point3d.new 0,0,0<- like here set_cuboid = Geom::Transformation.new pos_cuboid
      instance2 = entities.add_instance cuboid_wood, set_cuboid`

      but this is hardcoded
      and i want that the computer places the objects correctly together automatically,by calculating the best position, but i can't calculate the size of these objects, because i don't know how. (i would have to measure the size with the measure-tool in SU with the mouse, but it should retrieve the values with a method)

      Or is there another possibility to avoid the harcoded way?

      I have the task to do that with many components, that's why i wouldn't
      say the detailed coordinates for every components, which i load.

      the programm should be able to load componentes, put it together correctly and dynamically, take some photos in different perspectives, save these pictures, clear it all and start at the beginning with other components ... everthing is quite clear to me, with the exception of the hardcoded coordinates of these objects

      Thanks for your suggestions.

      Greets

      1 Reply Last reply Reply Quote 0
      • sdmitchS Offline
        sdmitch
        last edited by

        Chris88,

        The simplest way to determine the size of a component is to use the bounding box of the component. For example, if you wanted to assemble the components in the X direction, calculate the distance between the center points, calculate the new center point for instance2, define the transformation to move it there, then do the transform.

        bb1 = instance1.bounds
        ctr1 = bb1.center
        halfx1 = (bb1.max.x-bb1.min.x)/2.0
        bb2 = instance2.bounds
        ctr2 = bb2.center
        halfx2 = (bb2.max.x-bb2.min.x)/2.0
        ctr_to_ctr = halfx1 + halfx2
        new_ctr2 = ctr1.offset(X_AXIS,ctr_to_ctr)
        mov_cuboid = Geom;;Transformation.new(new_ctr2-ctr2)
        instance2.transform! mov_cuboid
        
        

        Nothing is worthless, it can always be used as a bad example.

        http://sdmitch.blogspot.com/

        1 Reply Last reply Reply Quote 0
        • C Offline
          Chris88
          last edited by

          Thank you very much, sdmitch!

          It sounds very good, i will test it at once.

          Do you know another way to assemble components dynamically?
          Because you said that this is the easiest way.

          1 Reply Last reply Reply Quote 0
          • C Offline
            Chris88
            last edited by

            It doesn't work correctly,

            my tool (driller, saw,...) is set right beside the wooden cuboid, although i put the cuboid on 0,0,0.

            Then i changed your code a little bit to:

            mov_cuboid = Geom;;Transformation.new(ctr1)
            

            so the tool is in the middle of cuboid, but i can't change the height of the tool or just x,y-coordinate

            1 Reply Last reply Reply Quote 0
            • sdmitchS Offline
              sdmitch
              last edited by

              Chris, The code works perfectly as far as it was designed to do and that was to place instance1 beside instance2. Only you know how you want and need the components to be related to each other and only you have the components to work with.

              Nothing is worthless, it can always be used as a bad example.

              http://sdmitch.blogspot.com/

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

              Advertisement