Windowizer 4 - alphabetical order of materials?
-
i'm using windowizer 4 . is there any way to arrange the materials listed in the glass materials in alphabetic order when the drop down menu comes?
-
The
Windowizer4.rbuses
matlist = getMaterials().split("|")
to assemble an collection of the available materials, as an array.
ThegetMaterials.rbreturns a string of all available material-names, separated by '|'.
It IS sorted...matNames.sort.join('|')- I don't see the issue ?
The same sorted list of materials is used for frames and glass ?? -
I don't know ruby..hence i don't know what you're saying

here are two screnshots


-
Open the Ruby Console and type this word + <enter>
getMaterials
It needs to be exactly as it's written [or Copy/Paste]
It should return a list of Materials in the model sorted by their names [separated by '|'] ?
It does that for me... and that's the code used inside Windowizer4 too.
Do you have the currentgetMaterials.rb[comes from Smustard.com with Windowizer4 ?] ?
If it doesn't work try this - Copy/Paste this code it should again be sorted...
matNames=[];Sketchup.active_model.materials.each{|e|matNames<<e.name};matNames.sort

-
@tig said:
Open the Ruby Console and type this word + <enter>
getMaterials
It needs to be exactly as it's written [or Copy/Paste]
It should return a list of Materials in the model sorted by their names [separated by '|'] ?
It does that for me... and that's the code used inside Windowizer4 too.
Do you have the currentgetMaterials.rb[comes from Smustard.com with Windowizer4 ?] ?
If it doesn't work try this - Copy/Paste this code it should again be sorted...
matNames=[];Sketchup.active_model.materials.each{|e|matNames<<e.name};matNames.sort

i have one getmaterials and it has this text
def getMaterials
model=Sketchup.active_model
mats=model.materials
matNames=[]
[]
mats.each {|e| matNames.push(e.name)}
matList=matNames.join('|')
return matList
endno version
your code [rubymatNames=[];Sketchup.a.......] works but do i need to type this everytime?? cant my plugin be edited by adding a line or two?
-
Try this...
Make a copy ofwindowizer4.rb- outside of the Plugins folder so it doesn't auto-load and confuse the issue! IF you screw up you can use it to replace the one you about to attempt a recode on !!
Edit thewindowizer4.rbfile that's in the Plugins folder using Notepad.exe [or an equivalent plain-text editor - NOT a wordprocessor as that will add formating and break the script !]
Find the second line containing the text 'getMaterials' [it's around line#299] that says...
matlist = getMaterials().split("|")
add a '#' to the start of that text thus...
#matlist = getMaterials().split("|")
This stops the line of code being read at all.
Now add this new line of code immediately below it...
matlist=[];@model.materials.each{|e|matlist<<e.name};matlist.sort!
This will make the list in the same way that you did manually in the test I gave you [hopefully successfully again], without the need for 'getMaterials' at all.
The 'wording' is slightly tweaked to suit the script's coding.
Save/close and restart Sketchup to auto-reload the script.
See if the materials lists are now properly ordered...

-
I did the coding sir as you said, im getting the following results.
im getting results like all the <> materials first, after that capital words sorted alphabetically,
then the [] type ones
then with small letters
will that be the order ? i mean SU is giving importance on brackets rather than letters
-
This isn't Sketchup's doing.

The 'sort' algorithm in Ruby does a straightforward alphanumeric sort of the 'words'.
It depends on ASCII code numbers etc...
So punctuation (! # etc), then numbers , then some punctuation (<> etc), then uppercase letters, then some other punctuation ([] etc) and then lowercase letters etc.
Paste this in the Ruby Console to see what I mean:
["zebra","Zebra2","456","123","ABC","[xyz]","[abc]","abc","<abc>","#1"].sort
The 'bracketry' around the material names is to do with how they have been created/imported etc - read the Help section on this...
You could use the 'display_name' [what's show in the Materials Browser] in the sorted list and then have a 'look up table' that uses the materials' 'display_name' against the actual Sketchup 'name'... BUT that some extra coding that RickW needs to do to his script.
Why not PM Rick and explain the issues...
Windowizer4 is a 'commercial script' - therefore posting too much of its code is 'not on' - I even worried about that one line tweak a gave you !
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement