Observer triggers and validation methods
-
Hi there,
I am fairly new to ruby (and this forum) and am trying to get a 3dconnexion-3dmouse to rotate selected objects.
I thought it would be a good idea to capture the view-changes and redirect it to object(s).
That would make the code generic for all input devices.In my attempts I found some restrictions where you pro's may have some solutions for:
Question 1:
The observers are triggered after the change event.
so, Viewobserver.onViewChanged passes a modified view. In fact, the screen seems also already refreshed!
So, I can get the Camera.eye, .target and .up values to set the drawingobject's transformations,
and, I can create a new Camera object to reset the view to it's original, but it will
show a 'glitch' on screen.What raises the following questions:
Are there a tricks to create:
a- Observer.BeforeViewChanged as opposed to Observer.AfterViewChanged although it (wrongly) is called Observer.OnViewChanged
So that one can do; def Observer.BeforeViewChanged(oProposedNewView) if oProposedNewView.Camera.eye.x > @nTheValueThatIreallyLike return oProposedNewView else return @oAdifferentViewThatILikeMuchBetter end end
-or-
b- View.freeze or View.Lock or View.Lockstate, something to disable and enable the screen-refresh?
-or-
c- Acces- and Assign methods? so that one can create constructions as:
Camera.eye.assign(oNewsetting) Camera.eye = oNewsetting ; if oNewsetting.x > @nTheValueThatIreallyLike end
-or/and-
Camera.eye.access(oNewsetting) Camera.eye.x = @nThexthatIreallylike return Camera.eye end
Hmmm, Maybe a lot of questions for a first post...
Regards,
Reind
-
The answers are easy and the same for all of your questions.
1) It is a big NO-NO to change the API classes. We have begun a Quarantine List for any plugin that does this and is released. (A nice name for a "dog poop" list.)
2) You or WE cannot create new observer callbacks, because they are called from the C++ side of the SketchUp engine, which only the Trimble Dev. Team can change. You would need to log an API Feature Request for any new observer callbacks. (I myself have logged several requests.)
-
Hmmm,
That is truly a limitation then.
yet, is there a way to prohibit SU to redraw the screen?
Like setting a refresh rate to very long, or simply a camera.freeze method?
I read there is a view.invalidate, but what about a view.do_Nothing_While_I_Sort_things_Out?Cheers,
and thannks for fast reply last time,Reind
-
@reind brackman said:
Like setting a refresh rate to very long, or simply a camera.freeze method?
I read there is aview.invalidate
, but what about a view.do_Nothing_While_I_Sort_things_Out?You use an undo operation, and set the
disable_ui
flag totrue
module Brackman def self.do_op( opname, disable_ui=true, model=Sketchup.active_model ) raise( ArgumentError, "no block given", caller ) unless block_given? model.start_operation( opname, disable_ui ) result = yield( model ) # call the block passing in the model ref model.commit_operation() rescue Exception => e UI.messagebox("Error in #{opname} operation;\n#{e.class.name}; #{e.message}\n") model.abort_operation() return e # return the Exception object else # no errors occurred so return result of the block return result end end # module Brackman
Then call it from one of your sub-modules like:
module Brackman module Rotate3D # plugin sub-module ;;Brackman.do_op('Rotate Object') {|model| sel = model.selection obj = sel[0] # apply a rotational Geom;;Transformation # to the object ref'd by obj HERE } end # module Rotate3D end # module Brackman
-
Thanks Dan,
Your example hints me to improve some other code parts (moving objects from external program).
But unfortunatly it wont help me with what I wanted to achieve, what is to get a 3dconnexion-mouse to rotate objects.
Basically I wanted to retrieve camerea.eye (pan and tilt) with a ViewObserver, then use the .eye data to rotate an object and return the model back as if no pan and tilt occurred in the first place without glitches.
It probably is better to get the SDK of the mouse to retrieve it's data and send it via SKSocket.Still, it would be a good idea to have a bit more freedom in the Observers, validation methods and/or control to the screen output.
Cheers,
Reind
-
The
SkSocket
class has never been reliable. It was always kinda of beta. This is why it is not listed in the API dictionary. (It might be removed in future versions.)Doesn't the native Rotate tool work with your 3DMouse ??
-
The SKSocket not reliable???????
You must be joking... I use this for years (Early SU6!) to send data to Sketchup for visualising machine motions between one application and another.
Just 3 simple commands make me run SU from other application and it works as a charm.
SKSocket.connect("localhost",5088)
SKSocket.add_socket_listener {|e| eval e}
SKSocket.write(@m_outp)
Ideal for automation projects.
If they abandon that they better come with a good way to run SU from another platform.Are you serious they want to abandon that? If so, who should I call?
Reind,
-
Oops, pushed submit too fast.
I got the 3dconnexionmouse working with their dll in VFP9 (Visual foxpro, don't ask me why except that i love that language) who in turn is sending - yes... via SKSocket - the values to Ruby-world, turning objects around.
So yes, it is working.
Now I like to learn how to set up COM events binding within ruby scripts. As I explained, ruby is new to me, but I start to love that language....Cheers.
R.
Advertisement