sketchucation logo sketchucation
    • Login
    1. Home
    2. Iltis
    3. Posts
    ⚠️ Attention | Having issues with Sketchucation Tools 5? Report Here
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 10
    • Posts 41
    • Groups 1

    Posts

    Recent Best Controversial
    • RE: [plugin]Export arcs, circles and vertex to dxf ?

      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

      posted in Extensions & Applications Discussions
      IltisI
      Iltis
    • RE: [plugin]Export arcs, circles and vertex to dxf ?

      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.

      posted in Extensions & Applications Discussions
      IltisI
      Iltis
    • RE: [plugin]Export arcs, circles and vertex to dxf ?

      OK, right.

      posted in Extensions & Applications Discussions
      IltisI
      Iltis
    • RE: [plugin]Export arcs, circles and vertex to dxf ?

      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
          }
      
      
      posted in Extensions & Applications Discussions
      IltisI
      Iltis
    • [plugin]Export arcs, circles and vertex to dxf ?

      Hi, a few year ago, You helped me to do a little plugin to export the outline of selected faces to X:Y coordinates in a text file. (Code below.) Thank you again.

      Today, I wanted to separate the arcs, circles and vectors of a selection (I don't need the faces), to export as 2D dxf file (Z=0 for all entities, like for the X:Y plugin below), with three entities (arc, circle, vectors) and be able to use it in a 2D CAD software.
      (Some pro laser cutting softwares must have the circle/arc entities to do the cutting interpolation ; if you use only small vectors, like the existing free dxf plugin exporter does, the processing and cutting time could be much much longer, so the price of the cutting is higher.)
      It could be a long dxf file, with no groups or order, just one entity after the other, but the circular entities must be described (for example a circle with a center and a radius).

      I have the informations to write the elementary dxf file, but I don't know (after search) how to get the initial datas from the selection. For example the center and the radius of a full circle. Could you help me?

      I'm french, sorry for the english mistakes. My answers can take one or two days, sorry.

      Thank you,
      Renaud.

      Here is the code of the face2X:Y plugin :

      module RenaudIltis
      
      def self.export_face_points
        selection = Sketchup.active_model.selection
        if selection.empty?
      	UI.messagebox("Nothing selected, export canceled")
        else
      	  # Count how many faces are in the current selection => must be > 0
      	 face_count = 0
      	 # Look at all of the entities in the selection.
      	 selection.each { |entity|
      	   if entity.is_a? Sketchup;;Face
      		 face_count = face_count + 1
      	   end
      	 }
      	 if face_count > 0
      		  # Ask for the file path.
      		  filepath = UI.savepanel("Export selected faces",nil,"*.txt")
      		  # Don't continue when the user cancelled
      		  return if filepath.nil?
      		  # Test of the file extension
      		  filepath = filepath.tr("\\","/")#in case any PC ruby weirdness...
      		  if File.basename(filepath,".*") == File.basename(filepath) #the suffix is right or missing
      			filepath=File.join(File.dirname(filepath), File.basename(filepath,".txt") + ".txt") #if the suffix is missing or right
      		  else
      			if File.basename(filepath,".*") + ".txt" != File.basename(filepath)#the suffix is different than .txt
      			   answer = UI.messagebox("Filename has not the '.txt' extension. Change your extension?", MB_YESNO)
      			   if( answer == 6 )
      				  filepath=File.join(File.dirname(filepath), File.basename(filepath,".*") + ".txt")
      			   end
      			else
      			  filepath=File.dirname(filepath) + "/" + File.basename(filepath,".txt") + ".txt" #if the suffix is missing
      			end
      		  end
      		  
      		begin
      		  # Open a file for writing
      		  File.open(filepath, "w"){ |file|
      			selection = Sketchup.active_model.selection
      			# Get an array of faces that are in the selection.
      			faces = selection.grep(Sketchup;;Face) 
      			faces.each_with_index{ |face, index|
      			  # Write a label for the face.
      			  file.puts("Face#{index+1}")
      			  # Get a transformation object that translates from model space to 2d space of the face.
      			  t = Geom;;Transformation.axes(face.vertices.first.position, *face.normal.axes).inverse
      			  # Write all vertices to the file.
      			  blnFirstPoint = true
      			  first_point_u=0
      			  first_point_v=0
      			    face.outer_loop.vertices.each{ |vertex|
      				# Get the point of the vertex and apply the transformation.
      				point = vertex.position.transform(t)
      				# Convert the coordinates
      				u, v = point.to_a.map{ |c| c.to_f }
                      if blnFirstPoint==true
      				  first_point_u = u
      				  first_point_v = v
      				  blnFirstPoint = false
      				end #if
      				# Write the coordinates to the file.
      				file.puts("#{(u*10000*25.4).to_i.to_f/10000};#{(v*10000*25.4).to_i.to_f/10000}")
      	            } 
      			  file.puts("#{(first_point_u*10000*25.4).to_i.to_f/10000};#{(first_point_v*10000*25.4).to_i.to_f/10000}")
      			  }
      		   }
      		  UI.messagebox("The file is here ;" + filepath)
      		rescue SystemCallError => e
      			if e.message =~ /(No such file or directory)/
      				UI.messagebox("Error, the file was not created. Be careful if you are using an older version of SketchUp, the full file path must not contain special characters. The full file path you requested is " + filepath)
      			else
      				fail() #re-raise the last exception
      			end
      		end
      	  else
      		UI.messagebox("No faces in the selection, export canceled")
      	  end
         end 
      end
      
      # This will run only once when the file is loaded the first time.
      unless file_loaded?(__FILE__)
      	# Add the method to the menu.
      	command = UI;;Command.new("Export selected faces to X;Y file"){
      		self.export_face_points
      	}
          command.small_icon = "faces2xy/faces2xy_icon_16.png"
          command.large_icon = "faces2xy/faces2xy_icon_24.png"
          command.tooltip    = "Export selected faces to X;Y file"
          command.menu_text  = "Export selected faces to X;Y file"
      
          menu=UI.menu("Plugins")
      	menu.add_item(command)
      	
      	tb = UI.toolbar("Selected faces to X;Y")
          tb.add_item(command)
          if tb.get_last_state == TB_VISIBLE
              UI.start_timer(0.1, false) { tb.restore }
          elsif tb.get_last_state == TB_NEVER_SHOWN
              tb.show
          end
          file_loaded(__FILE__)
      end
      
      end
      
      
      posted in Extensions & Applications Discussions extensions
      IltisI
      Iltis
    • RE: Rounding a value for export with a &quot;:&quot; separator

      OK, this works well :

                  begin
      		  # Open a file for writing
      		  File.open(filepath, "w"){ |file|
      			selection = Sketchup.active_model.selection
      			# Get an array of faces that are in the selection.
      			faces = selection.grep(Sketchup;;Face) 
      			faces.each_with_index{ |face, index|
      			  # Write a label for the face.
      			  file.puts("Face#{index+1}")
      			  # Get a transformation object that translates from model space to 2d space of the face.
      			  t = Geom;;Transformation.axes(face.vertices.first.position, *face.normal.axes).inverse
      			  # Write all vertices to the file.
      			  blnFirstPoint = true
      			  first_point_u=0
      			  first_point_v=0
      			    face.outer_loop.vertices.each{ |vertex|
      				# Get the point of the vertex and apply the transformation.
      				point = vertex.position.transform(t)
      				# Convert the coordinates
      				u, v = point.to_a.map{ |c| c.to_f }
                  if blnFirstPoint==true
      				  first_point_u = u
      				  first_point_v = v
      				  blnFirstPoint = false
      				end #if
      				# Write the coordinates to the file.
      				file.puts("#{(u*10000*25.4).to_i.to_f/10000};#{(v*10000*25.4).to_i.to_f/10000}")
      	            } 
      			  file.puts("#{(first_point_u*10000*25.4).to_i.to_f/10000};#{(first_point_v*10000*25.4).to_i.to_f/10000}")
      			  }
      		   }
      

      Thanks a lot! 😍
      Renaud

      posted in Developers' Forum
      IltisI
      Iltis
    • RE: Rounding a value for export with a &quot;:&quot; separator

      Hello TIG and driven. The solution of driven work good. Thanks a lot!

      My second problem is how to code the ********lines in Ruby :

        # Open a file for writing
              File.open(filepath, "w"){ |file|
               selection = Sketchup.active_model.selection
               # Get an array of faces that are in the selection.
               faces = selection.grep(Sketchup;;Face)
               faces.each_with_index{ |face, index|
                 # Write a label for the face.
                 file.puts("Face#{index+1}")
                 # Get a transformation object that translates from model space to 2d space of the face.
                 t = Geom;;Transformation.axes(face.vertices.first.position, *face.normal.axes).inverse
                 # Write all vertices to the file.
                 
              ********* blnFirstPoint=true
      
                 face.outer_loop.vertices.each{ |vertex|
                  # Get the point of the vertex and apply the transformation.
                  point = vertex.position.transform(t)
                  # Convert the coordinates
                  u, v = point.to_a.map{ |c| c.to_f }
      
                  ********* if blnFirstPoint=true then
                  *********    X1=u
                  *********    Y1=v
                  *********    blnFirstPoint=false
                  ********* end if
      
                  # Write the coordinates to the file.
                  file.puts("#{(u*10000*25.4).to_i.to_f/10000};#{(v*10000*25.4).to_i.to_f/10000}")
                 }
                 ********* file.puts("#{(X1*10000*25.4).to_i.to_f/10000};#{(Y1*10000*25.4).to_i.to_f/10000}")
                }
               } 
      

      It's to close the faces (see the attached picture).
      Thanks,
      Renaud


      Non-closed export

      posted in Developers' Forum
      IltisI
      Iltis
    • Rounding a value for export with a &quot;:&quot; separator

      Hello,
      I'm working on a plugin to export the 2D coordinates of the selected faces. (Okay, with big help from others, I'm newbie in Ruby)

      		  # Open a file for writing
      		  File.open(filepath, "w"){ |file|
      			selection = Sketchup.active_model.selection
      			# Get an array of faces that are in the selection.
      			faces = selection.grep(Sketchup;;Face) 
      			faces.each_with_index{ |face, index|
      			  # Write a label for the face.
      			  file.puts("Face#{index+1}")
      			  # Get a transformation object that translates from model space to 2d space of the face.
      			  t = Geom;;Transformation.axes(face.vertices.first.position, *face.normal.axes).inverse
      			  # Write all vertices to the file.
      			  face.outer_loop.vertices.each{ |vertex|
      				# Get the point of the vertex and apply the transformation.
      				point = vertex.position.transform(t)
      				# Convert the coordinates
      				u, v = point.to_a.map{ |c| c.to_f }
      				# Write the coordinates to the file.
      				file.puts("#{u*25.4};#{v*25.4}")
      			  }
      			}
      		  }
      

      It works, but I have two problems to solve, can you help me?
      1 / The numbers close to zero are represented by scientific notation (1e-14), which I have problems to read the text file.
      See for example this export of a circle :

      Face1
      0.0;0.0
      6.81483474218631;51.7638090205041
      -9.02389274415327e-014;103.527618041008
      ...
      -393.185165257814;51.7638090205041
      -386.370330515627;-9.02389274415327e-014
      -366.390246014701;-48.236190979496
      ...
      -19.9800845009259;-48.2361909794959
      

      I think I could use the command "sprintf", but I don't know exactly how to write it.

      2 / I need to repeat the first point at the end (to close the outline) and I don't know how to properly store this value for reuse.

      Thanks for your help.
      Renaud.

      posted in Developers' Forum
      IltisI
      Iltis
    • RE: Create file with accent in the path

      Nice, thank you Dan!

      posted in Developers' Forum
      IltisI
      Iltis
    • RE: Create file with accent in the path

      OK, thank you.

      posted in Developers' Forum
      IltisI
      Iltis
    • RE: Create file with accent in the path

      Mhh, the error is

      Error; #<Errno;;ENOENT; No such file or directory - C;/Users/Tarzan/Documents/aiR-C2/MiniCut2d/Bibliothèque/test.f2xy>
      

      I don't understand how to only catch this type of exception... (not in the "Ruby Exception Hierarchy"). I'll see this later.

      posted in Developers' Forum
      IltisI
      Iltis
    • RE: Create file with accent in the path

      Bingo! 2/2. It works fine now. Is "UTF-8 without BOM" the best to use? (Default value?)
      Thank you for the quick answer!
      I will see how to catch only the file exception.

      posted in Developers' Forum
      IltisI
      Iltis
    • RE: Create file with accent in the path

      OK, this code works on SU8 :

      		  begin
      		  File.open(filepath, "w"){ |file|
      			...
      		  }
      		 	UI.messagebox("The file is here ;" + filepath)
      		rescue
      		 	UI.messagebox("Error, the file was not created. Be careful if you are using an older version of SketchUp, the full file path must not contain special or accented characters. The full file path you requested is " + filepath)
      		 end
      

      The "è" looks "è" in the messagebox, but the user know how to fix the problem.

      I try to use it in SketchUp 2014, but I've got an error 😞

      Erreur de chargement du fichier faces2xy.rb
      Error; #<SyntaxError; C;/Users/Tarzan/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/faces2xy.rb;18; syntax error, unexpected ',', expecting ')'
      		  filepath = UI.savepanel ("Export selected faces",nil,"*.f2xy")
      C;/Users/Tarzan/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/faces2xy.rb;18; Can't assign to nil
      		  filepath = UI.savepanel ("Export selected faces",nil,"*.f2xy")
      C;/Users/Tarzan/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/faces2xy.rb;18; syntax error, unexpected ')', expecting ;; or '[' or '.'
      		  filepath = UI.savepanel ("Export selected faces",nil,"*.f2xy")
      
      

      Do you know how to fix this (in all SU versions...)?
      Thanks,
      Renaud

      posted in Developers' Forum
      IltisI
      Iltis
    • RE: Create file with accent in the path

      OK, I see the error in the Ruby Console (thank you for the tip) :

      Error: #<Errno::ENOENT: No such file or directory - C:/Users/Tarzan/Documents/aiR-C2/MiniCut2d/Bibliothèque/test.f2xy>
      ...

      I will try to catch it.

      posted in Developers' Forum
      IltisI
      Iltis
    • RE: Create file with accent in the path

      Mhhh, I've got a problem with my test :

      UI.messagebox(filepath)
      		  # Open a file for writing
      		  File.open(filepath, "w"){ |file|
      			selection = Sketchup.active_model.selection
      			 ...{
                                  ...{
      
      				# Write the coordinates to the file.
      				file.puts("#{u};#{v}")
      			  }
      			}
      		  }
      		 UI.messagebox("FileTest")
      		 if FileTest.exists?(filepath)
      			UI.messagebox("The file is there")
      		 else
      			UI.messagebox("The file is not there")
      		 end
      

      The first messagebox give me the path : "C:\Users\Tarzan\Documents\aiR-C2\MiniCut2d\Bibliothèque\test.txt"
      But no more messagebox after the "File.open"... do you know why?
      But if I understand this topic (http://sketchucation.com/forums/viewtopic.php?t=20289), the ".exists?" is not the solution.

      posted in Developers' Forum
      IltisI
      Iltis
    • RE: Create file with accent in the path

      File.exist? doesn't work, for same reasons... 😞

      posted in Developers' Forum
      IltisI
      Iltis
    • RE: Create file with accent in the path

      Thank you for your answer, but it's too high for me, ruby's newbie.

      Actually, if the file is not created, nothing happen, the user can't know that a problem occured.
      Is it possible to know if there is a problem?

      => If the file "filepath" is not created then Messagebox "You're using SketchUp 2013 or earlier version, the path of your file name can't use accented characters like é,e,è. The file will not be created. If you want to use accented characters in the path, you must use SketchUp 2014 minimum".

      Sorry for my "frenglish".
      Regards,
      Renaud.

      posted in Developers' Forum
      IltisI
      Iltis
    • RE: Create file with accent in the path

      Thank you very much.
      I will try with the last version of SketchUp.

      The link is dead.

      posted in Developers' Forum
      IltisI
      Iltis
    • Create file with accent in the path

      Hello,
      I'm working on a plugin and have this encoding problem : if there is "è" in the path, the file is not created :

      # Open a file for writing
      	  File.open(filepath, "w"){ |file|
      		...
      		  file.puts("Blabla")
      		  
      		}
      	  }
      

      Do you know how to fix it?
      (Test mith Sk7 on Windows7).
      Thanks and regards,
      Renaud.

      posted in Developers' Forum
      IltisI
      Iltis
    • RE: Same Z for multiple components

      Perfect! Thank you very much!

      posted in Newbie Forum
      IltisI
      Iltis
    • 1 / 1