sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    [Plugin] AMS Library 3.7.1b (29 May 2021)

    Scheduled Pinned Locked Moved Plugins
    107 Posts 38 Posters 615.5k Views 38 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • W Offline
      wikii
      last edited by

      @anton_s said:

      Description

      AMS Library is a collection of tools and functions used to interact with SketchUp window and its sub-windows using Microsoft Windows API. It's capable to switch SketchUp full screen, show/hide toolbar containers, status bar, scenes bar, and more elements of the window. It's also capable to observe and make decisions to various events of the window procedure. In many ways, this library is written to achieve things that cannot be done with standard SketchUp API.

      This library includes Ruby FFI and and Win32 API extensions as part of the utility. Both of these gems are recompiled under my own name-space for compatibility with other extensions. I do not take ownership of such gems, nor I claim any credit for them. I just happen to rely on them so much that it was essential to include them in the library.

      Requirements

      • Microsoft Windows XP, Vista, 7, or 8
      • SketchUp 6 or later
        Usage

      Yardoc Documentation

      Download

      • Available at PluginStore
      • ams_Lib_2.2.0.zip
        Extract content into the Plugins folder!

      It is a great lib!

      one question:

      when i use swo_on_maximize ,like this
      class MySketchupObserver
      def swo_on_maximize
      r=AMS::C.get_viewport_rect()
      p r
      end
      end
      AMS::Sketchup.add_observer($o=MySketchupObserver.new)

      I found get_viewport_rect returns the value of viewport before maximized.

      So, can you provide a method like swo_on_maximized, will be called when maximize complete?

      thank you for the great lib!

      wikii

      1 Reply Last reply Reply Quote 0
      • A Offline
        Anton_S
        last edited by

        That's a good idea. I will add swo_on_post_[event] methods in the upcoming version.

        1 Reply Last reply Reply Quote 0
        • A Offline
          Anton_S
          last edited by

          Hi Wikii. I added the post-events.
          You should try out this example in Ruby console:

          class MySUWindowObserver
            def swo_on_maximize
              puts 'swo_on_maximize'
              p AMS;;Sketchup.get_viewport_rect()
            end
          
            def swo_on_post_maximize
              puts 'swo_on_post_maximize'
              p AMS;;Sketchup.get_viewport_rect()
            end
          
          end # class MySUWindowObserver
          
          my_obs = MySUWindowObserver.new
          AMS;;Sketchup.add_observer(my_obs)
          

          AMS Library 3 ChangeLog: http://www.rubydoc.info/github/AntonSynytsia/AMS-Library/master/file/CHANGELOG.md

          1 Reply Last reply Reply Quote 0
          • W Offline
            wikii
            last edited by

            @anton_s said:

            Hi Wikii. I added the post-events.
            You should try out this example in Ruby console:

            class MySUWindowObserver
            >   def swo_on_maximize
            >     puts 'swo_on_maximize'
            >     p AMS;;Sketchup.get_viewport_rect()
            >   end
            > 
            >   def swo_on_post_maximize
            >     puts 'swo_on_post_maximize'
            >     p AMS;;Sketchup.get_viewport_rect()
            >   end
            > 
            > end # class MySUWindowObserver
            > 
            > my_obs = MySUWindowObserver.new
            > AMS;;Sketchup.add_observer(my_obs)
            

            AMS Library 3 ChangeLog: http://www.rubydoc.info/github/AntonSynytsia/AMS-Library/master/file/CHANGELOG.md

            Hi Anton_S !

            It works well in my pc.
            It is really cool!

            Thank you for your working.

            But I have one question more:

            When I use win+left or win+right to fill Sketchup to half the size of the screen, which observer call catch this operation?

            Thank you!

            wikii

            1 Reply Last reply Reply Quote 0
            • A Offline
              Anton_S
              last edited by

              Currently, no observer catches such operation, but if you want to track window moving and resizing, you can always use swo_on_enter_size_move, swo_on_size_move, swo_on_exit_size_move, or/and swo_on_viewport_size. Check out available observers here: http://www.rubydoc.info/github/AntonSynytsia/AMS-Library/master/AMS/SketchupObserver

              1 Reply Last reply Reply Quote 0
              • P Offline
                Pherim
                last edited by

                Hello, when I updated to 3.0.0 WindowsSettings didn't work any more, I had to delete both AMS Lib and WindowSettings and reinstall them to make it work again. Just thought I'd mention it in case anyone else has this problem.

                1 Reply Last reply Reply Quote 0
                • P Offline
                  Pherim
                  last edited by

                  I am not entirely sure, because I have not used SketchUp very much recently, but this plugin could be causing crashes for me, since I only noticed this happening after I installed the new version and it seems to have stopped since I deactivated it (and the Windows Settings plugin with it).

                  1 Reply Last reply Reply Quote 0
                  • A Offline
                    Anton_S
                    last edited by

                    Thanks for your feedback Pherim. It would be nice to know more details about the crash, so that I could fix it in case it came from that plugin:

                    1. What Windows version and SU version were you using?
                    2. Were you using AMS Library 3.0.1 and AMS Window Settings 4.2.0 - the latest versions of these plugins?
                    3. When did the crash occur? Did it occur right away or after some time of using SU?
                    4. What were you doing at the time the crash occurred? Like, what tool were you using or what command were you accessing?
                    5. What is the list of other plugins you have installed?

                    Your response would be greatly appreciated,
                    Anton

                    1 Reply Last reply Reply Quote 0
                    • P Offline
                      Pherim
                      last edited by

                      Hello,

                      1. I'm using Windows 7 Professional 64bit and the newest version of Sketchup Make 2015 64bit.
                      2. Yes, both plugins were up to date. I am completely sure about this as I had to uninstall both and then reinstall them via the plugin store to make it work at all... just updating both plugins somehow did not work, as I wrote in the post before. I also updated it to 3.0.1 after I wrote this post.
                      3. I am not entirely sure, and right now I am unable to reproduce the crash... it's just that I noticed suddenly that when I changed the tool the cursor would not change as it was supposed to, and also the old tool would still be highlighted in the toolbar. And then, as soon as I right-clicked on a component (well, at least it was a component or group at least some of the times it happened), Sketchup crashed instantly. Well, at the moment it doesn't seem to happen even with your plugins active, but I'll be on guard about it.
                      4. Quite a lot I'm afraid... Though so far, they all worked fine together, and so did the old versions of your plugins.

                      At the moment everything seems to be fine. If this changes, I'll get in touch again.

                      1 Reply Last reply Reply Quote 0
                      • A Offline
                        Anton_S
                        last edited by

                        Thank you for your response, Pherim. I, too, came across cursor changing issues, but didn't consider it was related to my library. For AMS Library 3.x.y, the main difference between prior versions, is that I modified it to be Unicode rather than Ascii. That said, I probably implemented something improperly. I will look into that issue.

                        1 Reply Last reply Reply Quote 0
                        • A Offline
                          Anton_S
                          last edited by

                          Hello Pherim. I tried to reproduce the crash or inconsistent cursor changing behavior with AMS Library 3.0.1, but, similarly to your trial, I couldn't. It is very likely that such bug persisted in version 3.0.0, but not in the current version, 3.0.1. But to be sure, I'll keep an eye on the library.

                          1 Reply Last reply Reply Quote 0
                          • W Offline
                            wikii
                            last edited by

                            AMS::Window.send_message can sent something to a sketchup window, but,how to get message in sketchup by ruby?

                            thank you.

                            1 Reply Last reply Reply Quote 0
                            • A Offline
                              Anton_S
                              last edited by

                              Are you asking for a windows function, like [GetMessage](https://msdn.microsoft.com/en-us/library/windows/desktop/ms644936(v) or [PeekMessage](https://msdn.microsoft.com/en-us/library/windows/desktop/ms644943(v)?

                              Current version of AMS Library, doesn't have these functions implemented.
                              However, you can implement a Windows function manually, using Win32::API that is shipped with AMS::Library. Here is an example:

                              
                              module MyDesiredNamespace
                              
                                GetMessageA = AMS;;Win32;;API.new('GetMessageA', 'PLLL', 'I', 'User32')
                                GetMessageW = AMS;;Win32;;API.new('GetMessageW', 'PLLL', 'I', 'User32')
                              
                                class << self
                              
                                  # Get windows message ANSI.
                                  # @note GetMessage waits until the message is received. This means this
                                  #   function will freeze the computer until the message is triggered.
                                  # @param [Fixnum] filter_min Value of the lowest message value to be retrieved.
                                  # @param [Fixnum] filter_max Value of the highest message value to be retrieved.
                                  # @param [Fixnum] handle A handle to the window whose messages are to be retrieved.
                                  # @return [Array] Message inforamtion;
                                  #   [handle, message, wParam, lParam, time, x, y]
                                  # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms644936(v=vs.85).aspx
                                  def get_messageA(filter_min, filter_max, handle = AMS;;Sketchup.get_main_window)
                                    buffer = "\0" * (4 * 7)
                                    # See https://github.com/djberg96/win32-api for Win32;;API usage
                                    res = GetMessageA.call(buffer, handle, filter_min, filter_max)
                                    return buffer.unpack('lLlllll')
                                  end
                              
                                  # Get windows message Unicode.
                                  # @note GetMessage waits until the message is received. This means this
                                  #   function will freeze the computer until the message is triggered.
                                  # @param [Fixnum] filter_min Value of the lowest message value to be retrieved.
                                  # @param [Fixnum] filter_max Value of the highest message value to be retrieved.
                                  # @param [Fixnum] handle A handle to the window whose messages are to be retrieved.
                                  # @return [Array] Message inforamtion;
                                  #   [handle, message, wParam, lParam, time, x, y]
                                  # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms644936(v=vs.85).aspx
                                  def get_messageW(filter_min, filter_max, handle = AMS;;Sketchup.get_main_window)
                                    buffer = "\0" * (8 * 4) * (4 * 3)
                                    # See https://github.com/djberg96/win32-api for Win32;;API usage
                                    res = GetMessageW.call(buffer, handle, filter_min, filter_max)
                                    return buffer.unpack('qLqqqll')
                                  end
                              
                                end # class << self
                              end # module MyDesiredNamespace
                              
                              # In the following case, the function will return when left or right mouse
                              # buttons are click caption or non-client area of any window.
                              res = MyDesiredNamespace.get_messageW(0x0A1, 0x0A6, 0)
                              
                              

                              However, if you're aiming to monitor Sketchup action commands, which come when different tools are activated, then you'll probably want to use AMS::SketchupObserver with swp_on_command(id):

                              
                              class MyObserver
                              
                                def swp_on_command(id)
                                  # Process command here
                                  p id
                                  # Return 1 to block this command; 0 to pass this command
                                  0
                                end
                              
                              end
                              
                              my_observer = MyObserver.new
                              AMS;;Sketchup.add_observer(my_observer)
                              
                              1 Reply Last reply Reply Quote 0
                              • W Offline
                                wikii
                                last edited by

                                Hi Anton_S

                                Thank you for you reply!

                                If I want send a message from Sketchup window A to Sketchup window B, I can use AMS::Window.send_message.

                                But ,how can Sketchup window B get to know there is a message come from window A?

                                I think , Window B must have an observer to get message when message come.

                                I want to konw , can window B respond message sent from A immediately?

                                Thank you for you great lib!

                                wikii

                                1 Reply Last reply Reply Quote 0
                                • A Offline
                                  Anton_S
                                  last edited by

                                  Hmm, communication between windows? That's interesting! I will look into that.

                                  1 Reply Last reply Reply Quote 0
                                  • J Offline
                                    Jim
                                    last edited by

                                    Maybe this?

                                    https://msdn.microsoft.com/en-us/library/windows/desktop/ms644951%28v=vs.85%29.aspx

                                    Hi

                                    1 Reply Last reply Reply Quote 0
                                    • A Offline
                                      Anton_S
                                      last edited by

                                      Thanks for the head start, Jim! That, SendMessageCallback, should do it. I will implement it into my library for an easy way to use. This is what I'm thinking to add in the future release:

                                      A function to communicate to another window.
                                      ` # Transmit information to another window.

                                      @param [Fixnum] dest_handle A handle to a destination window.

                                      @param [Fixnum] id A unique message identifier, a value b/w 0 and 4016.

                                      ID allows users to filter their messages from messages of other users.

                                      However, there is a downside, as some plugin developers might use

                                      same ID, but it's very unlikely.

                                      @param [String] data Message information.

                                      AMS::Sketchup.send_message_to_window(dest_handle, id, data)`

                                      An observer that receives transmitted messages.
                                      ` # Called when user sent message arrives to its destination window.

                                      @param [Fixnum] sender_handle A handle to a window that sent a message.

                                      @param [Fixnum] id Message id.

                                      @param [Fixnum] data Message information.

                                      AMS::SketchupObsever.swo_on_message_received(sender_handle, id, data)`

                                      A bonus function that allows users to get handles to all Sketchup Windows.
                                      ` # Get all SU windows

                                      @return [Array<Fixnum>] An array of all SketchUp main windows except this one.

                                      AMS.get_all_sketchup_windows`

                                      An example, where this window communicates to all other SU windows:

                                      class MyDataTransferClass
                                      
                                        MY_PORT = 123
                                      
                                        # @param [String] Data in string form.
                                        def send_data_to_all_windows(data)
                                          su_windows = AMS.get_all_sketchup_windows
                                          su_windows.each { |dest_handle|
                                            AMS;;Sketchup.send_message_to_window(dest_handle, MY_PORT, data)
                                          }
                                        end
                                      
                                        # Implement one of the SketchUp Window Observer callback methods.
                                        def swo_on_message_received(sender_handle, id, data)
                                          # Return if id is not yours
                                          if id != MY_PORT
                                          # Otherwise, do anything with data.
                                          # In our case, we'll evaluate it.
                                          eval(data)
                                        end
                                      
                                      end # class MyDataTransferClass
                                      
                                      # Create an instance of our communication class
                                      my_data_transfer = MyDataTransferClass.new
                                      
                                      # Register your class to SketchUp observers as it contains one of the SU observer methods.
                                      AMS;;Sketchup.add_observer(my_data_transfer)
                                      
                                      # Send a message to all other SU windows.
                                      my_data_transfer.send_data_to_all_windows("puts 'Hi, this is a message from another window!'")
                                      

                                      Well, you have an insigt of how I'm planning to implement it. Once I'll add these functions into my library, I will notify you, wikii.

                                      If anyone has any suggestions on improvement of this plan, please inform.

                                      1 Reply Last reply Reply Quote 0
                                      • P Offline
                                        Pherim
                                        last edited by

                                        @anton_s said:

                                        Hello Pherim. I tried to reproduce the crash or inconsistent cursor changing behavior with AMS Library 3.0.1, but, similarly to your trial, I couldn't. It is very likely that such bug persisted in version 3.0.0, but not in the current version, 3.0.1. But to be sure, I'll keep an eye on the library.

                                        Hello,

                                        it happened again, now in Sketchup2016, with basically nothing but your plugins installed via Sketchucation tools. I don't know what exactly causes it, but it never happened with AMS Library and Window Settings disabled. I hope you can find the issue and fix it, as I would really like to be able to toggle toolbars and toolbar containers with hotkeys. With SU2016, the new trays which replace the dialog windows can natively be toggled with hotkeys, which is a very good addition in my opinion.

                                        1 Reply Last reply Reply Quote 0
                                        • A Offline
                                          Anton_S
                                          last edited by

                                          Thanks for your another report Pherim. I'm trying my best to reproduce that crash. In order to track it down, a little more information that lead to a crash would be appreciated.

                                          1. Did the crash occurred following a certain operation, like triggering a particular button, shortcut, or command or did the crash occur randomly?
                                          2. At what time did SU crash, when SU launched or some after it after is launched?
                                          3. Was the Window Settings dialog open at the time of the crash?
                                          1 Reply Last reply Reply Quote 0
                                          • P Offline
                                            Pherim
                                            last edited by

                                            Alright, here's what I got so far:

                                            When I start Sketchup with AMS Lib and Window Settings active, at first everything works fine. As I begin playing around with different tools, both native SU and from extensions, after a short time, tools begin to stay highlighted in the toolbar (only native SU toolbars in SU 2016, as tools in other toolbar are not highlighted at all in this version) even after changing to another tool, and then shortly after SU will crash when right-clicking, mostly on a group or component, I believe, and possibly only with a non-native tool active.

                                            It does not happen with just AMS Lib active and Window Settings disabled in Sketchucation Plugins/Extensions Manager, but as no other plugin depends on it, I guess it could be the cause, as well.

                                            1 Reply Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 3
                                            • 4
                                            • 5
                                            • 6
                                            • 2 / 6
                                            • First post
                                              Last post
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement