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

    [plugin]Export arcs, circles and vertex to dxf ?

    Scheduled Pinned Locked Moved Extensions & Applications Discussions
    extensions
    13 Posts 2 Posters 2.5k Views 2 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.
    • IltisI Offline
      Iltis
      last edited by

      Hello TIG,

      Thank you very much 👍 , I will try to do a first sample.
      If you have the time to answer :
      1/ Could you look the adds in your code (below), to get the arc entities. Am I right?
      2/ If circ=false, how to get the Sketchup points of the entity?

      Renaud

          circles = []
      		arcs = []
          Sketchup.active_model.selection.grep(Sketchup;;Edge).each{|e|
            c = e.curve ### it's nil if a non-curve edge
            if c && c.is_a?(Sketchup;;ArcCurve) ### might be a circle or an arc
              circ = true
      				arc = false
              c.vertices.each{|v|
                ### vertex has at least edges, but are there at least 2 and are both in the curve
                es = 0
                v.edges.each{|ee| es += 1 if c.edges.include?(ee) }
                if es != 2 ### it's an arc
      						arc = true
                  break
                end
              }
            else ### it's not a curve, or if it is it's not a circle or an arc
              circ = false
              next
            end
            circles << c if circ && ! arc && ! circles.include?(c) ### only add it to list once
      			arcs << c if circ && arc && ! arcs.include?(c) ### only add it to list once
          }
      
          circles.each{|c| ### get circle's properties here, e.g.
            p c.center
            p c.radius
            p c.normal
          }
          arcs.each{|c| ### get arcs's properties here, e.g.
            p c.center
            p c.radius
            p c.normal
      			p c.start_angle
      			p c.end_angle
          }
      
      
      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        I think you have an error in collecting the circles and arcs.
        if es != 2 ### it's an arc arc = true circ = false break end
        later
        circles << c if circ && ! circles.include?(c) ### only add it to list once arcs << c if arc && ! arcs.include?(c) ### only add it to list once

        TIG

        1 Reply Last reply Reply Quote 0
        • IltisI Offline
          Iltis
          last edited by

          OK, right.

          1 Reply Last reply Reply Quote 0
          • IltisI Offline
            Iltis
            last edited by

            Hello TIG,

            When arc=false and circle=false, I wanted to store the entity in an array, could y help me? So at the end, I will use the edges of these entities for writing the polylines.

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

              You now have two arrays - for circles and arcs.
              Process each collected 'curve' in turn.
              e.g.

              circles.each{|c|
                c.edges.each{|e| # the curve's edges
                  # process each edge 'e'
                }
              }
              

              Do the same for the 'arcs' array...

              As it stands, you have arrays of curves which define circles of edges.

              Those 'collections' are pointing to their 'edges' - i.e. defining their 'segments', which can be used as you want later...

              TIG

              1 Reply Last reply Reply Quote 0
              • IltisI Offline
                Iltis
                last edited by

                I misspoke, sorry. I'm OK for the arc and circle. They will be writen in the DXF file as ARC entity and CIRCLE entity.
                What I don't see is how to collect the edges of the vertices of other entities of the selection/loop to write polylines (it's better than just lines for selection in the CAD softwares), when it's not an arc or a circle, in the "else" section of the previous code :

                
                  else ### it's not a curve, or if it is it's not a circle or an arc
                    circ = false
                    arc = false
                    
                    ...
                
                    next
                  end
                
                

                To write as polylines the dxf entities which are not circle or arc, I will use the following functions(*). The function dxf_write_polyline must be modified, because it's based on the loops of the faces, and the loop will be broken - or ignored - by the arcs and circles.

                
                tform=Geom;;Transformation.new()
                layername=model.active_layer.name
                
                def dxf_transform_vertex(vertex, tform)
                   point = Geom;;Point3d.new(vertex.position.x, vertex.position.y, vertex.position.z)
                   point.transform! tform
                   point
                end
                
                def dxf_write_polyline(face, tform, layername)
                 face.loops.each do |aloop|
                  $dxf_file.puts("  0\nPOLYLINE\n 8\n"+layername+"\n 66\n     1")
                  $dxf_file.puts("70\n    8\n 10\n0.0\n 20\n 0.0\n 30\n0.0")
                  for j in 0..aloop.vertices.length do
                    if (j==aloop.vertices.length)
                      count = 0
                    else
                      count = j
                    end
                    point = dxf_transform_vertex(aloop.vertices[count],tform)
                    $dxf_file.puts( "  0\nVERTEX\n  8\nMY3DLAYER")
                    $dxf_file.puts("10\n"+(point.x.to_f * $unit_conv).to_s)
                    $dxf_file.puts("20\n"+(point.y.to_f * $unit_conv).to_s)
                    $dxf_file.puts("30\n"+(point.z.to_f * $unit_conv).to_s)
                    $dxf_file.puts( " 70\n     32")
                  end
                  if (aloop.vertices.length > 0)
                    $dxf_file.puts( "  0\nSEQEND")
                  end
                 end
                end
                
                

                Thank you very much.

                (*)existing plugin from http://www.guitar-list.com, original authors: Nathan Bromham, Konrad Shroeder

                1 Reply Last reply Reply Quote 0
                • IltisI Offline
                  Iltis
                  last edited by

                  Hi,
                  In fact, there is the problem of the order of the vertices to make the polylines. I think I must follow the loops, like in the initial code of guitar-list, but I must test the ".curve" of each vertex and extract the arcs, circles, and the polylines with vertices in the order. A little tricky for me, I will take a paper and a pencil! 😄

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

                    Look at my 'Weld' tool.
                    That takes selected edges, and then welds them into a curve.
                    It has to sort the edges out in order and also get the start/end points correctly ordered.

                    However, a non-arc curve has a list of ordered vertices method, so you can get their positions as points using:
                    points = curve.vertices.collect{|v| v.position }
                    then use
                    points.each_with_index{|p, i| model.active_entities.add_text(i.to_s, p) }
                    to label the points to demonstrate to yourself that they are indeed ordered...

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • IltisI Offline
                      Iltis
                      last edited by

                      Thanks TIG, I will work on it.

                      1 Reply Last reply Reply Quote 0
                      • IltisI Offline
                        Iltis
                        last edited by

                        Hello TIG,
                        Like other people, I have the following problem : with the (Sketchup::ArcCurve) entities, the arcs are always rotated, with the .start_angle value equal to 0.0 (and not equal to the angle with the X axe, the API documentation is wrong on this point in my situation - working with the entities of the loops).
                        Do you have a clean (and 3D) workaround?
                        Best regards,
                        Renaud.

                        1 Reply Last reply Reply Quote 0
                        • IltisI Offline
                          Iltis
                          last edited by

                          I just saw that the .xaxis propery of the arcs are rotated => start_angle=0 is right, because the reference is wrong. OK, knowing that, I can see how to do this.

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

                          Advertisement