Parallel projection macro

I am trying to set up a macro for my 3D Connexion mouse that includes a step for setting Camera>Parallel Projection. Unfortunately the shortcut key settings only create a toggle between parallel & perspective mode. The same happens assigning a shortcut to Camera>Perspective. Is there a way to force SU into parallel mode with a macro regardless of the current camera mode ?

You can copy and paste this to Ruby Console (Menu Extensions>>Developer>>Ruby Console) then hit Enter (Return).

Sketchup.active_model.active_view.camera.perspective = false

Thanks @dezmo, but I don’t think we are on the same page. 3D Connexion will let me enter shortcut keys to form a macro. You have however lit the spark for me to start getting my head into Ruby. I’ve done machine code back in 1980’s, BASIC, LISP & GDL; how hard can it be
 :thinking:

You could set up the code snippet as an extension under “Tools”. You’d need a registration file (same name as extension folder) in your Plugins folder and an extension folder (same name as your registration file). Then assign a shortcut in SU that you can assign in the 3D Connexion software.

For example, a (ruby) file registration file:

idk_p_p_m.rb
module IDKProgramming
  module ParallelProjectionMacro

    VERSION = "1.0.0"

    EXTENSION_NAME = "Parallel Projection"
    LOADER_PATH = "idk_p_p_m/p_p_m_loader.rb"
    CREATOR = "IDK Programming"  
    COPYRIGHT = "©2024 by IDK Programming. All rights reserved."  
    DESCRIPTION = 'An extension for changing camera perspective to parallel perspective.'

    extension = SketchupExtension.new(EXTENSION_NAME, LOADER_PATH)
    extension.version = VERSION
    extension.creator = CREATOR
    extension.copyright = COPYRIGHT
    extension.description = DESCRIPTION
    
    Sketchup.register_extension(extension, true)

  end 
end

Your extension folder (idk_p_p_m) could have a loader file (not needed, but that’s how I do it) like this:

p_p_m_loader.rb
module IDKProgramming
  module ParallelProjectionMacro

    PLUGIN_PATH = File.dirname(__FILE__).freeze

    require File.join(PLUGIN_PATH, 'p_p_m_main.rb')
    
  end
end

That file would point to a ‘main’ file that has the snippet:

p_p_m_main.rb
module IDKProgramming
  module ParallelProjectionMacro
    extend self

    def activate_parallel_projection
      model = Sketchup.active_model
      view = model.active_view
      camera = view.camera

      camera.perspective = false
    end

    unless file_loaded?(__FILE__)
      menu = UI.menu('Tools')
      menu.add_item(EXTENSION_NAME) { activate_parallel_projection }
      file_loaded(__FILE__)
    end
  end
end

Then assign a shortcut that won’t take up anything you’d use all time, like ctrl+shift+p and create that as a macro.

2 Likes

I have been taking a crash course in Ruby this evening
 If I can get Ruby to do what I want it could save me hours on scene management.

2 Likes