Hello,
I'm trying to use rexml to read an XML file so I have downloaded rexml
and I use this:
require 'rexml/parsers/pullparser.rb'
if I doing a mistake in the file name sketchup throw an error and with
this line I don't have an error so I suppose that the file is loaded
and my $PATH is ok.
But when I try this:
@xml = REXML::Parsers::PullParser.new( f )
He said: uninitialized constant REXML::Parsers
How can I resolve that?
Thanks in advance
Benjamin
Here is my code
` require 'sketchup.rb'
path=Sketchup.find_support_file("Plugins")
Sketchup::require path+'/rexml/parsers/pullparser.rb'
puts(path+'/rexml/parsers/pullparser.rb')
class LDDFileImport
# Initialize variables
@model = Sketchup.active_model
# function to debug easilly
def DebugPuts(message)
if $show_debug_LDD_messages == true
puts(message)
end
end
#load XML
def ParseFile( filename )
DebugPuts("Begin ParseFile")
if (filename == nil) then return nil; end
model = Sketchup.active_model
model.start_operation "Import LDD File"
begin
DebugPuts "Parsing: "+ filename
entities = model.active_entities
f = File.new( filename, 'r' )
begin
@xml = REXML::Parsers::PullParser.new( f )
model.selection.clear
#model.selection.add TopLevel(entities)
ensure
f.close
end
model.commit_operation
rescue => bang
if (model)
model.abort_operation
end
UI.messagebox( "Error (in script) while reading \"" + filename +
"":\n" + bang )
end
end
end
Quick Debug Code, can be called by the ruby console
def lddParserTest()
was = $svgImportScriptDebug
begin
$show_debug_LDD_messages = true
f = LDDFileImport.new()
f.ParseFile( 'C:/Users/Admin/Desktop/Lego/3pcslxfml.lxfml' )
ensure
$show_debug_LDD_messages = was
end
end
def DoLDDImport
filename = UI.openpanel "Import lxfml File",nil,"*.lxfml"
if (filename)
f = LDDFileImport.new()
f.ParseFile( filename )
end
end
#--------------------------------------------------------------------------
Register within Sketchup
if(file_loaded("ldd.rb"))
menu = UI.menu("Plugins");
menu.add_item("Import lxfml File...") { DoLDDImport() }
end
#--------------------------------------------------------------------------
file_loaded("ldd.rb")`