Thursday, November 30, 2023
Home3D ModelingWould somebody be so sort as to check if this code works...

Would somebody be so sort as to check if this code works for you? – Ruby API


Would somebody be so sort as to check if this code works for you?
It really works for me however apparently not for different computer systems. I don’t know whether it is because of the language of the pc.
The code reads an xml file generated by a scheduling software program (Microsoft Venture) and creates two hashes within the mannequin with the duty information.
That is the xml file
Check Project3.xml.zip (9.4 KB)

module Rtches
	module Features
		lengthen self
		def self.loadXmlFileFromProject()
			require 'rexml/doc'
			embrace REXML
			@mannequin = Sketchup.active_model
			@mannequin.start_operation("dates import", true)
			xmlfilename = UI.openpanel("Open XML File", "c:/", "XML Recordsdata|*.xml||")
			return except xmlfilename
			xmlfile = File.new(xmlfilename)
			start
				xmldoc = Doc.new(xmlfile)
				@fechasdict = @mannequin.attribute_dictionary('Sketchup4D',true)
				XPath.every(xmldoc, "//Activity") 
					@fechasdict.set_attribute 'Tareas',e.parts["GUID"].textual content,[e.elements["Name"].textual content,
						e.parts["Start"].textual content,e.parts["Finish"].textual content,e.parts["WBS"].textual content,
						e.parts["ID"].textual content,e.parts["Summary"].textual content]
					valuetoadd = e.parts["WBS"].textual content + " " + e.parts["Name"].textual content
					@fechasdict.set_attribute 'Tareas2',valuetoadd,e.parts["GUID"].textual content
					
				test1 = @fechasdict.attribute_dictionary('Tareas').depend
				test2 = @fechasdict.attribute_dictionary('Tareas').depend
				if test1==0 || test2 ==0
					UI.messagebox('no duties discovered, please verify your xml file')
				else
					UI.messagebox("#{test1.to_s}"+' duties imported')
				finish
			rescue
				# mistake message
				UI.messagebox('the file couldn't be imported, please verify the file content material.')
			finish
			@mannequin.commit_operation
		finish
	finish
finish
Rtches::Features::loadXmlFileFromProject()

The result’s this:

Thanks upfront.


The XML file is UTF-8 encoded. That is good, however usually Microsoft packages on Home windows produce recordsdata encoded as UTF-16LE.

The file I uploaded was the one which it’s imagined to fail with the code I posted. If the issue is the encoding it should fail in all computer systems, mustn’t it?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments