Its very useful for making games in SU.
You can use it in sketchy physics for windows...
Posts
-
RE: [plugin] Updated (Dec. 30, 2011) hook Procedure
-
RE: [Plugin] Center of Gravity
@stefanka said:
Hello TIG!
Thanks for this logic answers.... I haven't see that I can change the units of density...
i'm so stupid.... I have loose a day to find how it works!!
Thanks for your job!!
Just a think, I have installed sketchyphysic 3.2 to try to find something for de CofG... and to move my model (it was a spécial door for boat)..
But when Sketchyphysic was installed, your plugin CofG run correctly, but not the composite... when i run it, nothing happend... I have unistalled Sketchyphysic, and it works...
Thats strange!Other think, my door is arround 25 group in an other group. when I run CofG, the résult was really haevy (arround 320kg) and the center of gravity looks wrong, and when a run CofG for each group, and i Composite after, i looks like better. (117 kg thats reallist)
Center of gravity looks better too.All groups are in the same matérial Steel arround 7800kg/cu.m
I dont understand why?
Thanks for your answers.!
Best reggards
StefSketchy Physics doesn't uses center of mass/gravity. It just uses the bounds center
-
RE: [Plugin] Center of Gravity
Very, very good plugin!!!
I can't even think how to calculate that kind of stuff, that's just pro.
-
[plugin] Updated (Dec. 30, 2011) hook Procedure
First, if you have downloaded HookProc plugin, then delete MSPhysics folder, myInputProc.rb file, and rbconfig.rb - if its version is higher, than sketchup's ruby core version.
Mouse and Keyboard Input Procedure
Introduction:
Input Procedure allows the user to monitor and make decistions for mouse and keyboard input messages that are sent to sketchup thread. For instance, lets say you want to write a plugin that would use key 'a' to do some task.You can do that by getting input in onKeyDown method. Though there is one thing: Key 'a' is a shortcut key to an arc tool - when you press key 'a' your tool deactivates, and the arc tool activates. How can you make it so that key 'a' doesn't interfere with arc tool? - Well there are two answers I know of:1st Answer: Go to shortcuts menu and remove key 'a' from being a shortcut to some tool.
2nd Answer: Use hook procedure, simple as I know of.1st answer is not good! If you wanted to set shortcuts back, you would have take some time for doing that, and if you wanted to upload a plugin to internet, so that others could use, before activating your plugin they would also have to remove shortcuts, and after deactivating, set tool shortcuts back. I think that's just a waste of time and no one would want to do that, so cross the first answer off and we're left with 2nd.
So anyways, what is Hook Procedure?
"A hook is a point in the system message-handling mechanism where an application can install a subroutine to monitor the message traffic in the system and process certain types of messages before they reach the target window procedure."Its not only capable of monetering messages, its also capable to prevent them to be sent to the window procedure, and this is what we wan't! We could prevent key 'a' from intefering with sketchup window, and still get its input.
Usage:
The usage is a bit similar to sketchup tool.
First, you'll need to write a class. The class should have some or all of the following methods:` onKeyboardInput(key_number, key, state)`key_number - a virtual key code to the virtual key
key - virtual key
state - the state of the key:0 - on key down
1 - key is down
(-1) - on key up
The return value should be:0 - let the message interfere with sketchup - process the message
1 - prevent the message from intefering with sketchup
Reference to virtual key codes: http://msdn.microsoft.com/en-us/library/dd375731(v=vs.85.aspx
The assigned virtual keys are in the VirtualKeyCodes.rb file.` onMouseInput(msg_number, msg, x, y)`msg_number - the number to the constant of the message
msg - the message
x, y - real cursor position
The return value should be:0 - process the message
1 - prevent the message from intefering with sketchup
Reference to mouse messages: http://msdn.microsoft.com/en-us/library/windows/desktop/ms645533(v=vs.85.aspx
The assigned message names are in the mouse input.rb file` onMouseWheelRotation(d, x, y)`d - rotation direction: 1 - forward, (-1) - backward
x, y - real cursor position
The return value should be:0 - process the message
1 - prevent the message from intefering with sketchupExample:
` require "MSPhysics/InputProc.rb"class MyInputTool
def initialize()
enddef onKeyboardInput(key_number, key, state)puts "OnKeyboardInput: key_number #{key_number}, key #{key}, state #{state}"
1 #remove the message
enddef onMouseInput(msg_number, msg, x, y)puts "OnMouseInput: msg_number #{msg_number}, msg #{msg}, cursor position (#{x}, #{y})"
0 #process the message
enddef onMouseWheelRotation(d, x, y)puts "OnMouseWheelRotate: direction #{d}, cursor position (#{x}, #{y})"
1 #remove the message
end
end$myInputTool = MyInputTool.new`
To hook the instance of the class we first need to select the hook, similar to selecting the tool:MSPhysics::InputProc.select_hook($myInputTool)Now, to hook it (Or turn it on):
` MSPhysics::InputProc.hook(input function name(s))` You can hook one or multiple of procedures in one time. Example: ` MSPhysics::InputProc.hook("onMouseInput")` or/and multiple procedures ` MSPhysics::InputProc.hook("onMouseInput", "onKeyboardInput", "onMouseWheelRotation")` You don't have to write them exactly the same, you can make it lowercased or capitalized and whatever... Ex: ("ONKeyboardinput", "onmousewheelrotation") You can also hook all: The function will automatically find the hook input methods that are in your instance class and hook them. ` MSPhysics::InputProc.hook_all()`Now, to unhook it (Or turn it off):
` MSPhysics::InputProc.unhook(input function name(s)) MSPhysics::InputProc.unhook_all()` or ` MSPhysics::InputProc.select_hook(nil or other tool)` When you select a different hook or nil, it will automatically unhook all and then select a different tool. If you select the same tool, it will just return, so don't get bothered by selecting it multiple times.You can also hook the procedures, that are already hooked. It will just return, so don't get bothered by hooking same procedures multiple times.
The same thing is with the unhook, hook_all, and unhook_all.
The errors and other stuff will be reported to the Ruby ConsoleTo get the status of procedures, call the method status:
MSPhysics::InputProc.status()
It will return the hash of all three input proceduers with their status. (true - on, false - off)If it finds an error in your script, it will report it in the Ruby Console and unhook the procedure in which the error occured.
You can toggle between hooking and unhooking messages as many times as want to.The example is in the InputProcExample.rb file.
Sketchup Version:
Tested and works in SU7 and SU8Operating System:
Windows - XP/Vista/7Footprint: (Edited)
InputProcExample.rb
MSPhysics/%(#0000FF)[core.rb InputProc.rb InputProc Readme.rtf mouse input.rb VirtualKeyCodes.rb] %(#FF0000)[win32/]%(#00FF00)[version 1.4.8 - [http://rubygems.org/gems/win32-api](http://rubygems.org/gems/win32-api)]ruby18/
api.so
ruby19/api.so
api.rbRequirements: (Edited)
none
Edit: This Post is old and outdated. If you're interested in implementing Hook Procedure into your tool, use AMS Library.
-
RE: Cursor Position To November92
NewtonServer is a dll library to newton physics stuff
-
RE: Getting cursor position while SP simulation is running.
To get all module methods:
MSketchyPhysics3.methods MSketchyPhysics3.private_methods MSketchyPhysics3.instance_methods MSketchyPhysics3.private_instance_methodsYou can examine the sketchy physics files to see those methods and here is the source to module: http://www.ruby-doc.org/core-1.9.3/Module.html
-
RE: Getting cursor position while SP simulation is running.
No, you can't.
view.center, andview.corner[n]also returns cursor position relative to view. If I would writeview.corner(0)(the upper left corner), it would always return [0,0], so the function is kind of not useful...Well, though, there is probably another way
Using win32-api to locate sketchup view and get its position. It will only work on windows and for mac ox x, I would have to use its library. And yeah I, still don't have good knowledge of win32-api functions, so it'ill most likely take a while before there would actually be a good script. Plus rightnow I only peaked at mac os x library, so yeah, need time to benefit the script... -
RE: HookProc
First of all, I'm also russian, you can write the post in russian and in english (if want to)and i'll reply in two languages.
So, what you wanted was to get hotkeys input?
- The actual plugin hookproc can't get hotkeys (key-combinations) input, though there should be a way to get it. I'll do some research on it... and then write a plugin for that.
-
RE: Getting cursor position while SP simulation is running.
@mrdailyblah said:
i thought u can just use MSketchyPhysics3::getCursor(), and put an array number thingy after it?
> curpos=MSketchyPhysics3;;getCursor() > mousex=curpos[0] #get x coordinate > mousey=curpos[1] #get y coordinate >MSketchyPhysics3::getCursor()returns cursor position relative to the whole screen, but the other one in sketchup tool, return cursor position relative to view. In most sketchup plugins, we need cursor position relative to view, not relative to screen. -
RE: HookProc
Ah, well okay, its for windows operating system then...
Thanks for checking

-
RE: HookProc
@unknownuser said:
i would check for you on mac but to be honest, i'm not even sure what it's supposed to do

Yes, from reading my own post, I need to explain things better...
Let's say you're creating a plugin and you want the plugin to do some task when press key 'a'. You can do that by getting input in onKeyDown method. Though there is one thing: Key 'a' is a shortcut key to an arc tool - when you press key 'a' your tool deactivates, and the arc tool activates. But, how can you make it so that key 'a' doesn't interfere with arc tool? - Well there are two answers I know of:
1st Answer: Go to shortcuts menu and remove key 'a' from being a shortcut to some tool.
2nd Answer: Use hook procedure, simple as I know of.
1st answer is not good. If you wanted to set shortcuts back, you would have take some time for doing that, and if you wanted to upload a plugin to internet, so that others could use, before activating your plugin they would also have to remove shortcuts, and after activating, set tool shortcuts back. I think that's just a waist of time and no one would want to do that, so cross the first answer off and we're left with 2nd.
So anyways, what is Hook Procedure?
"A hook is a point in the system message-handling mechanism where an application can install a subroutine to monitor the message traffic in the system and process certain types of messages before they reach the target window procedure."The hook is not only capable of monetering keyboard messages, it's also capable of monetering mouse messages, which include the MouseWheel. Not only that, it's not only capable of monitoring messages, it is also capable to prevent messages from being sent to window procedure. And this is what we want. We could prevent key 'a' from being proccesed, and still get the input of it.
How we do that? (Or how we use hook procedure)
First off all here is a link to hooks: [Hooks](http://msdn.microsoft.com/en-us/library/ms632589(v)
We would need to initiate a function [SetWindowsHookEx](http://msdn.microsoft.com/en-us/library/ms644990(v), using win32-api and windows-api:
API.new('SetWindowsHookEx', 'IKII', 'I', 'User32')Since, we wan't to monitor and process key 'a' message, we could use WH_KEYBOARD or [KeyboardProc](http://msdn.microsoft.com/en-us/library/ms644984(v). To do that we first need to create callback function. Since Win32API is not a good liblrary and is not capable to create calback functions, I decided to use win32-api. So here is the callback:
@keyboard_proc = Win32::API::Callback.new('ILI', 'I'){|code, wParam, lParam| #my script 0 #Return value: 0 - process the message, where 1 is to remove the message. }This is a simple look at keyboard procedure, though the hook sometimes requires the keyboard proc callback function to call [CallNextHookEx](http://msdn.microsoft.com/en-us/library/ms644974(v). The details on how and when the hookproc should be called is in the "return value" section of the KeyboardProc. Note if you want to understand it, read it slowly, it confused me a bunch of times. By following all the rules of that, the callback should look like that.
@keyboard_proc=Win32::API::Callback.new("ILI", 'I'){|nCode, wParam, lParam| #my script return_val = some value 0 or 1
Following the instructions:If nCode is less than zero, then the callback should call CallNextHookEx and return the value returned by CallNextHookEx.
If return_val is 1 or any other value, but not zero, then the callback should call CallNextHookEx and return the return_val value.
If return_val is 0 then, don't have to call CallNextHookEx.
By following the instrcutions, it would look like this:
CallNextHookEx.call(@hooks["keyboard"], nCode, wParam, lParam) if (return_val==1 and nCode>=0) if nCode<0 then CallNextHookEx.call(nil, nCode, wParam, lParam) else return_val end }Before we set hook, we need first know what to set the hook to. To the module handle or to the Thread. Setting a hook to module or global handle, will monitor and process messages that are to be sent to all window proceduers. Setting a hook to certain thread, will monitor and proceess messages sent to the current window procedure. We need to set it sketchup window.
To get a thread id of sketchup, we have to call many other functions, getting some kind of data that matches it. Since, when we activate our plugins we are in the sketchup window, we can call the function GetCurrentThreadId, without writing extra script that would find sletchup thread id.
ThreadID = GetCurrentThreadId.callNow since we have it we, can hook the function:
@hHook = SetWindowsHookEx.call(WH_KEYBOARD or 2, @keyboard_proc, 0, ThreadId)
The hook now calls@keyboard_proc, whenever there's a keyboard message is sent to sketchup window.Okay, we have this working, but how to set it back?
Well that's a job for function [UnhookWindowsHookEx](http://msdn.microsoft.com/en-us/library/ms644993(v).UnhookWindowsHookEx.call(@hHook)To get module handle, you would want to call [GetModuleHandle](http://msdn.microsoft.com/en-us/library/ms683199(v).
HMod = GetModuleHandle.callHook it:
@hHook = SetWindowsHookEx.call(WH_KEYBOARD or 2, @keyboard_proc, HMod, 0)And unhook when need to:
UnhookWindowsHookEx.call(@hHook)Though, not all hook callback functions are supported in being set to thread or global scope. In Remarks section of SetWindowsHookEx, scroll a bit down and there'll be a table of all hooks that show the scope they can be in or should be set to.
To get information about the mouse messages you could use MouseProc or/and LowLevelMouseProc. Hook also provides some more callback functions that could monitor mouse messages, but they can't make a decision for it. They can't state however the message to be processed. In other words, they can't prevent the message from being sent to the thread and the global scope.
MouseProc can give the mouse all mouse messages and data the user needs, expect the mouse-wheel rotation direction data. On theother hand, LowLevelMouseProc can give all mouse messages, including the mouse wheel rotation direction, but it cannot be set to thread. It can only be set to global. So if want to monitor and process the whole data of mouse messages, you should use two functions.
Now the Plugin:
The plugin consists of HookProc.rb (main), core.rb (My library), VirtualKeyCodes.rb, Mouse Input.rb (the constant names assigned to the mouse messages), Keyboard Input.rb (Also Constant names), and MyInputProcedure, a simple example to the HookProc usage.
The example plugin is myInputProcedure.rb file
MyInputProcedure.rb should automatically create sketchup text and write messages to it, whenever the user presses/holds down/releases keys or mouse button or rotates mousewheel, depending on menu item the user has selected. The example removes KeyboardProc, LowLelelKeyboardProc, and mouseProc messages. Where LowLevelMouseProc is set to process the mouse messages. If the LowLevelMouseProc would remove all mouse messages it receives, then it would act like the mouse is off.
USing the MyInputProcedure Example Plugin is simple. Toggle bettween the items you want. To set hook, select the menu item once. To unhook, select again or select "unhook all" menu item in "MyInputProcedure" submenu.
Note this plugin is not really useful. You can't define method initiate in ur class. If you would then it would remove the data stored in previous HookProc initiate method. I will update it, so that it would work a bit similar to Sketchup Tool and so it'll be useful.
-
RE: Set/Get Attribute
@dan rathbun said:
Not in the global Objectspace, no...
... all your code should be inside your unique toplevel module, and all your classes should be inside that as well.
Okay, that's what I thought. It was just the wrong use of variables, and people who were learning ruby from sketchy physcics scripts did the same thing, so now I know, Thanks

-
RE: HookProc
Does it works alright on Windows 7, and other windows platforms?
And
Can anyone please check if it works on mac or linux>?
I need some feedback here

-
RE: Set/Get Attribute
@thomthom said:
@anton_s said:
So, its the right way to use
@kind of variables in Attribute Dictionary?They are not related in any way. Maybe it would be best if you described what you are trying to achieve?
It's the scripts that confuse me in sketchy physics 'onTick' or 'scripted' fields.
Examining someones script, like Mr.k's or Wacov's, I usualy find instance variables that are not assigned and used in the class, but are writen outside of class, like local or global variables. The example is in my first post. I want to know if it is the right way to write scripts like they did, using instance variables as the variables. -
RE: Set/Get Attribute
So, its the right way to use
@kind of variables in Attribute Dictionary? -
Set/Get Attribute
Attributes acts like a file for each model.
When we call
eval(some attribute), it is similar to taskload(file).
Am I thinking right?**If do then:**I was disturbed or in better words got stuck by the idea of how scripts are writen in sketchy physics. The thing that disturbed me was the miss-use of variables:
` onstart{
@things = []
@count = 0
@hello = 10def getEntByName(name)
...
end
}`Creating instance varibales outside of class doesn't report errors, but they just act like global variables. For instance: I assign instance varible
@count = 10, outside of class, in some attribure and eval the attribute. Then I set_attribute@countfor another model and eval it too. The evaluation of second attribute would return me "10", but not the error that I expected. I don't understand how attributes work. If I eval it, does it even becomes defined in the plugin files? I need some explanation on that, I'm stuck. -
HookProc
Did you ever wanted to make a sketchup plugin that would use keyboard and mouse devices, without letting sketchup shortcuts interferring with it?
Well [Hook Procedure](http://msdn.microsoft.com/en-us/library/ms632589(v), is that powerful to do that.

The plugin allows the user to monitor, make decision, and run the script within the keyboard or/and mouse message activation.
It is provided with [KeyboardProc](http://msdn.microsoft.com/en-us/library/ms644984(v), [MouseProc](http://msdn.microsoft.com/en-us/library/ms644988(v), [LowLevelKeyboardProc](http://msdn.microsoft.com/en-us/library/ms644985(v), and with [LowLevelMouseProc](http://msdn.microsoft.com/en-us/library/ms644986(v) hook procedures. Supported with windows virual-key-codes, and mouse and keyboard input notification constants. Uses win32-api, windows-api, forwardable.rb, and rbconfig.rb. Though my rbconfig.rb CONFIG Hash is filled with Windows XP information. If you use different platform then, use your own rbconfig that is in ruby library folder.
The plugin is writen and tested in Windows XP operating system. Works in Sketchup 7 and SU 8.
Usage and example is in file myInputProc.rb.Note: In later time I'll probably add linux and mac virtual key codes, but for now its only supported with windows. I don't even know if this plugin would work on mac and linux operating system, so reply on how it works on yours.

-
Linux and Mac Virtual Key Codes
I have microsoft windows virtual key codes, but don't where to find linux and mac virtual key codes. Or do they even have those?