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

    Posts

    Recent Best Controversial
    • RE: Ruby script to output outer face loop?

      Thank you Thomas for the reply.

      So to verify you are saying that the Loops object returns edges in order, but the outer_loop does not. Correct?

      [Edit]
      Nope doesn't seem to matter. It is still creating lines flipped around.
      (see attachment)
      [/Edit]


      Output from my ruby.  Drawn in Top view.

      posted in Developers' Forum
      E
      emptyvessel
    • RE: Ruby script to output outer face loop?

      Discovered the Angle_Between() method and I am now calculating the start angle.

      Things are looking better...
      Except now I see that an outer loop in Sketchup is not a true path.
      Endpoints of edges are not necessarily coincident with the start point of the next edge.

      Is there some method or setting that will force this situation?
      Otherwise I am looking at recreating every edge and curve in the correct order.

      This is turning into a much bigger project than I had originally hoped.

      posted in Developers' Forum
      E
      emptyvessel
    • RE: Ruby script to output outer face loop?

      Okay I worked on this this weekend and I am ALMOST getting the output I want...

      
      'VB.NET Code output
      gp.AddLine(0.000,10.000,0.000,2.000)
      gp.AddArc(0.000,8.000,4.000,4.000,0.000,90.000)
      gp.AddLine(10.000,12.000,2.000,12.000)
      gp.AddArc(8.000,8.000,4.000,4.000,0.000,90.000)
      gp.AddLine(12.000,2.000,12.000,10.000)
      gp.AddArc(8.000,-0.000,4.000,4.000,0.000,90.000)
      gp.AddLine(2.000,0.000,10.000,-0.000)
      gp.AddArc(0.000,0.000,4.000,4.000,0.000,90.000)
      
      

      The start and end arc angles all appear to be 0 and 90.
      The x,y center point is different for each so I know I am getting each arc in the loop.

      How does this work?

      My latest conversion code.

      
      require 'sketchup'
      
      # Task; Convert sketchup face outer loop to VB.NET graphicpath code
      
      def ConvertToDotNetLine(edge)
        # Convert to VB.NET code graphicpath line definition
        startpt = edge.start.position
        endpt = edge.end.position
          
        s = "gp.AddLine("
        s += "%.3f" % startpt.x.to_f + ","
        s += "%.3f" % startpt.y.to_f + ","
        s += "%.3f" % endpt.x.to_f + ","
        s += "%.3f" % endpt.y.to_f + ")\n" 
        return s
      end
      
      def ConvertToDotNetArc(arc)
        # Convert to VB.NET code graphicpath arc definition
      
        x = arc.center[0]-arc.radius # Left of arc circle's bounding box.
        y = arc.center[1]-arc.radius # Top  of arc circle's bounding box.
        wt = arc.radius * 2          # width of arc circle's bounding box.
        ht = wt                      # height of arc circle's bounding box.
        startang = arc.start_angle
        endang = arc.end_angle
      
        s = "gp.AddArc("
        s += "%.3f" % x.to_f + ","
        s += "%.3f" % y.to_f + ","
        s += "%.3f" % wt.to_f + ","
        s += "%.3f" % ht.to_f + ","
        s += "%.3f" % startang.radians + ","
        s += "%.3f" % endang.radians + ")\n"  
        return s
      end
      
      model = Sketchup.active_model
      face = model.selection[0] 
      
      if (face) 
        sout = ""
        used_edges = []
        loop = face.outer_loop
        edgeuses = loop.edgeuses 
      
        edgeuses.each do|edgeuse|
          edge = edgeuse.edge
          next if used_edges.index edge 
          curve = edge.curve
          if (curve)
            used_edges = used_edges | curve.edges
            if curve.is_a? Sketchup;;ArcCurve        
              sout += ConvertToDotNetArc(curve)
              # UI.messagebox "Edge is an Arc Curve"        
            else
              UI.messagebox "Edge is a Curve"
            end
          else
              sout += ConvertToDotNetLine(edge)
              # UI.messagebox "Edge is a Line"
          end    
        end  # end edgeuses each 
        
        f = File.open("C;\\aaapath.txt", "w")
        f.write(sout)  
        f.close  
        
        UI.messagebox(sout)
      end
      
      
      posted in Developers' Forum
      E
      emptyvessel
    • RE: Ruby script to output outer face loop?

      Okay, Looked up the 'Uniq' method Now I am even more puzzled.
      The following code is a modified version of tt_su's.
      Uniq appears to be returning the wrong number of array elements.

      
      model = Sketchup.active_model
      face = model.selection[0]
      
      if face
        count = 0
        edges_and_curves = []
        edges_filtered = []
        
        loop = face.outer_loop
        edgeuses = loop.edgeuses  
      
        edgeuses.each do|edgeuse|
          count += 1
          edge = edgeuse.edge
          edges_and_curves << edge.curve || edge
        end
        
        edges_filtered = edges_and_curves.uniq
      
        UI.messagebox(edges_filtered.length)  # Reports 5 Should be 8
        UI.messagebox(count) # Correctly reports 52. (4 sides and 4 arcs * 12 facets)  Correct.
      end
      
      
      posted in Developers' Forum
      E
      emptyvessel
    • RE: Ruby script to output outer face loop?

      I think you gentlemen may be giving me too much credit for my knowledge of ruby.
      I am a rank beginner and do not get everything your are saying or showing in your snippets.

      slbaumgartner: your code still displays a arccurve message for all facets of the arc.
      How is "next if used_edges.index edge" suppose to remove edges from consideration?

      tt_su: Your code fails to run at all. "EdgeUses not found"
      Would you be so kind as to explain how each line of your snippet works.

      Regards,

      posted in Developers' Forum
      E
      emptyvessel
    • RE: Ruby script to output outer face loop?

      Okay I have a test script that iterates over the outer loop of a simple rectangle with
      a radius at each corner. What I cannot figure out is how to return just the four lines and four arcs.

      What I get with the following code is four lines and a hit for every facet in each arc.

      What am I doing wrong?

      
      require 'sketchup'
       
      model = Sketchup.active_model
      face = model.selection[0]
      
      if (face) 
        loop = face.outer_loop
        edgeuses = loop.edgeuses 
        
        edgeuses.each do|edgeuse|
      
          edge = edgeuse.edge
          curve = edge.curve
          if (curve)
            if curve.is_a? Sketchup;;ArcCurve
              UI.messagebox "Edge is an Arc Curve"
            else
              UI.messagebox "Edge is a Curve"
            end
          else
              UI.messagebox "Edge is a Line"
          end
        
        end  # end edgeuses each
        
      end
      
      
      posted in Developers' Forum
      E
      emptyvessel
    • RE: Ruby script to output outer face loop?

      I guess I am confused about straight lines.
      From the API documentation I was under the impression that an Edge could be
      A line, curve, or arccurve.

      How do I determine which is which in an if statement.
      Won't All three be true for "if edge.is_a? Sketchup::Edge"?

      posted in Developers' Forum
      E
      emptyvessel
    • RE: Ruby script to output outer face loop?

      Thank you gentlemen for the replies.

      I really want to get into this conversation, but right now I am slammed
      with work.

      My company just upgraded our MRP system and every app I've ever written that leverages the database it is broken.

      I will get back to this question sometime in the near future... perhaps in a week or two.

      Regards,

      Tom

      posted in Developers' Forum
      E
      emptyvessel
    • Ruby script to output outer face loop?

      Hi gang,

      It has been a couple of years since I started to delve into the sketchup api and ruby.

      I am doing a couple of jobs in VB.NET at the moment that could benefit from
      converting 2D sketchup geometry into VB.NET code for it's graphicalpath class.

      Would some kind soul tutor me through creating the script.

      I tossed the following together from memory, but I am sure it is way off base.

      
      # Output a VB.NET graphicalpath for a closed face 
      # bounded by 2D lines and arcs to the windows clipboard.
      
      require 'sketchup'
      include Win32
      
      model = Sketchup.active_model
      face = model.selection[0]
      
      if (Face)
        if Face.is_a? Sketchup;;Face
          
          loop = face.outerloop
      
          edgeuses = loop.edgeuses
      
          sout = ""
          edgeuses.each do|edgeuse|
            edge = edgeuse.edge
      
            if edge.is_a? Sketchup;;Line
              line = edge.line
      	s + ConvertToNetLine(line)
      
            Elsif edge.is_a? Sketchup;;ArcCurve
              arc = edge.arccurve
              s + ConvertToNETArc(arc)
            end
          end
      
      
          clipboard.set_data(sout)
          
      
        else
          # Show 'Select a single Face and try again'
        end 
      end
      
      #--- Functions ---
      
      def ConvertToDotNetLine(line)
        # Convert to VB.NET code graphicpath line definition
        return "gp.AddLine( + line[0] + "," + line[1] + ","  + line[3] + ","  + line[4] + ")\n" 
      end
      
      def ConvertToDotNetArc(arc)
        # Convert to VB.NET code graphicpath arc definition
      
        x = arc.center[0]-arc.radius # Left of arc circle's bounding box.
        y = arc.center[y]-arc.radius # Top  of arc circle's bounding box.
        wt = arc.radius * 2          # width of arc circle's bounding box.
        ht = wt                      # height of arc circle's bounding box.
        startang = degrees(arc.start)
        endang = degrees(arc.stop-arcstart) # Delta of arc angle
      
        Return = "gp.AddArc(" + x + "," + y + "," + wt +  "," + ht + "," + startang "," + endang + "\n"
      end
      
      def degrees(radians)
        return radians / 2 * 3.1415
      end
      
      
      posted in Developers' Forum
      E
      emptyvessel
    • 1 / 1