[Plugin] Material_Maintenance v2.2 - 2013-01-13

[Plugin] Material_Maintenance v2.2 - 2013-01-13

Postby Myhand » Sat Oct 27, 2012 7:44 pm

Updated to version 2.2 with bug fixes for MAC and large models - Download available at same location below

Updated to version 2.1 with thomthom's coding tips - Download available at same location below

I ran into problems with material management when I started to do PR rendering of my planned home extension. Exports took long and assigning material properties became unmanageable. I also had many materials that looked similar, but had slightly different properties.

I tried the various material clean/replace plugins out there but found that even though they all were good at some things, none quite did what I needed.

So I wrote yet another variation or the material management plugins, but one that does exactly what I want it to do, I did it partly because I needed it and partly to learn how to do plugins.

* It allows you to select multiple materials you want to replace from a list
* You can select which entities and faces you want to update.
* Shows material thumbnails to help identify materials
* You can now choose if you want to change materials in:
- The current selection
- The whole model (does not include component definitions)
- Component definitions
* You can now identify where materials have been used in the model by:
- Construction Lines
- Highlighting the faces and component instances with selected materials
* Selecting all entities with the selected materials applied.
* Allows you to list components that contain the selected materials in their definitions

You can download it here:

http://www.keepingmyhandin.com/Downhome ... ntenance_2
0
Last edited by Myhand on Mon Jan 14, 2013 12:38 am, edited 6 times in total.

Myhand 
 

Re: [Plugin] GlobalMaterialChange v1.4 20110525

Postby Myhand » Sun Nov 11, 2012 10:27 pm

After trying to clean up a fairly large model and finding it hard to figure out which materials to replace, I have updated the Material_Maintenance plugin to include the following features:

* Shows material thumbnails to help identify materials
* You can now choose if you want to change materials in:
- The current selection
- The whole model (does not include component definitions)
- Component definitions.
* Is much faster
* You can now identify where materials have been used in the model by:
- Construction Lines
- Highlighting the faces and component instances with selected materials
* Selecting all entities with the selected materials applied.
* Allows you to list components that contain the selected materials in their definitions

You can download it here:

http://www.keepingmyhandin.com/Downhome ... ntenance_2
0

Myhand 
 

Re: [Plugin] Material_Maintenance v1.0 20121027

Postby Bob James » Mon Nov 12, 2012 8:19 am

There is a bogus blue download button that sends you to a bad place. Really bad. :puke:
Clicking on the file name leads not to a zip download, but to a page that looks like an ftp site. :?

The arrow to the right is the "real" download button for the zip file. :D
0
i7-4930K 3.4Ghz, 2x GTX780 6GB, 32GB DDR3-1600 ECC, OCZ Vertex 4 500GB, WD Black 3TB, 32TB NAS, 4x 27" Monitors, SpaceMouse Pro, X-keys XK-60
User avatar
Bob James 
Premium Member
Premium Member
 

Re: [Plugin] Material_Maintenance v1.0 20121027

Postby Myhand » Mon Nov 12, 2012 9:45 am

Bob James wrote:There is a bogus blue download button that sends you to a bad place. Really bad. :puke:
Clicking on the file name leads not to a zip download, but to a page that looks like an ftp site. :?

The arrow to the right is the "real" download button for the zip file. :D


I apologise Bob! I had a "Comments" widget from PNXE at the bottom of my pages to allow guests to leave comments. This widget is free but supported by adds and I see some of these adds now have "Down load" buttons, which is very annoying. I have now removed the widget at the bottom of the pages. Will need to figure out another way for users to leave comments.

And yes you are right the little arrow to the right of the zip file downloads the file. Clicking the file name link directly browses the content.

Please do let me know what you think! Given that people now cannot leave comments on my blog anymore I might open a thread just for feedback on this Plugin.

Cheers,

Myhand.
0

Myhand 
 

Re: [Plugin] Material_Maintenance v1.0 20121027

Postby thomthom » Mon Nov 12, 2012 12:19 pm

Myhand wrote:http://www.keepingmyhandin.com/Downhome/Sketchup/MaterialMaintenance


Nice looking UI :)


I had a quick look at the source and got a couple of suggestions:

1. #typename is terrible slow! It's string comparison which is a slow operation in any language - but especially in Ruby. #is_a?() is much faster to use. More info: http://www.thomthom.net/thoughts/2011/1 ... -typename/

2. Mostly the plugin is wrapped in a class, but you have some variables and methods you add to the global namespace - that would be, they get added to Kernel - which inherited by Object which then means it'll be in every other object. It's recommended that you wrap everything in its separate namespace - since the SketchUp environment is a shared one. Common convention is that authors pick a root namespace (mine is TT, TIG uses TIG as a root module for everything. Then each plugin get their own module within the author module.
More info: http://www.thomthom.net/thoughts/2012/0 ... velopment/

3. It appear you're using a recursive method to traverse collections of entities. This will eventually lead to a stack overflow and crash SketchUp if the entities collection is large enough. Unroll your recursive loop into a flat one to avoid that.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Plugin] GlobalMaterialChange v1.4 20110525

Postby thomthom » Mon Nov 12, 2012 12:23 pm

Myhand wrote:After trying to clean up a fairly large model and finding it hard to figure out which materials to replace, I have updated the Material_Maintenance plugin to include the following features:

Ah! Didn't notice this before I posted.

Can you please provide just one download link and keep the original post updated? It makes it much easier to keep track of changes and knowing how to get the latest. Links and info within a thread is very easily missed.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Material_Maintenance v1.0 - 2012-10-27

Postby thomthom » Mon Nov 12, 2012 12:40 pm

More comments:

4. Avoid using global variables. You can easily conflict with other plugins if they pick the same variables. Instead make use of a instance or class variable within your namespace. (See #2)

5. Model.start_operation will be much faster if you set the optional disable_ui flag to true.

6. def clearMaterialWithConstructionLines()
Code: Select all
@constructionList.each do |c|
  activeEntities.erase_entities(c);
end

Erase operations, or any entity operation, is quite slow. Try to use a minimum of them.
This one looks can be written as:
Code: Select all

activeEntities
.erase_entities(@constructionList);
 

Faster than doing an erase operation for each entity.

7. Beware of Material.display_name - it should only be used to display the name of the material to the UI, but not as an ID to reference a material. You can get teh wrong material. More info: http://www.thomthom.net/thoughts/2012/0 ... materials/

8.
Code: Select all

begin
  d
.refresh_thumbnail;
rescue;
end


An alternative, that avoids rescuing and looks cleaner would be:
d.refresh_thumbnail if d.respond_to?( :refresh_thumbnail )

(Btw, what's up with the semi-colons?)
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Material_Maintenance v1.0 - 2012-10-27

Postby thomthom » Mon Nov 12, 2012 12:42 pm

That "List Components Containing Selected Materials" function looks really nice. I've yet to test this plugin as I'm in a middle of a large render right now.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Material_Maintenance v1.0 - 2012-10-27

Postby Myhand » Tue Nov 13, 2012 12:54 am

Hi thomthom, thanks for the suggestions they are most welcome! As you might have gathered from looking at the code, I have never coded in Ruby before, so my use is not exactly idiomatic and the SU API is also new to me. I will implement your suggestions later in the week when I have some time.

thomthom wrote:(Btw, what's up with the semi-colons?)


Probably giving away my age ;) but my background is in structured languages (Pascal, Modula 2, C++ and later Java) so I feel naked without the semi-colons... :) I find it harder to read the code without them and Ruby don't seem to mind.
0

Myhand 
 

Re: [Plugin] Material_Maintenance v1.0 - 2012-10-27

Postby Bob James » Tue Nov 13, 2012 4:01 am

Anxious for you two to iron out the details 8-)

A great interface for what will turn out to be an awesome plugin :bounce:
0
i7-4930K 3.4Ghz, 2x GTX780 6GB, 32GB DDR3-1600 ECC, OCZ Vertex 4 500GB, WD Black 3TB, 32TB NAS, 4x 27" Monitors, SpaceMouse Pro, X-keys XK-60
User avatar
Bob James 
Premium Member
Premium Member
 

Re: [Plugin] Material_Maintenance v1.0 - 2012-10-27

Postby thomthom » Tue Nov 13, 2012 9:25 am

Myhand wrote:I have never coded in Ruby before, so my use is not exactly idiomatic and the SU API is also new to me.

But you have coded before - and that shows. :) There's quite a few new plugin authors here that have never coded before. That's why I try to have a scan through their first plugin and give some tips.

Myhand wrote:Probably giving away my age ;) but my background is in structured languages (Pascal, Modula 2, C++ and later Java) so I feel naked without the semi-colons... :) I find it harder to read the code without them and Ruby don't seem to mind.

I know what you mean, these days I work mainly with Ruby, but I used to do web-development - PHP, HTML, JS, CSS. Having spent so long in Ruby land I'm not lost in PHP and often get syntax errors because I forget the ;. Still need to use HTML, CSS and JS for webdialogs - and I've had to set myself into C in order to make C extensions - so I get to use my curly brackets. But there are times where I'm jumping between all them languages all at once - not always easy to adjust too the syntax...
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Material_Maintenance v1.0 - 2012-10-27

Postby Myhand » Sun Nov 18, 2012 9:45 pm

I only got time to work on this again this weekend. Implemented all thomthom's tips, thanks again thomthom! :thumb:

Only one I did not do is 5

thomthom wrote:5. Model.start_operation will be much faster if you set the optional disable_ui flag to true.


As the docs says the flag defaults to false anyway.

I also did the following extra bits:

1) Changed the main hash keys to symbols instead of strings - Again to avoid String comparisons. I ran a few tests and this actually makes a big difference for large strings, but in practice probably not so much here as the material names are usually not so long

2) Now shipping as a .rbz file for easier installing

3) Various other small performance and code complexity enhancements

Works OK on a model of mine that has around 500k entities.

Has anyone tried the previous version out yet?
0

Myhand 
 

Re: [Plugin] Material_Maintenance v1.0 - 2012-10-27

Postby thomthom » Sun Nov 18, 2012 10:31 pm

Myhand wrote:Only one I did not do is 5

thomthom wrote:5. Model.start_operation will be much faster if you set the optional disable_ui flag to true.


As the docs says the flag defaults to false anyway.


Yes? The argument defaults to false - so the UI isn't disabled and you won't get the performance gain. The argument need to be true in order to get a performance gain.

I wonder if I have misunderstood something here - or maybe you misunderstood me?
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Material_Maintenance v1.0 - 2012-10-27

Postby Myhand » Sun Nov 18, 2012 11:41 pm

thomthom wrote:Yes? The argument defaults to false - so the UI isn't disabled and you won't get the performance gain. The argument need to be true in order to get a performance gain.

I wonder if I have misunderstood something here - or maybe you misunderstood me?


Thanks thomtthom. It is me being an idiot! :oops:

Yes, you are of course right. I got the logic inverted. Changes made and the updated version has been uploaded.
0

Myhand 
 

Re: [Plugin] Material_Maintenance v1.0 - 2012-10-27

Postby Myhand » Sun Nov 18, 2012 11:52 pm

thomthom wrote: I've had to set myself into C in order to make C extensions - so I get to use my curly brackets.


Curly braces is what I miss most in Ruby :D. And of course a good IDE would have been nice... I am generally surprised with the lack of tools and libraries. e.g. no JSON support was a unfortunate surprise, and would have made the GUI much easier.

For this add-in I have written a simple protocol, which supports strings and arrays, but no complex objects or matrixes. Was going to show a tree of the model, but need to pass more complex data structures then, and JSON would have been perfect.

Does the C API give you better access to the model? I would love to be able to change the layer materials (transparency and colour) as this currently requires manual setup in my plugin.
0

Myhand 
 

Re: [Plugin] Material_Maintenance v1.0 - 2012-10-27

Postby thomthom » Mon Nov 19, 2012 1:37 pm

Myhand wrote:Curly braces is what I miss most in Ruby :D. And of course a good IDE would have been nice... I am generally surprised with the lack of tools and libraries. e.g. no JSON support was a unfortunate surprise, and would have made the GUI much easier.

For this add-in I have written a simple protocol, which supports strings and arrays, but no complex objects or matrixes. Was going to show a tree of the model, but need to pass more complex data structures then, and JSON would have been perfect.

I've got a bridge in development in my TT_Lib2 library: http://www.thomthom.net/software/sketchup/tt_lib2/doc/
A JSON sub-class of a Hash and a bridge where I can call JS functions just with their name from Ruby and it will convert many types of objects to JS object and the return value of the JS function will be converted back into Ruby objects. Got most of the basic data types working and some of SU's custom classes, such as Vector3d and Point3d.
https://bitbucket.org/thomthom/tt-library-2/

Parallel to that there's a WebDialog bridge developed in SketchUp's Developer Tools they released as Open Source at last Basecamp: https://github.com/SketchUp/sketchup-developer-tools

You could have a look at either repos if it could help you.

It would have been interesting to create a standalone bridge as an open source project, avoiding each developer to create their own version.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Material_Maintenance v1.0 - 2012-10-27

Postby cmd » Fri Nov 23, 2012 10:05 pm

When I launch the plugin, the materials list area is empty and when I select "Re-Load Materials", I receive the following error:

"Error: #<NoMethodError: undefined method `refreshMaterials' for #MH_KeepingMyHandIn::MaterialMaintenance:0x24571cb8>>"

You can see the attached screenshot

Thoughts?

CMD
0
- CMD
User avatar
cmd 
SketchUp Team
SketchUp Team
 

Re: [Plugin] Material_Maintenance v1.0 - 2012-10-27

Postby TIG » Fri Nov 23, 2012 11:11 pm

@cmd

Do you have a Selection made before this Tool is launched ?
It's not obvious from your screenshot.
You have its 'Materials' option set to 'Select from List' and its 'Scope' option set to list for 'Selection Only'...
This might then invoke an untrapped error ?
This obviously shouldn't happen... BUT it might explain things...
Try using it with a selection and/or some different option settings...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Material_Maintenance v1.0 - 2012-10-27

Postby Myhand » Sat Nov 24, 2012 12:40 am

cmd wrote:When I launch the plugin, the materials list area is empty and when I select "Re-Load Materials", I receive the following error:

"Error: #<NoMethodError: undefined method `refreshMaterials' for #MH_KeepingMyHandIn::MaterialMaintenance:0x24571cb8>>"
CMD


Hi CMD,

I see you are running on a MAC which unfortunately I cannot test against. It appears not to be able to find the refreshMaterials method, which is definitely there and working on windows. Only thing I can think of is that either:

- ruby behaves differently on a MAC (I am not a Ruby expert so might well not have the method syntax exactly right when you add modules etc, and maybe the MAC implementation is stricter that the windows)
- or JavaScript behaves marshals the string containing the method name differently.

Few questions:
- Do you have a windows machine you can test this on?
- Is this happening with all models? I suspect it is as not finding the method should not be model dependent.
- have you tried remove the plugin manually (all files) and reinstalling
0

Myhand 
 

Re: [Plugin] Material_Maintenance v1.0 - 2012-10-27

Postby Myhand » Sat Nov 24, 2012 12:42 am

TIG wrote:@cmd

Do you have a Selection made before this Tool is launched ?
It's not obvious from your screenshot.
You have its 'Materials' option set to 'Select from List' and its 'Scope' option set to list for 'Selection Only'...
This might then invoke an untrapped error ?
This obviously shouldn't happen... BUT it might explain things...
Try using it with a selection and/or some different option settings...


Good thought TIG, but from what I can see this should not cause the problem. I have specifically tested for no selection, and the error is also not a null pointer error. I think it has to do with it running on a MAC...
0

Myhand 
 

Re: [Plugin] Material_Maintenance v1.0 - 2012-10-27

Postby thomthom » Sat Nov 24, 2012 11:46 am

hm... the error is a missing refreshMaterial method - how can that be OSX specific?
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Material_Maintenance v1.0 - 2012-10-27

Postby Myhand » Sat Nov 24, 2012 1:41 pm

thomthom wrote:hm... the error is a missing refreshMaterial method - how can that be OSX specific?


I pass the method name in from javascript... the method certainly is there, and this code works on Windows... So somehow it does not resolve in this case.

So as far as I can see: either the method name coming in from JS (I assume the webdialog run in Safari on OSX) is somehow corrupted - how I do not know or I am not using the robust RUBY syntax in defining the method, and Ruby on OSX cannot find it.

For instance should I pre-pend it with "self". I do not know and cannot debug as I do not have OSX.

Has anyone else had this problem in windows, or got it working in OSX?
0

Myhand 
 

Re: [Plugin] Material_Maintenance v1.0 - 2012-10-27

Postby Myhand » Sat Nov 24, 2012 10:36 pm

cmd, I have done some experiments and suspect you may have a corrupt installation.

You can either:

- fully delete the plugin. The whole ..\Plugins\Material_Maintenance folder. And the reinstall and see if you still get the problem

- open your ..\Plugins\Material_Maintenance\Material_Maintenance.rb file in a text editor and see if on line 150 you have the following method definition:

def refreshMaterials(selectionOnly, wholeModel, components)

- send me the ..\Plugins\Material_Maintenance\Material_Maintenance.rb file
0

Myhand 
 

Re: [Plugin] Material_Maintenance v1.0 - 2012-10-27

Postby cmd » Sat Nov 24, 2012 10:56 pm

Myhand wrote:
- open your ..\Plugins\Material_Maintenance\Material_Maintenance.rb file in a text editor and see if on line 150 you have the following method definition:

def refreshMaterials(selectionOnly, wholeModel, components)


I have looked into the file and I have found the required "refreshMaterials" definition.

Regardless, I will test it out on my windows system through parallels and let you know what I find.

CMD
0
- CMD
User avatar
cmd 
SketchUp Team
SketchUp Team
 

Re: [Plugin] Material_Maintenance v1.0 - 2012-10-27

Postby Myhand » Sun Nov 25, 2012 11:44 am

cmd wrote:I have looked into the file and I have found the required "refreshMaterials" definition.

Regardless, I will test it out on my windows system through parallels and let you know what I find.

CMD


Thanks CMD, that will be very useful. I hate not being able to debug it myself!
0

Myhand 
 

Re: [Plugin] Material_Maintenance v1.0 - 2012-10-27

Postby Myhand » Sun Nov 25, 2012 9:40 pm

thomthom wrote:I've got a bridge in development in my TT_Lib2 library: http://www.thomthom.net/software/sketchup/tt_lib2/doc/
A JSON sub-class of a Hash and a bridge where I can call JS functions just with their name from Ruby and it will convert many types of objects to JS object and the return value of the JS function will be converted back into Ruby objects. Got most of the basic data types working and some of SU's custom classes, such as Vector3d and Point3d.
https://bitbucket.org/thomthom/tt-library-2/

Parallel to that there's a WebDialog bridge developed in SketchUp's Developer Tools they released as Open Source at last Basecamp: https://github.com/SketchUp/sketchup-developer-tools

You could have a look at either repos if it could help you.

It would have been interesting to create a standalone bridge as an open source project, avoiding each developer to create their own version.


Thank you thomthom, very impressive library! :thumb: A shame I did not know about it before I started.

Unfortunately I already developed a basic bridge so changing it now would be more work than just adding a JSON marshal class. I wrote a basic one in ruby (so probably not the most efficient but works fine for the size of objects I want to pass). Does all objects, and escapes special characters etc. and does the trick for now. I will publish the code a bit later if anyone is interested. As all of my complex objects go from ruby to JS I have not written a parser (yet).

You have some experience with the C++ API. Does that give access to more attributes than the Ruby API. Specifically I want to change the material assigned to layers.
0

Myhand 
 

Re: [Plugin] Material_Maintenance v1.0 - 2012-10-27

Postby thomthom » Sun Nov 25, 2012 10:16 pm

Myhand wrote:You have some experience with the C++ API. Does that give access to more attributes than the Ruby API. Specifically I want to change the material assigned to layers.

The C++ SDK for for reading and writing files. It's not something you can use from within SketchUp - manipulate the active model.
But if your goal it to generate a SKP file, then it might be the thing for you. However, I've not used it.


Regarding the Bridge - we talked about this at Basecamp (2012). I think the topic has potential for an Open Source project. We're currently testing out the experience of open source group projects with the STL Importer/Exporter and the Development Tools that SketchUp released. I'd like to see a bridge project established - and even more projects - so we can avoid redoing the work which the next man already have done.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Material_Maintenance v1.0 - 2012-10-27

Postby Myhand » Mon Nov 26, 2012 11:43 pm

For anyone interested here is a link to the JSON formatter class I created. I am now using this for the next version of this plugin, which will allow you to pick a component and find its parent hierarchy. i.e. components containing nested instances of the specified component.

http://www.keepingmyhandin.com/Downhome ... ementation
0

Myhand 
 

Re: [Plugin] Material_Maintenance v1.0 - 2012-10-27

Postby cmd » Tue Nov 27, 2012 12:42 am

Myhand wrote:Thanks CMD, that will be very useful. I hate not being able to debug it myself!


Myhand,

I installed the script on my windows version and all worked fine.

I also removed and reinstalled it on my Mac but I am getting the same error on launch of the script :(

Error: #<NoMethodError: undefined method `refreshMaterials' for #<MH_KeepingMyHandIn::MaterialMaintenance:0x15306b40>>



CMD
0
- CMD
User avatar
cmd 
SketchUp Team
SketchUp Team
 

Re: [Plugin] Material_Maintenance v1.0 - 2012-10-27

Postby Myhand » Tue Nov 27, 2012 1:17 am

cmd wrote:
Myhand wrote:Thanks CMD, that will be very useful. I hate not being able to debug it myself!


Myhand,

I installed the script on my windows version and all worked fine.

I also removed and reinstalled it on my Mac but I am getting the same error on launch of the script :(

Error: #<NoMethodError: undefined method `refreshMaterials' for #<MH_KeepingMyHandIn::MaterialMaintenance:0x15306b40>>


CMD


Thanks CMD, sounds like my hunch might have been right and that it is something to do with the MAC.

Can anyone that has used the script on a MAC (successfully or otherwise) please let me know?

Else we might have to do this the hard way... CMD, if I add some debug code to the script would you mind running it and sending me the output?

Cheers,

myhand
0

Myhand 
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 

Next


 

Return to Plugins

Who is online

Users browsing this forum: typhoon1969 and 32 guests

Visit our sponsors: