Ruby plugin - Export from skp to Quake .map file
-
Hi! I'm a noob at ruby scripts and I'd like to make a ruby plugin for converting sketchup models to GTK Radiant editor (Quake III Arena) .map files.
The .map file is basically a .txt file structured as follows:**```
//entity 0
{
"classname" "worldspawn"
// brush 0
{
( 126 -344 92 ) ( 130 -344 92 ) ( 130 -352 96 ) common/caulk 0 0 90 0.25 0.25 0 0 0
( 126 -336 128 ) ( 126 -352 128 ) ( 126 -336 0 ) gothic_ceiling/woodceiling1a 0 0 90 0.25 0.25 0 0 0
( 130 -344 92 ) ( 126 -344 92 ) ( 130 -344 0 ) gothic_ceiling/woodceiling1a 0 0 90 0.25 0.25 0 0 0
( 130 -352 0 ) ( 130 -336 0 ) ( 122 -352 0 ) common/caulk 0 0 90 0.25 0.25 0 0 0
( 130 -352 0 ) ( 130 -352 128 ) ( 130 -336 0 ) gothic_ceiling/woodceiling1a 0 0 90 0.25 0.25 0 0 0
( 130 -352 0 ) ( 122 -352 0 ) ( 130 -352 128 ) gothic_ceiling/woodceiling1a 0 0 90 0.25 0.25 0 0 0
}
}where, in a brush (a block), each line represents a plane whith its texture. Each plane is represented by 3 coordinates (a triangle). Planes can only define convex brushes (blocks); no concavities allowed **``` //entity 0 { "classname" "worldspawn" // brush 0 { ( x y z ) ( x y z ) ( x y z ) texturefolder/texture sShift tShift rotation sScale tScale |detail|structural| 0 0 ( x y z ) ( x y z ) ( x y z ) texturefolder/texture sShift tShift rotation sScale tScale |detail|structural| 0 0 ( x y z ) ( x y z ) ( x y z ) texturefolder/texture sShift tShift rotation sScale tScale |detail|structural| 0 0 ( x y z ) ( x y z ) ( x y z ) texturefolder/texture sShift tShift rotation sScale tScale |detail|structural| 0 0 ( x y z ) ( x y z ) ( x y z ) texturefolder/texture sShift tShift rotation sScale tScale |detail|structural| 0 0 ( x y z ) ( x y z ) ( x y z ) texturefolder/texture sShift tShift rotation sScale tScale |detail|structural| 0 0 } } ```** I think what I'm trying to script is at least conceptually quite easy, but I don't know how to start.. The main question I ask is how to make sketchup creat a txt or map file to input converted data into?
-
The SketchUp API does not have IO methods... That is standard to Ruby.
So you need to 1st learn standard Ruby.
Ruby Newbie's Guide to Getting Started -
Ok, i've been playing around with the ruby console in sketchup and some of those tutorials (Thanks for the links!) and at least I wrote some commands I liked:
Dir.chdir("/Temp") File.new("newfile.map", "w+")
And that creates a new .map file in the Temp folder for me to write into. Does anyone know how to make a "select folder" popup, or save the file in the same folder as the .skp?
-
Sketchup's UI API
UI.open_panel()
, andsave_panel()
etc
Thenfolder=File.dirname(model.path)
etc
Read both the API, AND the general Ruby File/Dir stuff together...You don't need to use Dir.chdir() if you give
File.new(fpath, 'w')
the full-path to the file... which you can of course pre-assemble from the model's directory path and the new file's name, thus
fpath=File.join(File.dirname(model.path), 'my.map')
Of course you can check that the model has been saved and therefore
not model.path.empty?
before proceeding etc...
Advertisement