Get materials from definition (through file operation).
-
Sorry could not describe the topic better.
Don't know how trivial this question is, but is there any way to get a collection of materials from a component definition's path(file). I.e without loading it into Sketchup.
I'm guessing no, but one never knows..
Might add, this will be done from inside a webdialog. Or sent like some sort of value to webdialog.
If it's not doable or to complicated then I guess doing a js-callback and load in the desired comp.definition in Sketchup is more feasable. Then deleting the definition with this snippet I found from TIG.
model.start_operation("Delete Definition") definition.entities.erase_entities(definition.entities.to_a) model.commit_operation
I rather ask now, then finding out later it could have been done much simpler..
-
Option 1. Use the C++ SDK to load the process the .skp file.
Option 2. Reverse engineer the .skp file format. (Not really realistic - I've tried it.)
Option 3. Do load the component, and erase it - as you suggested.
-
@jolran said:
... is there any way to get a collection of materials from a component definition's path(file). I.e without loading it into Sketchup ?
THAT seems like an oxymoronic question.
-
Option 1 and 2 appears to be a lot of more work than option 3 .
I think I'll try option 3 first and see how it goes.
Thank you Thomthom.
Dan.
Yes, I agree, but there are no dumb questions, just dumb people
-
@dan rathbun said:
THAT seems like an oxymoronic question.
Not really, the C++ SDK is there - so it's possible.
-
@jolran said:
@Dan, Yes, I agree, but there are no dumb questions, just dumb people
oxymoron (definition) has nothing to do with being dumb.
How can you know what the path is, to the file, that a
ComponentDefinition
would be loaded from, unless it is already loaded as a member of theDefinitionList
collection, ... that you access, to call it'spath()
method upon, to get the path to it's file .. and 'round and 'round, and again and again, etc., etc ... ? -
Hi Dan, sorry for the missunderstanding.
I should have explained further, but usually when I do, things get more messy.Anyway, in short the path IS known.
I already have a premade collection of components in a plugin/folder.
From there I rebuild the path string from several selections(#id's) in the webdialog.Like: path = File.join(File.dirname(FILE), "somefolder/skp_comps/#{folder}/#{comp_name}.skp")
So, Sketchup.active_model.definitions.load(path)
will of course load the definition to Sketchup.But, yes the path is always only a string and not a drawingelement until entering Sketchup if that is what you meant..
I was hoping one could do something when the path was known, but I think Thomthom already answered that question.
-
@jolran said:
I already have a premade collection of components in a plugin/folder.
OK.. then why not ALSO have a premade collection of Materials in a "plugins/folder/materials" directory ?
-
@unknownuser said:
OK.. then why not ALSO have a premade collection of Materials in a "plugins/folder/materials" directory ?
Might be better to grab the materials from components in this case.
The idea is that the end user should be able to add new components to that folder and everything updates.
Anyway, I "sort of" have it working already now with option 3 (wich was pointed out earlier).
Thanks for the suggestion.
Advertisement