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

    Posts

    Recent Best Controversial
    • RE: How to judge whether a 3D point is visible or not

      @sdmitch said:

      @lbsswu said:

      Hi everyone,

      Suppose I have opened the Sketchup software, I want to know whether a 3D point is visible or not in current view.
      For example, the 3D point may locate on the back of a person, thus we can't see it when the person facing to us.

      This should be done by Sketchup ruby code.Could anyone help me?

      I placed a construction point, the little black dot just below the horizon, and "Nancy" in the model. I then used the following code to test if the point was visible.

      mod = Sketchup.active_model
      > ent = mod.active_entities
      > sel = mod.selection
      > vue = mod.active_view
      > eye = vue.camera.eye
      > cp = ent.grep(Sketchup;;ConstructionPoint)[0]
      > pt = cp.position
      > vec = pt.vector_to(eye)
      > hit = mod.raytest([pt,vec])
      > if hit
      >  puts "pt is not visible"
      > else
      >  puts "pt is visible"
      > end
      > 
      

      Hi, sdmitch. Thank you very much. It works!

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • RE: How to get the projected coordinate of a 3D point?

      @tig said:

      view.screen_coords returns the point in the Model as X,Y coords - screen value.
      But you must ensure that the exported image used the same size as the window, otherwise there is no direct relationship between the point and the image's pixels...

      Got it! Thanks for your help!

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • RE: How to get the projected coordinate of a 3D point?

      @slbaumgartner said:

      view.screen_coords

      Got it! Thanks for you help!

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • How to judge whether a 3D point is visible or not

      Hi everyone,

      Suppose I have opened the Sketchup software, I want to know whether a 3D point is visible or not in current view.
      For example, the 3D point may locate on the back of a person, thus we can't see it when the person facing to us.

      This should be done by Sketchup ruby code.Could anyone help me?

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • How to get the projected coordinate of a 3D point?

      Hi everyone,

      I have a problem about how to get the projected coordinate of a 3D point.

      Suppose the 3D point locates at [10 20 30], then I save an image of the scene in current view.

      Then, how do I know the coordinate of the 3D point in the saved image?

      Does anyone have some ideas?

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • RE: How to get the bounding box of a CAD car?

      @tig said:

      You don't need to find those [even if you could] because the Zoom Extents on a single car does that in the view.
      Of course depending on your screen's current proportions and the exact view of the car you will get some 'white space' around the image.
      If you don't want all images to be the same size then that 'white space' is best removed with an Image editor [like Gimp] - where you can batch-open each file in turn and Auto-Crop it and save, to ensure that each car occupies as much of the image as possible...

      thanks for your tip! maybe I will do that in the future.

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • RE: How to get the bounding box of a CAD car?

      @dukejazz said:

      It is true you may not need bounding box corner coordinate of a car in each image to make 3D models to 2D images,
      ...

      thanks for your kindly reply, I will try these method.

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • RE: How to get the bounding box of a CAD car?

      @dan rathbun said:

      You would insert each car component onto a new layer, switch to that layer, and turn all other layers OFF, and zoom extents.

      Then use view.write_image to create the image files.

      Suppose there is one car in a image, how to get the coordinates of the car's bounding rectangle?

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • How to get the bounding box of a CAD car?

      I have some CAD cars and I need to project these 3D models to 2D images, is there a method to get the 2D bounding box coordinate of a car in each image? e.g., the 4 corner coordinates, (x1,y1), (x2,y2), (x3,y3), (x4,y4) of the green bounding box in the following attachment.

      smp.jpg

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • RE: Skb files

      @tig said:

      @rich o brien said:

      Try TIG's Purge All plugin. It does mean doing this for each file.
      Although with a little rewriting you could 'batch' purge all SKP files in a folder say, removing the dialog/option prompts... πŸ˜‰

      OK, thanks a lot!

      posted in Newbie Forum
      lbsswuL
      lbsswu
    • RE: Skb files

      @tig said:

      The SKB file is just a version of the SKP file that is one save behind it, so there is often little size difference, and the file is slightly out of date.
      Use the SKP file.
      Have you used Model Info > Statistics to Purge Unused on the SKP ?
      The saved SKP will then be as small as it can be, when unused components, materials, layers and styles are cleared out.
      Also note that if you have large images used for textured materials, you could also try editing those to something smaller in their resolution, and then reapply them to their materials - the SKP might not loose much in its appearance at all, but this can shrink its size noticeably.
      Zipping a SKP will make it smaller, but by how much depends on its constituents.
      File Sharing sites have varying limits on file size.
      Most email services limit an attachment size to 20/25Mb.
      This forum has a limit of 4Mb.
      Some services disallow unusual file extensions - like SKP - so a ZIP file is more likely to be acceptable AND smaller too...

      Hi, TIG! Is there some way to do "Model Info > Statistics to Purge Unused on the SKP" by ruby code? I have to many .skp files, it's wasting to much time to shrink them one by one. 😞

      posted in Newbie Forum
      lbsswuL
      lbsswu
    • RE: Correspondence of color names in Paint Bucket

      @tig said:

      I'm not sure that there is any correspondence between the external SKM file's RGB values and the built-in [OpenGL] colors.
      You can of course make new materials directly from from colors - like 'AliceBlue' - just by specifying a valid name as the material.
      You can also get any material's RGB color values in API code and from that you can compare it to the 'built-in' colors' RGB values.
      See the Material AND Color parts of the API docs...
      If you have a material already in the SKP why do you need to use a new 'color' based one at all ?

      Hi, TIG. Sorry for my late thanks.

      Actually, other people im my group use two styles of colors, e.g.the external SKM file's colors and the built-in [OpenGL] colors. I want to integrate them.

      posted in Newbie Forum
      lbsswuL
      lbsswu
    • Correspondence of color names in Paint Bucket

      Does anyone know the correspondence of color names in Paint Bucket and Color table?

      For example, I select a color "Color_A01" in Paint Bucket, is the color in the Color table https://developers.google.com/sketchup/docs/ourdoc/color?, like "AliceBlue".

      The "Color_A01" is select by someone else, I need to know the corresponding name in the table so that I can use it in my ruby code. Is there a corresponding list?

      posted in Newbie Forum sketchup
      lbsswuL
      lbsswu
    • RE: How to get the absolute coordinates of faces?

      @anton_s said:

      Here's what I've got.

      def self.currentPos(parent, child_pos) #Get the position of the point relative to parent's transformation
      >     return child_pos unless (parent.class == Sketchup;;Group) and (parent.class == Sketchup;;ComponentInstance)
      >     tra = parent.transformation.origin.to_a
      >     xaxis = parent.transformation.xaxis.to_a
      >     yaxis = parent.transformation.yaxis.to_a
      >     zaxis = parent.transformation.zaxis.to_a
      >     # my experimented formule
      >     external_pos[x] = tra[0] + child_pos[0]*xaxis[0] + child_pos[1]*yaxis[0] + child_pos[2]*zaxis[0]
      >     external_pos[y] = tra[1] + child_pos[0]*xaxis[1] + child_pos[1]*yaxis[1] + child_pos[2]*zaxis[1]
      >     external_pos[z] = tra[2] + child_pos[0]*xaxis[2] + child_pos[1]*yaxis[2] + child_pos[2]*zaxis[2]
      >     #external_pos = child_pos.transform(parent.transformation).to_a #alternative sketchup formula
      >     return external_pos
      > end
      

      Copy to editor to unwrap the code lines.
      It basically shows how that transform formula works
      By the way If you have sketchy physics, you can see play with something similiar here: Navigation System

      Thanks for your code. But I still did not get the coordinate that I want, the return coordinate is equal to the child's coordinate. The type of the child is Sketchup::Face, and the type of its parent is Sketchup::ComponentDefinition. I made a group like this:

      
      model = Sketchup.active_model;
      groups = [];
      model.definitions.each{|d| groups << d if d.group? }
      entities = model.entities;
      selection = model.selection;
      pgrp = [];
      groups.each{|d| pgrp << d.instances[0] if d.instances[0].name=="car_top" }
      tmpents = pgrp[0].entities;
      #print pgrp[0]
      faces = tmpents.find_all{|entity|entity.class==Sketchup;;Face}
      ctr = faces[8].bounds.center
      print ctr
      pos = self.currentPos(pgrp[0], ctr)
      print pos
      
      

      pgrp[0] is a group that contain faces[8]. May be there are some bugs...

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • RE: How to get entities from selection?

      @tig said:

      @lbsswu said:

      @tig said:

      Try my suggestion[s] - far easier to understand and get results if you read the alternatives carefully....
      I believe that Aerilius was thinking that your 'selection' was actually a 'group'.
      Then the 'group'.entities would have worked...

      Thanks TIG! I have tried your suggestions. It works, but maybe there is a bug in my script, I did not get the correct coordinates.
      Without at least a few clues we can't help you much further πŸ˜•
      If you are trying to find the center of a selection of objects then my examples will return the bounds.center
      You never explained properly what it is you are trying to do...
      We answer your query only to find it's not the answer to the question you ought to have asked really πŸ˜’
      Can you explain what you seek and we might help with a path to get there.
      Sometimes you seem to have gone half way down the wrong road and then ask us how to get to you destination by carrying on, when really you need to go back to the start and set off in the correct direction as it'll be much easier/quicker...

      My task is get the parts' center of a 3D car model. I find the problem which posted in the website:
      http://forums.sketchucation.com/viewtopic.php?f=180&t=46520&p=416248#p416248

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • RE: How to get the absolute coordinates of faces?

      @tig said:

      I assume you have somehow got the center of the face inside its 'context' - let's call it pt.
      You have a reference to the face's 'container' [a group or instance].
      You can get the transformation of that - e.g. tr=instance.transformation.
      You can apply a transformation to a point thus:
      pt.transform!(tr)

      You can also do the inverse - e.g. you have a point outside of the context and want to convert it as if it's inside the context...
      pt.transform!(tr.inverse)

      I'm unsure about which way round you want to do this, but somewhere in this is your answer...

      I split my 3D car model in several parts, e.g. door, wheel, etc. I want to locate their center no matter the user change the view point.

      Use the top of the car as an example, I built a "car_top" group, and used the group as a container, but still did not get the correct coordinate.

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • How to get the absolute coordinates of faces?

      I want to get the absolute center coordinates of faces. But I find the coordinates are affected by the edit mode. Two images in the attachment is an illustration. The first image shows model in edit mode, while the second does not. My goal is to get the absolute coordinate of the center of the red face. However, in the first image, the center is Point3d(-9.0624, -22.0221, 63.6455); in the second image, the center is Point3d(-0.178652, -0.258835, 1.39058).

      The first coordnate is what I wanted. But this required me to use mouse to clik the model several times. Could anyeone tell me if there are some methods to get the absolute coordinate without mouse clik?


      test1.PNG


      test2.PNG

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • RE: How to get entities from selection?

      @tig said:

      Try my suggestion[s] - far easier to understand and get results if you read the alternatives carefully....
      I believe that Aerilius was thinking that your 'selection' was actually a 'group'.
      Then the 'group'.entities would have worked...

      Thanks TIG! I have tried your suggestions. It works, but maybe there is a bug in my script, I did not get the correct coordinates.

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • RE: How to get entities from selection?

      @aerilius said:

      Yes:

      entities = selection.entities #
      > 
      

      ...

      The first line has a "NoMethodError" error...

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • RE: How to add an entity to entities?

      @thomthom said:

      You're aware of the API documentation, right?
      https://developers.google.com/sketchup/docs/classes

      The Entities class has many method to add entites - depending what you want to add:
      https://developers.google.com/sketchup/docs/ourdoc/entities

      You're not talking about adding an existing entity to a different Entities collection?

      I am sorry I made a mistake about the concepts of Sketchup::Entity and Sketchup::ComponentInstance. I have two car models, and I should use entities.add_instance to add a car.

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • 1
    • 2
    • 1 / 2