Help me solve a mystery
-
A new clue in the mystery. If the components exist before the plugin is executed, it runs without a problem. So it is something regarding the initial creation of the components in the plugin that apparently doesn't occur when the Ruby Web Console script is executed.
-
if you simply wrap it as a string [ in the .rb file with eval ] and load that, does it work?
i.e
eval %Q(# you original code here)
also, if you post the code it's easier to test...
john
-
I would not trust my old Ruby Web Console plugin. There were name-space issues if I remember correctly.
One simple way to write and test code in SketchUp is to use your favorite editor. Then create a menu or tool button in SketchUp to load the file you are editing. The advantge of a menu is that you can create a shortcut to reload the file. It's a simple, fast, and effective workflow.
-
Apparently the only mystery is why creating components "on the fly" is only partially successful at best.
-
I could think of 2 things related to those errors. You are referencing face.normal in the add instance method. BUT using pushpull on the face after referencing to a variable may delete the original face/faceID or reference what you may call it.
Also maybe using load definitions from paths might bring more succes than add ?
-
Jolran is correct.
When you usef.pushpull()
the original face is lost.
So when you later try to use a reference to that face 'f
' it is a 'deleted-entity' - raising an error...
But since your container's entities only has the one face with that normal you can re-find the face if needed - or just set a reference to the normal [say asn=f.normal
] BEFORE doing the pushpull that deletes the face... -
In this case, I don't attempt to reference the face later. Also, if the plugin doesn't have to create the components, it ran normally.
I tried creating a group for each "box" then group.to_component. This was a better but still unreliable.
I eventually ended up just adding the "boxes" to a single group rather than making components at all. This then created another problem which was resolved in the test plugin by doing nothing more than simply moving the .add_group statement. I can't imagine why that should make a difference.
The good news is that all the gremlins have been eliminated and all is right with the world.
-
The old webconsole may have done some initializing of local varibales that your method does not have.
Such as:
model = Sketchup::active_model defns = model.definitions selset = model.selection
etc.
Look at the code for the webconsole.
-
@sdmitch said:
In this case, I don't attempt to reference the face later.
Yes you did.. you tried to create a transform using
f.normal
so that method would likely returnnil
or raise an exception.Or the
add_instance
method would returnnil
making theci
referencenil
.Obviously you expect a valid instance or group when you use the
explode
method, but the reference (that you are callingexplode
upon,) is referencingnil
.Learn to write nil tests / valid test into your code to catch these errors, ie:
ci.explode if ci
-
Is this editor will have the same behavior?
SketchUp Ruby Code Editor • [as]
This code editor extension offers an easy-to-use and visually appealing way to write and modify Ruby scripts directly within SketchUp. These scripts can then be used to create geometry, add functionality or add data within the SketchUp 3D modeling environment. The SketchUp Ruby API provides an extensive set of functions to automatize SketchUp in many ways or create scripted, computational geometry.
[as] (www.alexschreyer.net)
the author said it was based on the Ruby Web Console
Advertisement