sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    How to draw an edge with an angle and distance

    Scheduled Pinned Locked Moved Developers' Forum
    25 Posts 4 Posters 1.3k Views 4 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.
    • Dan RathbunD Offline
      Dan Rathbun
      last edited by

      When done.. you will need to test the hits array members and retrieve objects that are certain types.

      <span class="syntaxdefault">hit_faces </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> hits</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">select </span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">|</span><span class="syntaxdefault"> e</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">][</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">instance_of</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Face</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault">hit_comps </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> hits</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">select&nbsp;</span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">|</span><span class="syntaxdefault"> e</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">][</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">instance_of</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">ComponentInstance</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">}</span><span class="syntaxdefault"> </span>
      

      ..etc ...

      @TIG: I think hit=rayt[0][0] would return the x coordinate of pt ?

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        Hey you missed my boo-boo I had written hits.each instead of hits.select
        (corrected the code..)

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          morc ... use [ code=php ] and [ /code ] tags around your sourcecode when you post it here.

          I sent you a PrivateMessage, explaining how.

          You are missing 2 end statements at the bottom, just before the **}** closing of the block.

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • M Offline
            morci429
            last edited by

            Tig it isn't working.
            guys could u have a look at the code and tell me what do you think?

            
            require 'sketchup.rb'
            
            UI.menu("PlugIns").add_item("Fire Arrows") {
            
            ents = Sketchup.active_model.entities
            
            Sketchup.active_model.selection.each do |e|
            if e.is_a? Sketchup;;Face
            
            ce=e.bounds.center
            
            en=ce.offset(e.normal, 100000.mm)
            
            cl90=ents.add_cline(ce, en)   #a vertical line
            
            tr=Geom;;Transformation.rotation(ce, Z_AXIS, 45.degrees)
            en.transform!(tr)
            cl45=ents.add_line(ce, en)   #a 45 deg line
            
            
            vec=ce.vector_to(en)
            dist=ce.distance(en)
            
            hits=[]
            pt = Geom;;Point3d.new  
            pe=ce.clone ### set up a copy of the point to raytest from
            goon=true
            while goon
              rayt= Sketchup.active_model.raytest(pe, vec)
              goon=false if not rayt
              pt=rayt[0]
              hit=rayt[1][0]
              goon=false if ce.distance(pt) > dist
              hits << [pt, hit]
              pe=pt ### look from last hit point...
            end#while
            
            
            hits.each do |s|
            if s[1][0].is_a? Sketchup;;Face
            hit_face = s.bounds
            zmin = hit_face.min.z
            zmax = hit_face.max.z
            h = zmax - zmin
            h = h.to_m
            UI.messagebox s[1][0]
            UI.messagebox h
            end
            end
            
            
            tr=Geom;;Transformation.rotation(ce, Z_AXIS, -90.degrees)
            en.transform!(tr)
            cl135=ents.add_cline(ce, en)  #a 135 deg line
            
            #en=ce.offset(Z_AXIS, 5000.mm)
            
            #tr=Geom;;Transformation.rotation(ce, X_AXIS, -45.degrees)
            #en.transform!(tr)
            #cl135=ents.add_cline(ce, en)  #a 135 deg line
            
            #tr=Geom;;Transformation.rotation(ce, X_AXIS, 90.degrees)
            #en.transform!(tr)
            #cl135=ents.add_cline(ce, en)  #a 135 deg line
            
            
            
            end
            end
            }
            

            Thanks Dan,
            i added the two end statements. but the complier doesn't like line 31 ]

            pt=rayt[0]
            

            thanks again Dan

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              @morci429 said:

              Tig it isn't working.

              Error messages?
              Unexpected behaviour?

              It always help to be specific to what isn't working.

              Thomas Thomassen — SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • M Offline
                morci429
                last edited by

                Error: #<NoMethodError: undefined method []' for nil:NilClass> C:/PROGRA~1/Google/GOOGLE~3/Plugins/Fire Arrows.rb:31 C:/PROGRA~1/Google/GOOGLE~3/Plugins/Fire Arrows.rb:7:in each'
                C:/PROGRA~1/Google/GOOGLE~3/Plugins/Fire Arrows.rb:7
                C:/PROGRA~1/Google/GOOGLE~3/Plugins/Fire Arrows.rb:3:in `call'

                Sorry if i wasn't clear enough

                1 Reply Last reply Reply Quote 0
                • TIGT Offline
                  TIG Moderator
                  last edited by

                  Try adding a test after the goon=false if not rayt like
                  next if not rayt that way it will jump.

                  I notice that your 'line' creation is a bit muddled - you a make one then transform the end_point [en] BUT doing so around the Z_AXIS leaves it where it is - do it around the X_AXIS or Y_AXIS...

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    morc..

                    EDIT:The problem is that the API doc does not say that if the ray does not hit anything, the raytest method just returns nil.

                    rayt= Sketchup.active_model.raytest(pe, vec)

                    If you read the API for Model.raytest(), you'll see that the first argument must be an Array; the second optional argument (added in SU8.0M1,) is the wysiwyg_flag that sets whether to hit hidden geometry.

                    EDIT:Actually the method is smart enough to know what you mean... you don't really need an Array arg, unless you want to use the wysiwyg_flag %(#BF4000)[argument.

                    So you can to call it this way:]
                    rayt= Sketchup.active_model.raytest( **[**pe, vec**]** )

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • M Offline
                      morci429
                      last edited by

                      Tig it isn't working.
                      guys could u have a look at the code and tell me what do you think?

                      ...*[snip]*... reposted [in later post](http://forums.sketchucation.com/viewtopic.php?f)
                      
                      1 Reply Last reply Reply Quote 0
                      • Dan RathbunD Offline
                        Dan Rathbun
                        last edited by

                        Added a note at the bottom of the API doc page for Model.raytest() informing readers of the nil return value, when no geometry is "hit."

                        I'm not here much anymore.

                        1 Reply Last reply Reply Quote 0
                        • M Offline
                          morci429
                          last edited by

                          guys i think you are right, the hits array is empty. the ray isn't hitting any geometry. Still trying to find out why though

                          1 Reply Last reply Reply Quote 0
                          • TIGT Offline
                            TIG Moderator
                            last edited by

                            Rather than start with convoluted code try a simple 'one-liner' pasted into the Ruby Console...
                            Draw two rectangular faces place them one above the other, above the origin.

                            rt=true;p=ORIGIN;while rt;p rt=Sketchup.active_model.raytest(p,Z_AXIS);p=rt[0]if rt;end
                            

                            it should produce something like this
                            [Point3d(0, 0, 16.9685), [#<Sketchup::Face:0xbea3ae8>]] [Point3d(0, 0, 39.3701), [#<Sketchup::Face:0xbea3ad4>]] nil
                            NOW you know it's working........

                            TIG

                            1 Reply Last reply Reply Quote 0
                            • M Offline
                              morci429
                              last edited by

                              Mission accomplished
                              Thanks to you all Geniuses

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

                              Advertisement