[Plugin] Material_Maintenance v2.2 - 2013-01-13
-
CMD, here is the next iteration of the debug script. It might fix the problem as I have changed the way I specify the special characters I use from literals to providing the actual character codes. Even though they are special they are extended ascii so should work fine. As the .js file is UTF8 encoded I have not changed how I specify the chars there yet, but again it might just work.
Either way I have also added extra trace code, so if it does not work it will give us further info to help pin down the problem.
Do you mind trying it out and sending me the output again? Same procedure as before, just replace the .rb file with the attached version.
-
@mistro11 said:
I'm having such a great month upgrading my Sketchup! Artisan, SketchUV, ProfileBuilder Pro, 1001Bits, and now this VERY useful plugin.
Managing materials was always a major headache for me, especially when building multi-story houses with downloaded furniture. I tend to forget the fact that the downloaded furniture may have some of the same materials I assigned to what I already have in the model. I once waited for a long KT render to find out the pillows on one of the beds were made of chrome. This looks like it will save me a lot of material scanning time before export.
Your first Ruby is a shiner
Thanks Mistro11!
-
!!!=> fromUIHandler: parameter string = 73-0¶__vz¶refreshMaterials¶true¶false¶false p1 = >>73-0Â<< p1 = >>__vzÂ<< p1 = >>refreshMaterialsÂ<< p1 = >>trueÂ<< p1 = >>falseÂ<< p1 = >>false<< calling function >>refreshMaterialsÂ<< Error: #<NoMethodError: undefined method
refreshMaterials' for #<MH_KeepingMyHandIn::MaterialMaintenance:0x11f904b4>>
/Users/johns_iMac/Library/Application Support/Google SketchUp 8/SketchUp/Plugins/Material_Maintenance/Material_Maintenance.rb:122:insend' /Users/johns_iMac/Library/Application Support/Google SketchUp 8/SketchUp/Plugins/Material_Maintenance/Material_Maintenance.rb:122:in
fromUIHandler'
/Users/johns_iMac/Library/Application Support/Google SketchUp 8/SketchUp/Plugins/Material_Maintenance/Material_Maintenance.rb:69:ininitialise'
-
` > 183.chr
·182.chr
¶`
they are not the same as the original chars, I was seeing in my script editor, and the script is now saying it's encoded uft8, which it wasn't
john -
You are returning a string divided up with some unique character.
You then parse that string into bits, splitting it with that character.
Unfortunately that character seems not to be a simple 1 bit ASCII character when passed over, so the split ends with the weird extra character that's left over at the end.
This causes the issue.
MAC and PC Ruby are different in the way they handle text-encoding...
Are your various files encoded as 'UTF-8 without BOM
' ?
If you have Notepad++ it's a simple setting.
This makes files 'cross-platform' [hopefully!].
AND/or can you use a less 'exotic' dividing character - perhaps '|' ? -
@tig said:
You are returning a string divided up with some unique character.
You then parse that string into bits, splitting it with that character.
Unfortunately that character seems not to be a simple 1 bit ASCII character when passed over, so the split ends with the weird extra character that's left over at the end.
This causes the issue.
MAC and PC Ruby are different in the way they handle text-encoding...
Are your various files encoded as 'UTF-8 without BOM
' ?
If you have Notepad++ it's a simple setting.
This makes files 'cross-platform' [hopefully!].
AND/or can you use a less 'exotic' dividing character - perhaps '|' ?TIG, I think your description is spot-on. I have now encoded the attached version of the file with
UTF-8 without BOM
(yes I use Notepad++ ) The JS file is already was already encoded in the that format.I would not have thought that the ruby file encoding should make a difference anymore as I am now explicitly setting the character codes (which are in the ascii range) I suspect JS is passing the character in as UTF-8. The reason for the exotic chars is that Sketchup does not seem to constrain chars users can enter in material names so in theory you can get conflict in the lower ascii range.
I should probably write the simple JSON parser to complement my simple JSON serializer and get rid of the current char token approach in my bridge.
driven, cmd, can you test again please?
-
@driven said:
` > 183.chr
·182.chr
¶`
they are not the same as the original chars, I was seeing in my script editor, and the script is now saying it's encoded uft8, which it wasn't
johnHi John, these are the actual char codes, I have not changed the JS side and these codes still work for me on windows.
I will now also change them in JS to explicit ASCII values. Unfortunately I have to repackage the whole plugin then, so will take me a bit of time, but then again it is likely to work.
-
SketchUp return strings in UTF-8. Anything above the ASCII character range will be multi-byte characters - which is easily mangled by Ruby 1.8's string manipulation methods as it treats 'characters' as single bytes.
-
@thomthom said:
SketchUp return strings in UTF-8. Anything above the ASCII character range will be multi-byte characters - which is easily mangled by Ruby 1.8's string manipulation methods as it treats 'characters' as single bytes.
But my characters are well within the ASCII range...? i.e. they still fit within a byte. from which value does it convert them to multi byte?
-
Ok so here is a debug version with the the token chars explicitly specified in both JS and Ruby. Unfortunately you will have to un-install the whole plugin and install the debug version.
It still has tracing code in, so will still be a bit slow.
John, CMD can you test again please?
-
!!!=> fromUIHandler: parameter string = 73-0¶__vz¶refreshMaterials¶true¶false¶false p1 = >>73-0Â<< p1 = >>__vzÂ<< p1 = >>refreshMaterialsÂ<< p1 = >>trueÂ<< p1 = >>falseÂ<< p1 = >>false<< calling function >>refreshMaterialsÂ<< Error: #<NoMethodError: undefined method
refreshMaterials' for #<MH_KeepingMyHandIn::MaterialMaintenance:0x11b2f898>>
/Users/johns_iMac/Library/Application Support/Google SketchUp 8/SketchUp/Plugins/Material_Maintenance/Material_Maintenance.rb:121:insend' /Users/johns_iMac/Library/Application Support/Google SketchUp 8/SketchUp/Plugins/Material_Maintenance/Material_Maintenance.rb:121:in
fromUIHandler'` -
@driven said:
!!!=> fromUIHandler: parameter string = 73-0¶__vz¶refreshMaterials¶true¶false¶false p1 = >>73-0Â<< p1 = >>__vzÂ<< p1 = >>refreshMaterialsÂ<< p1 = >>trueÂ<< p1 = >>falseÂ<< p1 = >>false<< calling function >>refreshMaterialsÂ<< Error: #<NoMethodError: undefined method
refreshMaterials' for #<MH_KeepingMyHandIn::MaterialMaintenance:0x11b2f898>>
/Users/johns_iMac/Library/Application Support/Google SketchUp 8/SketchUp/Plugins/Material_Maintenance/Material_Maintenance.rb:121:insend' /Users/johns_iMac/Library/Application Support/Google SketchUp 8/SketchUp/Plugins/Material_Maintenance/Material_Maintenance.rb:121:in
fromUIHandler'`Hi John, thanks for testing is this output from the latest Material_Maintenance_debug.rbz file?
If so did you fully delete the previous version, install and restart Sketchup?
-
Yes, I did it manually to start and when the results appeared to go backwards I deleted those and used SU to install the .rbz
exactly the same resultsBTW. if you can put a 20px margin around your html, I can attach web Inspector to look at the js, I need a crack to get in...
-
!!!=> fromUIHandler: parameter string = 73-0|__vz|refreshMaterials|true|false|false p1 = >>73-0<< p1 = >>__vz<< p1 = >>refreshMaterials<< p1 = >>true<< p1 = >>false<< p1 = >>false<< calling function >>refreshMaterials<< String Time = 6.0e-05 Total Entities = 1
I changed the js and the ruby¶
into|
-
next error...
!!!=> fromUIHandler: parameter string = 73-0|__vE|findComponents|·147713020 p1 = >>73-0<< p1 = >>__vE<< p1 = >>findComponents<< p1 = >>·147713020<< calling function >>findComponents<< Error: #<ArgumentError: invalid value for Integer: "·147713020">
-
@driven said:
next error...
!!!=> fromUIHandler: parameter string = 73-0|__vE|findComponents|·147713020 p1 = >>73-0<< p1 = >>__vE<< p1 = >>findComponents<< p1 = >>·147713020<< calling function >>findComponents<< Error: #<ArgumentError: invalid value for Integer: "·147713020">
Good work! This one is because the "·" char (183) char is used as an array token, and is also passed as a double byte char. So you would need to change that also.
BTW, I have just seen that the debug.rbz I attached earlier was not built properly. So it might well be that the fix I put in earlier will work, but I cannot get the build to work yet.
Appologies for wasting your time with testing that version!
-
@myhand said:
@thomthom said:
SketchUp return strings in UTF-8. Anything above the ASCII character range will be multi-byte characters - which is easily mangled by Ruby 1.8's string manipulation methods as it treats 'characters' as single bytes.
But my characters are well within the ASCII range...? i.e. they still fit within a byte. from which value does it convert them to multi byte?
You seem to be using the ANSI range - you use bytes 182 and 183 which is not ASCII.
ASCII is just 0-127 - while ANSI is a sub-set that extends that with 128-255.UTF-8 matches the ASCII character encoding - but does not match ANSI. In UTF-8 bytes 128-255 are control characters. So when you feed a UTF-8 system (like SketchUp) ANSI strings you get messed up characters.
¶
encoded in UTF-8 is[194, 182]
- which is why when you split by just182
you get the extra194
byte (Â
). -
When I send parameters back from WebDialogs I've used combo characters like || or ||| which I know is very unlikely to appear in the data I send. (In the context of what I've done I've been sure they'd not appear.)
In a system where there is user input you'd want to create your own escape sequence where you pick a character as array separator and ensure to escape any occurrence in the data - which then is un-escaped when you receive it on the other end.
-
Another way is to restrict what a user can enter - e.g.
<input type="text" id="project_name" value="" style="font-size:7pt; width:300px;" onKeyup="(this.value=this.value.replace(/[^-_0-9A-Za-z]/,''));" ... >
This example limits the user's INPUT for the 'project_name' to letters, numbers, _, - etc... Then you can be sure that any 'separator' like '|' won't get replicated in the entered text... Obviously you need to change the regexp to suit your needs... -
@tig said:
Another way is to restrict what a user can enter - e.g.
<input type="text" id="project_name" value="" style="font-size:7pt; width:300px;" onKeyup="(this.value=this.value.replace(/[^-_0-9A-Za-z]/,''));" ... >
This example limits the user's INPUT for the 'project_name' to letters, numbers, _, - etc... Then you can be sure that any 'separator' like '|' won't get replicated in the entered text... Obviously you need to change the regexp to suit your needs...yes I agree you always want to constrain at the input. In this case though the input in question is the Sketchup material editor, so I unfortunately have no control over that input.
Advertisement