Sure you could use grep, sed etc but wait, what if we had a scripting language in Sketchup that had good file reading capability, powerful regular expression matching, and a binding to the Sketchup geometry API etc.
I guess we can only hope. π
Seriously, something like this works fine:
IO.foreach("my_inputfile.ext") { |aline| /^(\S*) ([^$]*)/.match(aline) verb = $1 rest = $2 case verb ....whatever you need to do here eg entities.add_face, entities.add_group etc }This is my mickey mouse .obj importer I use for Sketchup:
pos = [] tex = [] group = nil IO.foreach("/tmp/test.obj") { |aline| /^(\S*) ([^$]*)/.match(aline) verb = $1 rest = $2 case verb when "s" # ignore smoothing group when "v" # close current group if group pos = [] tex = [] group = nil end / (\S*) (\S*) (\S*)/.match(rest) pos.push Geom;;Point3d.new($1.to_f,$2.to_f,$3.to_f) when "f" if /(\S*)\/(\S*) (\S*)\/(\S*) (\S*)\/(\S*)/.match(rest) vertices = [pos[$1.to_i], pos[$3.to_i], pos[$5.to_i]] elsif /(\S*) (\S*) (\S*)/.match(rest) vertices = [pos[$1.to_i], pos[$2.to_i], pos[$3.to_i]] end group.entities.add_face vertices when "g" # open a new group /(\S*)/.match(rest) group = Sketchup.active_model.entities.add_group group.name = $1 puts "group(#{$1})" end }Adam