Ok. I didn't know.. I thought it was native. Is there some way to stash this inside my script so that the method is local? Or perhaps I shouldn't worry about that? (How do I check if a method is defined? If I can't, are duplicates OK?)
Posts made by agamemnus
-
RE: Looking to make a script, but dunno how.
-
RE: Looking to make a script, but dunno how.
@chris fullmer said:
A few things. I'm getting errors when I try to run the script. I have not looked at all the code, so I'm not sure what I'm doing wrong yet. But, I'll try to look it over tonight.
I'm also not entirely sure what your questions are about groups and components and component instances. Maybe it will make more sense when I get the script to run all the way through. I'll try to get back to this in a few hours,
Chris
I don't know why you are getting errors. I am not getting any errors. I did not use any globals AFAIK, so that can't be it. No idea.
I'll try to rehash the question. I'm trying to convert the "target" objects into "base" objects but so far the only way to do that is to convert the "targets", if they are groups or lines, to new/unique component instances and then change the definition of that instance. Instead, I would like to either change the unique component instances back into groups (and delete the component definition), or to simply change the objects right away into groups, depending on whether any of these methods are possible and which one is faster. (see "Convert_objects_randomly.choosetarget_changeobjects")
-
RE: Looking to make a script, but dunno how.
Here is a file with both scripts (random color and object), and another file that shows the result of using SketchyPhysics 3, these two scripts, and Chris Fullmer's "Scale and Rotate Multiple" and "Loose Geometry to Groups" scripts. (Gems are from the 3D Warehouse)
So now ... what if I wanted to make the result groups instead of component instances? So far the script is only converting everything to unique component instances and changing the definition. Ideally I want to just change the geometry of the groups without making unique component instances. So, assuming I could do one of these, which one is more efficient (faster), and can I even do any of these (and how) --?
-
Convert "target" objects to component instances based on "base" objects, then convert "target" objects back to groups and delete the components.
-
Convert "target" objects straight to groups based on "base" objects.
(If anyone thinks my question is unclear I would rephrase it.. I needs answers!
)
-
-
RE: The Go Programming Language (By Google)
I didn't watch it all (maybe later) but here are some thoughts.
The man speaks a lot of truth.
You cannot have a truly efficient and truly dynamic language. (though he never says you can). You can have a semi-dynamic language. A lot of people don't really use PHP's dynamic capabilities (like looking at its own code as a string) very much, but the semi-typelessness is what makes it "easy". You really have to sacrifice parts of the dynamic language to make it efficient. So I guess he's right on in that.
Reduce typing? Yes. Foo should go away.
Remove type hierarchies? Eh?
Clean syntax? YES, stop it with the alternative vague shortcuts already!
No implicit basic type conversions? Well, ok.
I don't like case sensitivity in general. Making case change the meaning of something completely is even worse. No support there.
Multi-thread capable? Well, I guess that is very complicated and offloading that to the language is good. But of course it does reduce the programmer's power, though in most cases it'd be an acceptable trade-off. -
RE: Looking to make a script, but dunno how.
Okay, script 1 is finished. It could use some expansion though, possibly. (eg: (1) convert areas instead of just lines, groups, and components [hard] and (2) don't make identical unique components as options [very doable, but might not be worth it]) The only real problems now are cosmetic:
-
I am not sure that "Convert objects randomly" is a very good name for the script. I can't think of anything else that is both short and also semi-self-explanatory, though.
-
The dropdown in the "options" is too big! I don't know how to set its width.
Code:
# ---------------------------------- # ================================== # ---------------------------------- # # "Convert objects randomly" script # Released into the public domain by Agamemnus. # Version 1; November 10, 2009 # Contact the author; sketchup at flyingsoft dot phatcode dot net # # Purpose; # # Easily converts a set of objects (target) into another set (base) randomly, # distributed amongst members of the base set. # # Use; # 1) Select a set of objects -- currently only components and/or groups work. # 1b) Pick "Select base objects" in "Plugins">"Convert Objects Randomly". # 2) Select a target set of objects -- currently only components, groups, or lines. # 2b) Pick "Convert selected to random base objects" in "Plugins">"Convert Objects Randomly". # 2c) Done! You may pick "Convert selected to random base objects" again if you wish -- # your previous base and target object sets apply if you did not fundamentally change # (explode, convert to group, etc-- geometry editing is fine) the target components. # # 3) Set "Plugins">"Convert Objects Randomly">"Settings">"Convert lines to base objects?" to "YES" # if you want ungrouped lines in the target set to be affected. Set "NO" otherwise. # The default is "YES". # # Behavior of result objects in version 1; # If the picked "base" object is a group, the target object is converted into a unique component. # If the picked "base" object is a component, the target object is converted into a component # instance of that component type. # # # ==Miscellaneous Notes;== # 1.) Much thanks to the Sketchup forum regulars in helping with problems in this script. # # 2.) Looking for Work ;( # ...in the fields of; # economic analysis # business strategy # marketing # UI design # web based programming # 2D visual art # 3D visual art. # general programming. # M.A. in International Economics and Finance at Brandeis IBS, BA in economics at Brandeis IBS and Brandeis University. # 16 years of experience in amateur programming in BASIC-based languages (Basic, Freebasic, VB, etc.) # Several years of experience in PHP and Javascript. Experience in C-LISP, Matlab, and "some" # experience in Ruby (eh!) and C. # Work environment must at a _minimum_ contain penguins performing tricks, live. # # ---------------------------------- # ================================== # ---------------------------------- require 'sketchup.rb' module Convert_objects_randomly @base_entities = [] @target_entities = [] @convert_lines = true def Convert_objects_randomly.choosebase @base_entities = Sketchup.active_model.selection.to_a if @base_entities.empty? results = UI.messagebox "Please select base groups and/or components first." Sketchup.send_action "selectSelectionTool;" return end end def Convert_objects_randomly.choosetarget target_entities = Sketchup.active_model.selection.to_a if @base_entities.empty? results = UI.messagebox "Please select base groups and/or components first." Sketchup.send_action "selectSelectionTool;" return end if target_entities.empty? if @target_entities.empty? results = UI.messagebox "Please select target groups and/or components first." Sketchup.send_action "selectSelectionTool;" return end target_entities = @target_entities end target_entities.each do |current_entity| if current_entity.is_a?(Sketchup;;Group) current_entity = current_entity.to_component current_entity.definition = @base_entities[rand(@base_entities.length)].definition elsif current_entity.is_a?(Sketchup;;ComponentInstance) current_entity = current_entity.make_unique current_entity.definition = @base_entities[rand(@base_entities.length)].definition elsif (@convert_lines == true) current_entity = Sketchup.active_model.active_entities.add_group(current_entity) current_entity = current_entity.to_component current_entity.definition = @base_entities[rand(@base_entities.length)].definition end end @target_entities = target_entities Sketchup.active_model.commit_operation end def Convert_objects_randomly.settings if (@convert_lines == true) default = "yes" else default = "no" end settings_query1 = inputbox(["Convert lines to base objects? "],[default], ["yes|no"], "Convert Objects Randomly Settings") if (settings_query1[0] == "yes") @convert_lines = true else @convert_lines = false end end end #Convert_objects_randomly module Convert_objects_randomly_menu = UI.menu("Plugins").add_submenu("Convert Objects Randomly") Convert_objects_randomly_menu.add_item("Select base objects") {Convert_objects_randomly.choosebase} Convert_objects_randomly_menu.add_item("Convert selected to random base objects") {Convert_objects_randomly.choosetarget} Convert_objects_randomly_menu.add_item("Settings") {Convert_objects_randomly.settings}
-
-
RE: Looking to make a script, but dunno how.
Ugh. Maybe it's just better to use Chris's unsorted geometry->groups script first.
-
RE: Looking to make a script, but dunno how.
@martinrinehart said:
@agamemnus said:
Ok, thanks. How do I convert an entity to an entities collection?
You don't. Use an entities collection returned by the entities method:
> Sketchup.active_model.entities > myGroup.entities > someComponent.entities >
But I can't... it's not a group or component. It's a line.... tried "current_entity = current_entity.entities", no go.
-
RE: Looking to make a script, but dunno how.
@thomthom said:
@agamemnus said:
- The code refuses to convert lines to groups!! (I have "current_entity = current_entity.add_group")
Check the API on that method. It only belongs to Entities collections. Not single Entity
http://code.google.com/intl/nb/apis/sketchup/docs/ourdoc/entities.html@agamemnus said:
- Is there any way to make a yes/no dropdown
Check the second example in the manual:
http://code.google.com/intl/nb/apis/sketchup/docs/ourdoc/ui.html#inputboxOk, thanks. How do I convert an entity to an entities collection?
Edit: The textbox width is still really long, even with the dropdown now...
-
RE: Looking to make a script, but dunno how.
Thanks guys. Got myself two more issues now, though.
- The code refuses to convert lines to groups!! (I have "current_entity = current_entity.add_group")
- Is there any way to make a yes/no dropdown, and if not how do I change the size (width) of the inputbox text?
require 'sketchup.rb' module Convert_objects_randomly @base_entities = [] @target_entities = [] @convert_only_groupsinstances = true def Convert_objects_randomly.choosebase @base_entities = Sketchup.active_model.selection.to_a if @base_entities.empty? results = UI.messagebox "Please select base groups and/or components first." Sketchup.send_action "selectSelectionTool;" return end end def Convert_objects_randomly.choosetarget target_entities = Sketchup.active_model.selection.to_a if @base_entities.empty? results = UI.messagebox "Please select base groups and/or components first." Sketchup.send_action "selectSelectionTool;" return end if target_entities.empty? if @target_entities.empty? results = UI.messagebox "Please select target groups and/or components first." Sketchup.send_action "selectSelectionTool;" return end target_entities = @target_entities end target_entities.each do |current_entity| if current_entity.is_a?(Sketchup;;Group) current_entity = current_entity.to_component current_entity.definition = @base_entities[rand(@base_entities.length)].definition elsif current_entity.is_a?(Sketchup;;ComponentInstance) current_entity = current_entity.make_unique current_entity.definition = @base_entities[rand(@base_entities.length)].definition else current_entity = current_entity.add_group current_entity = current_entity.to_component current_entity.definition = @base_entities[rand(@base_entities.length)].definition end end @target_entities = target_entities Sketchup.active_model.commit_operation end def Convert_objects_randomly.settings if (@convert_only_groupsinstances == true) default = "yes" else default = "no" end settings_query1 = inputbox(["Convert only groups/components to base objects?"],[default],"Convert Objects Randomly Settings") if (settings_query1[0] == "yes") @convert_only_groupsinstances = true else @convert_only_groupsinstances = false end end end #Convert_objects_randomly module Convert_objects_randomly_menu = UI.menu("Plugins").add_submenu("Convert Objects Randomly") Convert_objects_randomly_menu.add_item("Select base objects") {Convert_objects_randomly.choosebase} Convert_objects_randomly_menu.add_item("Convert selected to random base objects") {Convert_objects_randomly.choosetarget} Convert_objects_randomly_menu.add_item("Settings") {Convert_objects_randomly.settings} file_loaded(__FILE__)
-
RE: Looking to make a script, but dunno how.
@chris fullmer said:
#3 - The @target_entities will hold its value until SketchUp is closed, after it is given a value once. So you should clear it after your script is run each time. Add a
@taget_entities = []
to the end of your script. That is my gess as to what is happening.Well, I know that it holds its value -- that was a way to re-randomize if the user wanted to without selecting those same groups again. But, if I set @target_entities to something else and it (@target_entities) is already set to something, that won't cause a leak, right? (the array it was previously set to will be cleared from memory?)
-
RE: Looking to make a script, but dunno how.
Thanks. I couldn't do it with "@module base_entities = '' "-- that gave me an error. I used " @base_entities = '' ". And looks like I need that " @base_entities ='' " or else something weird happens (maybe undefineds everywhere?) and the if statement for base_entities did not work. (it does now, of course)
So now I have to figure out how to iterate through target_entities and convert each to a random base_entities ..
There isn't a native function I could use?
Edit: Figured it out mostly... See post 1 below.
-
RE: Looking to make a script, but dunno how.
The first script is almost done. I have a few problems --
-
I could not find a way to convert groups to components so I changed them to unique components and then changed the definition of THOSE to the randomly selected base component. Isn't there a more efficient way?
-
I can't seem to convert the target groups to components fast enough -- I used 'if (current_entity.typename == "Group") // current_entity.to_component // end', but that only applies at the end of the script so I have to run it twice.. dunno how to make it convert instantly. Tried shoving "Sketchup.active_model.commit_operation" after and then converting the unique components to base components but it won't budge.
-
When I do "@target_entities = target_entities", and I already had a non-empty @target_entities, am I leaking?
-
(mini-gripe) The rand function is glitchy. Sometimes it gives several (3-4) repeats in a 90-size or so list, which has an incredibly low chance of occurring.
require 'sketchup.rb' module Convert_objects_randomly @base_entities = [] @target_entities = [] def Convert_objects_randomly.choosebase @base_entities = Sketchup.active_model.selection.to_a if @base_entities.empty? results = UI.messagebox "Please select base groups and/or components first." Sketchup.send_action "selectSelectionTool;" return end end def Convert_objects_randomly.choosetarget target_entities = Sketchup.active_model.selection.to_a if @base_entities.empty? results = UI.messagebox "Please select base groups and/or components first." Sketchup.send_action "selectSelectionTool;" return end if target_entities.empty? if @target_entities.empty? results = UI.messagebox "Please select target groups and/or components first." Sketchup.send_action "selectSelectionTool;" return end target_entities = @target_entities end target_entities.each do |current_entity| if (current_entity.typename == "Group") current_entity.to_component end end Sketchup.active_model.commit_operation target_entities.each do |current_entity| if (current_entity.typename == "Group") or (current_entity.typename == "ComponentInstance") current_entity.make_unique current_entity.definition = @base_entities[rand(@base_entities.length)].definition end end @target_entities = target_entities Sketchup.active_model.commit_operation end end #Convert_objects_randomly module Convert_objects_randomly_menu = UI.menu("Plugins").add_submenu("Convert Objects Randomly") Convert_objects_randomly_menu.add_item("Select base objects") {Convert_objects_randomly.choosebase} Convert_objects_randomly_menu.add_item("Convert selected to random base objects") {Convert_objects_randomly.choosetarget} file_loaded(__FILE__)
-
-
RE: Looking to make a script, but dunno how.
Either. Anyway, here's what I have now. I already have a problem I can't figure out-- I can't get both IF statements to work in the second def. It will skip the second if statement as of now... dunno why.
require 'sketchup.rb' module Convert_components_randomly def Convert_components_randomly.choosebase base_entities = Sketchup.active_model.selection if base_entities.empty? results = UI.messagebox "Please select base groups and/or components first." Sketchup.send_action "selectSelectionTool;" return end end def Convert_components_randomly.choosetarget target_entities = Sketchup.active_model.selection if target_entities.empty? results = UI.messagebox "Please select target groups and/or components first." Sketchup.send_action "selectSelectionTool;" return end if Convert_components_randomly.choosebase.base_entities.empty? results = UI.messagebox "Please select base groups and/or components first." Sketchup.send_action "selectSelectionTool;" return end end end #Convert_components_randomly module convert_components_randomly_menu = UI.menu("Plugins").add_submenu("Convert Components Randomly") convert_components_randomly_menu.add_item("Select base components") {Convert_components_randomly.choosebase} convert_components_randomly_menu.add_item("Select components to convert") {Convert_components_randomly.choosetarget}
-
Looking to make a script, but dunno how.
I want to make two scripts. In one script you would be able to select a series of components and add it to the memory of the script. Then you would be able to select another bunch of components and the script would convert each component to the ones in the memory, randomly and evenly distributed per component-in-memory.
The second script would be similar except I would be adding to memory colors and randomly replacing colors (of a set of groups or components) instead of replacing component geometry.
I have no idea what the commands for this would be.
I'm looking for commands that would let me do pretty much all of this... I looked at
http://code.google.com/apis/sketchup/docs/index.html and really I'm quite lost as to which commands to use. -
RE: Rocky outcrop -- best method?
@massimo said:
You can try this, agamemnus.
Actually had that already. I don't need an icosahedron, I need something like an icosahedron... just way more sides.
I tried expanding the icosahedron by using the Catmull-Clark subdivide, but again the problems with the faces not all being front faces. It also created geometry inside, and at the second iteration it started making grooves. (even after I manually removed the geometry)
-
RE: Rocky outcrop -- best method?
Thanks. That helps... but:
*When I used Catmull-Clark, it left the original mesh and it made a new mesh that had spotted parts -- back faces mixed with front faces. How can I easily and quickly set them all to front faces? (there's nothing inside or intersecting.... it's all one mesh... I thinks)
- I started with a circle with 48 sides and made that into a sphere before starting to deform and shape it, but I was hoping for a polygonal solution (like an icosahedron except more triangles).. any idea where I can get a tool that makes these kinds of spheres?
-
Rocky outcrop -- best method?
I'd like to make a rock that's flat at the bottom and has high-ish and low-ish some protruding curves on the top. Then I want to add in various deposits of sparkly crystal/gem-like things on the outcrop.
I'd like to make a few versions of this (6), varying by size.
I have no idea how to (easily) make the mesh for the rock. I did try the "sculpt" tools but they were extremely slow and I couldn't get anything nice. =(
Help!
-
RE: SketchyPhysics Rendering: Toy Car Crash
Logs, logs everywhere! Nice animation!
-
RE: Random tip: A stack of logs without obvious repetition
@fletch said:
here's the 'final' where I used the logs. thanks again Miguel!
Wow, that looks fun. What are you using it for?
-
RE: Removing unrendered objects
Al, that will also select things I can't see. It will also select pieces in complete groups that I can't see.
xrok1.. I dunno, just imagine a model, any model. Imagine I am looking at the model from some angle, any angle. Imagine I don't see the entire model because I'm looking at a closeup. I want to remove the parts of the model that I don't see.