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

    kimpastro

    @kimpastro

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

    kimpastro Unfollow Follow
    registered-users

    Latest posts made by kimpastro

    • RE: [REQ SU api] Set component axis

      @tig said:

      Although it's convoluted you can do it already... You use:
      definition.entities.transform_entities(Geom::Transformation.translation(ORIGIN.vector_to(some_other_point_in_the_context)), definition.entities.to_a)
      to move the origin/insertion-point of the definition.
      If there are any existing 'instances' you'll also need to apply an inverse transformation to them ?
      If the axes are rotated you can also do a ...Geom::Transformation.rotation(anchor_point, axis_vector, angle)...
      and again you might need to fix any existing 'instances'...

      Sorry bring back this post but, with this is possible to do the second move (at right)?

      6.png

      posted in Developers' Forum
      kimpastroK
      kimpastro
    • Apply changes when click on the element

      Hello guys, need some help again.

      Scenario:

      Have two entities selected, and when I click in my plugin need to calculate the sum of both selected LenX and apply this value on the next entity that i'll click. Like image below:

      http://imageshack.com/a/img538/3996/y8E0rI.jpg

      My code until now:

      
      model = Sketchup.active_model
      selections = model.selection
      
      lenx_total = 0.to_i
      leny_total = 0.to_i
      lenz_total = 0.to_i
      
      if selections.empty?
        UI.messagebox('Select at least one component.')
      else
          selections.each do |sel| 
            lenx_total = lenx_total + sel.definition.get_attribute('dynamic_attributes', '_lenx_nominal')
        end
      end
       
      # All this is for test only, where i'm stuck and trying to discover something
      model.find_entity_by_id(18618).definition.set_attribute 'dynamic_attributes', '_lenx_nominal', lenx_total
      new_def = model.find_entity_by_id(18618).definition
      model.place_component new_def
      
      

      Thanks for your time.

      posted in Developers' Forum
      kimpastroK
      kimpastro
    • RE: Importing don't have to bring inherit of lenz

      well.. that's embarrassing...

      actually the "problem" is that i had overloaded "onElementAdded" method.. and put:

      
      @service.recent_inherit! entity
      
      

      now i send a new attribute, then it becomes:

      
      if entity.definition.get_attribute 'dynamic_attributes', 'imported_entity'
        @service.recent_inherit! entity
      end
      
      

      sorry about that and thanks for your time.

      cheers.

      posted in Developers' Forum
      kimpastroK
      kimpastro
    • Importing don't have to bring inherit of lenz

      Hi again everyone.

      I thought that had finished my import tool... but.. found a "bug". I have a situation, as follows:

      *Note: Not sure about the name of the things yet.. When I say entity I mean a rack, shelf, desk, table or anything that is a full mounted object.

      When create an entity with LenZ 700mm, put another entity on your side with LenZ 400mm, then export all, everything is save with correct attributes. But, when I import, the second entity assume LenZ = 700mm. The both assume the same height.

      But if I change the order of put entities (400mm first, then 700mm after), when Import, everything occurs as it meant to be, with the respective LenZ.

      Here's my import code:

      
        loaded_module = Sketchup.active_model.definitions.load_from_url uri
      
        moduli['attributes'].each do |key, value|
          my_load_texture_method
          loaded_module.set_attribute 'dynamic_attributes', key, method_to_inches_mm_etc(value)
        end
        
        my_method_to_set pos_x, pos_y, pos_z and rot_z
              
        t_rotation = Geom;;Transformation.rotation(ORIGIN, Z_AXIS, rot_z.degrees)
        point = Geom;;Point3d.new pos_x, pos_y, pos_z
        t_position = Geom;;Transformation.new point
      
        entities = Sketchup.active_model.active_entities     
        instance = entities.add_instance(loaded_module, t_rotation)
        instance.transform!(t_position)
      
        $dc_observers.get_latest_class.redraw_with_undo instance
      
      

      What I could observe is that, SU execute a rotation in ORIGIN, then apply texture and high(at this point he puts the wrong LenZ attribute), then move to his position.

      posted in Developers' Forum
      kimpastroK
      kimpastro
    • RE: Move a Transformation.rotation object to x, y and z position

      @dan rathbun said:

      @kimpastro said:

      PS: don't know if i'm using the correct terms for elements like: model, entity, modules, etc. Sorry about that.

      Yes you are misusing the term module.

      In your examples, "loaded_module" is a "loaded_component_definition".

      module is a ruby keyword, and a block of code that forms a namespace.

      Thanks, I'll be careful next time. πŸ˜„

      I'm confusing about module because we use the same term to determine the "master entity" of our projects to our clients.

      posted in Developers' Forum
      kimpastroK
      kimpastro
    • RE: Move a Transformation.rotation object to x, y and z position

      Alright, understood.
      Thanks a lot TIG and Dan for all information. you guys are awesome!!!

      posted in Developers' Forum
      kimpastroK
      kimpastro
    • RE: Move a Transformation.rotation object to x, y and z position

      @TIG, thanks a lot man.. that clarify a lot of things now. 😎

      but, still having some issues.
      All that code is inside of an 'each' block.. so actually he'll place N entities on the module and

      Well.. while I was writing that above, I've tried another thing, and this works:

      
      instance = entities.add_instance(loaded_module, t_rotation)
      instance.transform!(t_position)
      
      

      but this don't:

      
      instance = entities.add_instance(loaded_module, t_position)
      instance.transform!(t_rotation)
      
      

      The both generate modules and put they in the model, but the second option rotate the entity like... earth and sun, not in your own axis.

      and i need $dc_observers because i'm using texture in these guys, and before setting dynamic_attributes i'm loading textures and setting up to them, and need to redraw to apply (at least, that's a solution I've founded).

      PS: don't know if i'm using the correct terms for elements like: model, entity, modules, etc. Sorry about that.

      posted in Developers' Forum
      kimpastroK
      kimpastro
    • Move a Transformation.rotation object to x, y and z position

      Hi everyone,

      just need to move a Transformation.rotation, to another X, Y point.

      My Code:

      
      vector = Geom;;Vector3d.new 0,0,1
      
      #rot_z came from jSON, here he's an Integer 45
      t_rotation = Geom;;Transformation.rotation ORIGIN, vector, rot_z * Math;;PI / 180
      
      

      Alright, have this code, but now I need to move this guy above to a new position:

      
      #pos_x, y and z came from an imported jSON.
      point = Geom;;Point3d.new pos_x, pos_y, pos_z
      t_position = Geom;;Transformation.new point
      
      

      I've tried:

      
      t_rotation = t_rotation.set! t_position
      
      

      And after all that, I put entities into model, like that:

      
      entities = Sketchup.active_model.active_entities
      instance = entities.add_instance loaded_module, t_position
      $dc_observers.get_latest_class.redraw_with_undo instance
      Sketchup.active_model.materials.purge_unused
      
      

      *loaded_module is:

      
      loaded_module = Sketchup.active_model.definitions.load_from_url uri
      loaded_module.set_attribute 'dynamic_attributes', 'front', 'black_color'
      etc...
      
      

      And tried a lot of other combination with Transformation...

      This structure of classes and instances in Sketchup is just so confuse to me. Don't know who is parent of who, the Ruby API is very poor and misterious... I work with web app dev, not sketchup.. and this thing is hurting my brain. 😍 lol.

      Well... that's it. Thank you all.

      posted in Developers' Forum
      kimpastroK
      kimpastro
    • RE: Get X,Y,Z of active_model with Ruby

      @tig said:

      Your cod-example is very very unclear. πŸ˜•
      What " XYZ" of the 'model' are you seeking ?
      Please explain yourself better...

      I'll throw in some ideas that might help, meanwhile...

      bounds = Sketchup.active_model.bounds
      > center = bounds.center ### the center point of the model's bounding box, which includes XYZ coordinates.
      > min = bounds.min ### the minimum point of the model's bounding box, which includes XYZ coordinates.
      > max = bounds.max ### the maximum point of the model's bounding box, which includes XYZ coordinates.
      > xdim = bounds.width ### the width [X/red] dimension of the model's bounding box, in inches.
      > ydim = bounds.height ### the height [Y/green] dimension of the model's bounding box, in inches.
      > zdim = bounds.depth ### the depth [Z/blue] dimension of the model's bounding box, in inches.
      > ### to get the three x,y,z values in inches [aka Float] of a point3d reference use...
      > x,y,z = point.to_a
      > ### to get a single coordinate value in current model-units [aka Length] of a point3d reference use...
      > x = point.x
      > ### etc... there are lots of permutations...
      > 
      

      TIG, first of all thanks for reply.

      I misunderstood the whole thing.
      The "model" I've mentioned actually is the entity that contain all children entities.

      What I do was something like that:

      
      if not is_children?
      position; {
        x; entity.transformation.origin.x,
        y; entity.transformation.origin.y,
        z; entity.transformation.origin.x
      }
      end
      
      

      Thanks again, the bound method that you've explained, resolved a few other things.

      posted in Developers' Forum
      kimpastroK
      kimpastro
    • Get X,Y,Z of active_model with Ruby

      Hi, I swear I do a lot of research about this issue but can't find anything or can't understanding anything about what I've found.

      Just need to get the value of x,y and z of a active_model, because i'm gonna to export the project in json format and need when import to continue with they respective position.

      Ex:
      my_model['x'] = Sketchup.active_model.getX
      my_model['y'] = Sketchup.active_model.getY
      my_model['z'] = Sketchup.active_model.getZ

      the getX getY and getZ is what i need.

      If someone could help me or just link a topic about this explanation, will help me a lot.

      thanks so much guys.

      posted in Developers' Forum
      kimpastroK
      kimpastro