Request: Automatically add ConstructionPoint at Center of Ci
-
John,
Yes, this can be done. I'll see if I can come up with something.
-
I should have said, "Yes, theoretically, it can be done."
Reality is BugSplatting
Conversing with the SU crew about the issue... -
In principle you'd have some 'observer' auto-made in each model that's watching for new geometry to be added. If it forms an arc or circle a simple script adds a centre point ?
-
Isn't is possible to observer the Circle Tool itself? Or subclassing the Circle Tool?
azuby
-
@azuby said:
Isn't is possible to observer the Circle Tool itself? Or subclassing the Circle Tool?
azuby
I don't think you can observe a Tool. You can observer the Tools class.
But, I think by using both a ToolsObserver and a ModelObserver, you can get to where you want to be.
-
Oh, you have to differentiate between "collection of tools" and "class of Tools"
The class of Tools is Class, Tools itself is a class. What you mean is the collection of one tool and one more tool -> tools (not Tools). I do mention that, because we are in the Ruby forum and Ruby programmers would come in semantic conflict by the words.
This is, what the spec says: "The Tools class contains methods to manipulate a collection of SketchUp tools." - that means a collection of - hm - circle tool, square tool etc. This classs do provide an add_observer method, so that you can register an object to a collection of tools, which gets notified of changes in the collection.
Your are right, there does not seem to be a way of registering an observer to a Tool object. Also subclassing the circle tool does not seem possible, because I can't reach the circle Tool object.
Maybe there is a way adding a Tools observer to the tools collection where the circle tool is in.
azuby
-
In my example, you would need a 3rd observer - EntitiesObserver - to get the entities to add the center point to.
The following attachment adds these 3 observers and outputs debugging info to the Ruby Console.
-
At jim & TIG
Not strictly on topic, but I'm trying to figure out how to write observers for a script of my own. I can't seem to find any kind of observer documentation anywhere; is there such thing as a formal observer? Jim's example above seems to indicate there is, and is the closest example I've got so far. So; how would I write a camera observer that calls a specific function every time the camera is moved (manually or by another tool/script)? Would that be something like "class CameraObserver < Sketchup::ModelObserver" with some camera specifc code thrown in?
I also need a Tools observer; how do I activate a constraint for each drawing tool based on (3Dpoint) information from the first click? Would that work better as a tool observer or a onLButtonDown action? I want something fairly efficient for this one; I don't expect the camera to be moving much for this plugin so I'd rather tie this to tools or clicks than to the camera.
Any suggestions, code, or links to observer documentation
Censored to protect your privacy Rick - I'm trying to use this for the 2D idea; any ideas or suggestions on how to best implement this?
[birchins]
-
I usually draw the circle using the Circle Tool first and then use "Get Midpoint" because I have "midpoint.rb".
[Invader ZIM]
-
You want to create a view observer (not a camera observer, since those don't exist). The general form is:
- create the observer, deriving from the appropriate template
- attach the observer to the appropriate object
In your case, this would take the form of
class MyViewObserver < Sketchup;;ViewObserver def onViewChanged(view) # do stuff here end end $myViewObserver = Sketchup.active_model.active_entities.add_observer(MyViewObserver.new) #assigning to a global variable is optional, but allows you to remove the observer later #you could also create a class variable to store the various instances, or there are other possibilities as well
Hope that helps...
-
The Tools observer has some problems - "toolname" is truncated on the Mac, making it hard (or impossible) to get the active tool based on name. However, the toolid works fine.
class MyToolsObserver < Sketchup;;ToolsObserver def onActiveToolChanged(tools,toolname,toolid) #do stuff here puts "Selected tool; #{toolid} ;; #{toolname}" end end Sketchup.active_model.tools.add_observer(MyToolsObserver.new)
That said, to constrain drawing to a 2D plane will probably require recreating all the tools with the constraints built in.
Advertisement