Align points
-
Hi all!
I'm trying to make a align script for points. I think it could be useful to correct none planar lines and more...
It works fine for lines but with faces it makes them triangulated (by autofold) since it moves each point individually.
Since I'm a noob to ruby I now need help figuring out how to auto delete all the edges created by autofold.Here's what I've tried. But doesn't work:
class AutofoldWatch < Sketchup;;EntitiesObserver def onElementAdded(element) autofoldEdges = []; ### Gather all new edges in an array if element.typename == "Edge" and element.valid? autofoldEdges.push(element) end#if return autofoldEdges; end#def end
And just before the action happens:
Sketchup.active_model.entities.add_observer(AutofoldWatch.new) ###Observer added
And last in the script I'm trying to remove the new edges in the "autofoldEdges" array:
autofoldEdges.erase! ###Erase edges created by autofold Sketchup.active_model.entities.remove_observer AutofoldWatch ###Observer removed
-
Hi Pixero, nice to see you here.
A bit hijacking. Check your layout script JS Sketch 01. It seems you copie the Sketchy pencil Scribble.style to made it.
Try out your script for an object and then toggle to Sketchy Pencil Scribble. There are no changes. You have to copie it first in the Style Browser then make the changes for a new style. Otherwise the update can go wrong.I'm in again. I'll give align points a go....if you say it's okay !
regards Burkhard
-
Pixero,
When you add the observer, assign it to a variable, like this:
$af=Sketchup.active_model.entities.add_observer(AutofoldWatch.new) ###Observer addedThen, when you want to delete the observer, use
Sketchup.active_model.entities.remove_observer $af ###Observer removed
The reason is, right now the code tries to remove a class, rather than removing an instance of that class. That doesn't work
Hope that helps...
-
Again my call (as made in various other threads in the old forum): DO NOT USE GLOBAL VARIABLES if not really really necessary. (global variables begin with a $ in Ruby). You are NOT secure, that these variables aren't used by another script that could destroy your context / scope. Put the observer handling to setup and teardown methods within a/your class and save the observer within the class in an instance variable (instance variables begin with ONE Censored to protect your privacy in Ruby).
azuby
-
Thanks Azuby, I didnt know that. But I am a noob on Ruby.
I've never seen it in the ruby docs though. Since I've seen both @ and $ used, I assumed you could use either.
In my noobiness I though the @ came from @-atlast.Rick W, thanks I tried it but it still doesnt work. Could you please take a look at my script to see where I go wrong?
Maybe try my script with a rectangle and set Align to custom and some custom value.
Advertisement