Import 2 components with a single icon.
-
Rest assured, this code is crazy for me too!
But as crazy as it is, it works :
@tig said:
What are you smoking ?
Smoking is bad for health, so I like to drink.
@tig said:
So to test your code YOU need to add some simple steps within it...
For example some p or puts for the returned state as you set various paths,
also testing for File.exist?(some_file_path)Can you show an example, I can test?
@tig said:
To be frank. for someone who is publishing extensions this is a surprisingly poor show...
I can't see what is so difficult in this process.I am sad to disappoint you, but I started in ruby.
My extensions work 99%, with "Dynamic Components", and 1% of ruby, to create a simple toolbar.
Thank you for your franchise.
@tig said:
You seem to to be making things far more complicated than they need to be...
You definitely right!
Can show me a simple example for the same result?
Cordially
David
-
I already showed how to set up distinct references etc and you replied.
http://sketchucation.com/forums/viewtopic.php?p=604766#p604766To check if the two paths are correct try:
puts "#{@@path_to_00} = #{File.exist?(@@path_to_00)}"
puts "#{@@path_to_02} = #{File.exist?(@@path_to_02)}"Perhaps this would also be better to definitely avoid the prompt..
Sketchup.active_model.import(@@path_to_00, false) Sketchup.active_model.import(@@path_to_02, false)
-
Having thought this over...
Assuming both SKP files exist...
I think the issue is caused by your use of themodel.import(path_to_skp)
method.
The first run of the import forks off to another process, where you insert/move the instance of the imported file - thus the second import never starts as it's effectively cancelled by the first one.There are other ways of doing this...
defn = model.definitions.load(path_to_skp)
adds the SKP to the model's definition,
then you can use other methods to insert it into the model.
entities.add_instance(defn, transformation)
Or use the alternative
model.place_component(defn)
You could also make your class a Tool and after adding the instance[s] use your tool to move the instance to a new location...
Another alternative might be to load the two and then make a group and add the two instances to its entities ?I am not entirely sure what it is you are trying to achieve ?
A simpler way might even be to combine the two components into one new SKP and import than ? -
Hello,
I am sorry for not being clear enough.
As it is possible to protect all a collection of "Dynamic Components", with a single "Parent Component," I want to import the "Component Parent" along with my dynamic models.
Import both components with a single icon sembait like a good idea, but I found much better now.
I allowed myself to open a new Topic with this new idea that is totally different.
If you still want to help me, I'd be delighted.
Sorry, for the time you have wasted on this topic.
Cordially
David
-
@tntdavid said:
As it is possible to protect all a collection of "Dynamic Components", with a single "Parent Component," I want to import the "Component Parent" along with my dynamic models.
Create a template model that already has your set of component definitions loaded, and then the user can use that template when they start a new model.
-
@dan rathbun said:
Create a template model that already has your set of component definitions loaded, and then the user can use that template when they start a new model.
I understand your reasoning.
But I wish maximum ease of use of my dynamic components, and simultaneously protect them.
If we take the example of "Click-Window 3D", the windows are useless without the "Control Panel", which is the perfect example of a component "Parent" protector.
If the "Control Panel" is not on the SketchUp scene, you'll have problems with my dynamic components.
Instead of importing the control panel manually, I want it to be imported automatically.
This will prevent user error, because 80% of the time the first reflex of a user is importing the "3D Window" before the "Control Panel".
This can lead to a crash of SketchUp.
It is therefore urgent for me to find a solution to import the "Control Panel" automatically on each new SketchUp scene.
Cordially
David
-
Now you have explained your reasoning perhaps we can come up with some ideas...
When a user clicks on a 3d Window DC to import I assume it's through your code - perhaps a toolbar ?
So instead of immediately importing that DC, you could first check if your special Control Panel component definition is loaded and if so if an instance of it is placed in the current view/scene...
If the answer id no to either of those tests, then additional code could be run to do that step [or those steps] before moving on to import the DC.
As explained before, rather than importing the Control Panel you can use
cp = model.definitions.load(path_to_CP)
Then say place an instance thus
model.active_entities.add_instance(cp, ORIGIN)
Then import the Window DC ?
-
I am currently developing a version of Click-Window 3D without "Control Panel".
The 3D window will be changed manually with tools, "Scale", "Interact with Dynamic Components," and "Component Options".
A perfect example is my plugin, Click-Change.
However, i want to keep the protection of a "Parent" component, which will be a kind of invisible activation key of my "Dynamic Components".
The method used in the code is not important, only those conditions is important:
*** The "Parent" component, must be imported automatically.**
*** It must be on the SketchUp scene before the first dynamic component.**
*** It must be invisible or locked to prevent copy.**
By fulfilling these conditions, we will have a good chance of protecting our dynamic components.
@tig said:
As explained before, rather than importing the Control Panel you can use
cp = model.definitions.load(path_to_CP)
Then say place an instance thus
model.active_entities.add_instance(cp, ORIGIN)Then import the Window DC ?
Your proposal meets the three conditions?
Thank you
David
-
@tig said:
cp = model.definitions.load(path_to_CP)
Then say place an instance thus
model.active_entities.add_instance(cp, ORIGIN)The code should look like this ?
module ClickWindow3D_Trial_mm module SomeSubModule def self.do_somethings() path=Sketchup.find_support_file "cube.skp","Components" model = Sketchup.active_model definitions = model.definitions componentdefinition = definitions.load path point = Geom;;Point3d.new 10,20,30 transform = Geom;;Transformation.new point definitions = model.definitions instance = entities.add_instance componentdefinition, transform end self.do_somethings() end end
If not, can you show me an example?
Without explanation with code examples, I do not understand you.
Thank you for your patience.
David
-
Please indent you code helpfully...
However, even as it is, your code should 'almost' work...
Below, I've made a few minor adjustments, like -
the()
around methods' passed arguments, clearer naming etc...
I have also added###
to the start of some unwanted code [that's like a 'rem
' statement, as seen in some older coding conventions]module TNTDAVID module ClickWindow3D_Trial_mm def self.auto_run_code() path = Sketchup.find_support_file("cube.skp", "Components") ### let's assume that this SKP exists, ### but it does limit the search to that specific SketchUp folder - ### probably best to find it in your own subfolder of SKPs ### and have it shipped within your extension's subfolder ! model = Sketchup.active_model definitions = model.definitions component_definition = definitions.load(path) point = Geom;;Point3d.new(10, 20, 30) ### these offsets are in inches ! transformation = Geom;;Transformation.new(point) ### definitions = model.definitions instance = entities.add_instance(component_definition, transformation) end self.auto_run_code() ### runs the code, loads the skp and places at instance... end end
-
Unfortunately even with your adjustment, the code does not work yet.
When I launch SketchUp, nothing happens.
And the "Ruby console" shipments this error message :
@unknownuser said:
Error: # <TypeError: no implicit conversion of nil into String>
Or is the error?
See you soon.
David
Advertisement