sketchucation logo sketchucation
    • Login
    1. Home
    2. bobdiya
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    B
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 4
    • Posts 9
    • Groups 1

    bobdiya

    @bobdiya

    10
    Reputation
    1
    Profile views
    9
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    bobdiya Unfollow Follow
    registered-users

    Latest posts made by bobdiya

    • RE: Group moves to origin when I doubleclick to select component

      Dan, Thank you for your reply.

      group.png

      Origin of the group g.transformation.origin is (150, 10, 3). One of the corners' (say P) coordinate of RectangleBox is (19, 0, 0). (RectangleBox is ComponentInstance and belongs to the group.

      Seeing the value (19,0,0) and the position of the point P, it is clear the coordinate is with respect to the Group's coordinate system. So I need to add the group's origin to get the coordinates of P in Sketchup coordinate system. That would be - (169, 10, 3).

      Question: This looks like the hard way. Is there any direct way?

      Let me give you the actual picture.
      Problem I am trying to solve: Find all the faces that are touching (in contact with) other faces in the selection.

      The approach

      1. I get all the plys (RectangleBoxes i.e., ComponentInstances) in the selection (Recursive solution).
      2. Then I get all the faces of the plys
      3. I go on to compare each face against every other face to see if they are in contact. If they are then I add it to the resulting array.

      **Another query:**In get_extremes_of_face method face.vertices returns vertices with respect to the Group's origin. And this is where i will need to offset the origin of the group to get the 'absolute coordinates'. But is there a better way to do this?

            def get_all_faces(ply)
              entities = ply.definition.entities
              all_faces = []
              for entity in entities
                if entity.instance_of?(Sketchup;;Face)
                  all_faces << entity
                end
              end
              return all_faces
            end
            
            def is_face_coplanar_to_another?(face1, face2)
              face1_extremes = get_extremes_of_face(face1)
              face2_extremes = get_extremes_of_face(face2)
              if(face1.area > face2.area)
                val = check_if_one_extremes_contain_another(face1_extremes, face2_extremes)
              else
                val = check_if_one_extremes_contain_another(face2_extremes, face1_extremes)
              end
      
              return val
            end
      
            def get_extremes_of_face(face)
              vertices = face.vertices
              i = 0
              array = []
              x_value1 = []
              y_value1 = []
              z_value1 = []
              for ii in (0..3)
                 array[i] = vertices[ii].position
                 x_value1[i] = array[i][0]
                 y_value1[i] = array[i][1]
                 z_value1[i] = array[i][2]
                 i += 1
              end
              x_min = x_value1.min
              x_max = x_value1.max
              y_min = y_value1.min 
              y_max = y_value1.max 
              z_min = z_value1.min 
              z_max = z_value1.max
              value = {;x_min => x_min,;x_max => x_max,;y_min => y_min,;y_max => y_max,;z_min => z_min,;z_max => z_max}
              return value
            end
      
            def check_if_one_extremes_contain_another(ex1, ex2)
              if (ex1[;x_min] <= ex2[;x_min] && ex1[;y_min] <= ex2[;y_min] && ex1[;z_min] <= ex2[;z_min])
                if(ex2[;x_max] <= ex1[;x_max] && ex2[;y_max] <= ex1[;y_max] && ex2[;z_max] <= ex1[;z_max])
                  return true
                else
                  return false
                end
              end
              return false
            end
      
      
      posted in Developers' Forum
      B
      bobdiya
    • Group moves to origin when I doubleclick to select component

      Here are two groups, each group containing 2 rectangle boxes

      Groups.png

      When I double click on one of the rectangle box, the group moves to the origin. In the above image the origin is out of sight but in below image the groups are moved to the origin.
      BoundingBox.png

      Why does this happen?

      I then printed the bounding box of each of the rectangle boxes in both the groups. I am surprised to see that RectangleBox 1 and RectangleBox 3 have same values. Similarly 2,4. As if to indicate they are same objects. (See the bounds listed below)

      COMPARE 1 and 3, 2 and 4 . They are same

      1 - Rectangle box
      Point3d(0, 21.455, 0) - Point3d(19.8533, 21.455, 0) - Point3d(0, 22.1636, 0)
      Point3d(19.8533, 22.1636, 0) - Point3d(0, 21.455, 4.72441) - Point3d(19.8533, 21.455, 4.72441)
      Point3d(0, 22.1636, 4.72441) - Point3d(19.8533, 22.1636, 4.72441)

      2 - Rectangle box
      Point3d(19.1446, 0, 0) - Point3d(19.8533, 0, 0) - Point3d(19.1446, 21.455, 0)
      Point3d(19.8533, 21.455, 0)- Point3d(19.1446, 0, 4.72441) - Point3d(19.8533, 0, 4.72441)
      Point3d(19.1446, 21.455, 4.72441) - Point3d(19.8533, 21.455, 4.72441)

      3 - Rectangle Box
      Point3d(0, 21.455, 0) - Point3d(19.8533, 21.455, 0)- Point3d(0, 22.1636, 0)
      Point3d(19.8533, 22.1636, 0)- Point3d(0, 21.455, 4.72441) - Point3d(19.8533, 21.455, 4.72441)
      Point3d(0, 22.1636, 4.72441) - Point3d(19.8533, 22.1636, 4.72441)

      4 - Rectangle box
      Point3d(19.1446, 0, 0) - Point3d(19.8533, 0, 0) - Point3d(19.1446, 21.455, 0)
      Point3d(19.8533, 21.455, 0) - Point3d(19.1446, 0, 4.72441) - Point3d(19.8533, 0, 4.72441)
      Point3d(19.1446, 21.455, 4.72441) - Point3d(19.8533, 21.455, 4.72441)

      What I'd like to do?
      I'd like to get the (unique) coordinates of each of the rectangle boxes in 3D space.

      Attached the sketchup file.


      simple1.skp

      posted in Developers' Forum
      B
      bobdiya
    • Is the ruby source for rectangle tool or similar available?

      I've been reading up the ruby source of tools - Construction line, Sphere tool by Jim Foltz and rotate scale tool by thomthom. They have been very helpful in writing my tool.

      Also, I have been wondering if there exists a version of ruby source for rectangle tool. The source to this tool will help me figure a lot of things I want to achieve. I searched for it but in vain. Even an older version or something similar would be helpful.

      posted in Developers' Forum
      B
      bobdiya
    • RE: How do I represent and keep a track of cuboids I create?

      @dan rathbun said:

      On Pro edition you can use the boolean intersect() method, which should work even when the cuboid is rotated away from the global axis.

      I dint know this. Thank you.

      @dan rathbun said:

      You do not need to create them and keep references to them. Think of it as that they always have bounds if they have dimension. Then access their bounding box instances only when comparing:

      cube1.bounds.intersect(cube2.bounds).valid?

      The drawback is that bounding boxes are always aligned with the global axis, even if the object has been rotated. So the bounding box may be larger than the cuboid if it was rotated less than 90 degrees off the global axis.

      I get that I can use cube1.bounds.intersect(cube2.bounds).valid? when my (cubes)objects have dimensions. But given that the user is likely to rotate the cube (<90 degree off the global axis) then I will have to create and keep references to the bounding boxes? Because now the default bounding boxes are larger and they don't represent the bounds of the cube themselves. Correct?

      posted in Developers' Forum
      B
      bobdiya
    • RE: How do I represent and keep a track of cuboids I create?

      Dan,

      Thanks for the code example. Representing and maintaining cuboids taken care of. I see why my code is slow. My approach scanned through all the entities, but you directly get the list of definitions and then you get the definition you are interested in. From there, its instances. Perfect!

      One problem that I'm facing still how to figure out if two cuboids are intersecting.

      • Is there a way(method) I can use to check if two components are intersecting?

      I used the intersect method to see if it returned an empty BoundingBox, when I was comparing the BoundingBoxes of two cuboid instances that I wanted to check for intersection. But those BoundingBoxes were not the cuboid themselves, but I guess bounding boxes which are enclosure sort of thing to the component. So should I create these BoundingBox objects manually for each of cuboids so that I can use this method?
      How do I approach this?

      posted in Developers' Forum
      B
      bobdiya
    • RE: How do I represent and keep a track of cuboids I create?

      Dan, Thanks for the pointer. The plugin did help me understand the Sketchup environment more and solve my problem.

      I wanted to keep a track of all the components that my tool was creating. Now I was not aware that the model.entities was already keeping track of them. So I traversed through the entities, checked if its a ComponentInstance, if it is, then check if its a component that my tool created, to get hold of it.

      posted in Developers' Forum
      B
      bobdiya
    • How do I represent and keep a track of cuboids I create?

      I have a written a simple tool that creates cuboids. All I do internally to create the cuboid is

      model=Sketchup.active_model()
      ents = model.entities()
      group = ents.add_group()
      corners = get_corners() # Assume I've written a method that will return 4 corners of the face
      face = group.entities().add_face(corners[0], corners[1], corners[2], corners[3])
      face.pushpull(pushpull_distance.mm)
      model.selection.add(@group)
      compInstance = @group.to_component
      
      

      What I would like do?
      I'd like to prevent the tool from creating any overlapping (or intersecting) cuboids. (see the attached image)

      My approach

      1. Represent the cuboid in the tool as a object
      2. Have an instance variable bb, which I'd set it with the boundbox of the cuboid
      3. Maintain a list of cuboid objects. Add this newly cuboid object to the list only if its bounding box doesn't contains? any of bbs in the list
      4. Now go ahead and actually draw

      Questions

      1. Is my approach ok? Any easier way to achieve it.
      2. How to represent the cuboid? The piece of code face.pushpull(pushpull_distance.mm) creates the cuboid from the face, but it doesn't return any object that I could use

      interesting.png

      posted in Developers' Forum
      B
      bobdiya
    • RE: Can I override the basic functionality of pushpull?

      Apologies for the delayed response.

      Here is how a user would use the Plytool (the tool that creates a box/ply)

      1. Click on the tool icon. Now click (to mark the first point) and start drawing the ply
        1.png
      2. Stop at another point (which is the second point). Leg go the left click and you have your ply
        2.png

      Coming to the questions

      @tig said:

      From what you've said you don't actually want to stop the user having the PlushPull tool available to them ?

      Correct. I don't want to stop the user from using Push/pull but just restrict the user from pushing or pulling on certain kind of faces [e.g - vertical faces only].

      @tig said:

      Limiting the user's choice within your tool of available faces for this pushpulling is a matter of testing a face for its suitability - this can be whatever you want - orientation of face.normal [e.g. only 'up' faces], or faces using a particular material or layer ?
      That way your own pushpull tool will simply work in limited ways...

      Yes, this seems like the suitable option to try. I will try this and get back if any questions. Ideally I would have preferred the ability to override pushpull tool (thereby not introducing a new limited version of pushpull tool). But this should do for now.

      Thanks guys for helping me out and clarifying what is possible and what not.

      posted in Developers' Forum
      B
      bobdiya
    • Can I override the basic functionality of pushpull?

      I'm new to plugin dev and I've created a tool - plytool - seeing some examples.

      This tool allows you to use it like a rectangle tool, but instead of creating a face it will create a cuboid (a ply). If you had to do it using the basic tools you would (1) create a face (2) pushpull it to certain thickness. So now, you could simply do it in one step using the plytool.

      What I'd like to do?
      I'd like to restrict the user on using the pushpull tool only on some faces of the cuboid created using the tool.

      Question
      Can I override the functionality of pushpull to do that? If yes, can you point me to some help examples. If no, it would help if you could suggest me an alternative.

      Thanks

      posted in Developers' Forum
      B
      bobdiya