sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Axes vectors in Sketchup 8

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 3 Posters 625 Views 3 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.
    • D Offline
      Deanby7
      last edited by

      I want to offset points along the x, y and z axes and want to setup vector variables. The following doesn't work in Sketchup 8.

      xa, ya, za = Sketchup.active_model.axes.axes
      

      The Ruby API shows 2016+ in the reference document.
      Is there another way of doing this?

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        SketchUp comes with several built in Constants

        ORIGIN X_AXIS Y_AXIS Z_AXIS

        which are, in effect...

        [0,0,0] [1,0,0] [0,1,0] [0,0,1]

        I think you are over thinking this...

        TIG

        1 Reply Last reply Reply Quote 0
        • D Offline
          Deanby7
          last edited by

          Trying to follow your example from the holeinthewall!!
          I seem to get hung up on the simplest of things!! I am getting Error: #<ArgumentError: wrong number of values in array> between p "ok" and p "ok2" lines of code!! Grrrrrr

          module DeanBy7
          	module Stair_Builder
          		def self.main
          		    @tht = 2600.mm if(!@tht)
          			@wid = 900.mm if(!@wid)
          			@trd = 32.mm if(!@trd)
          			org = [0,0,0]
          			mod = Sketchup.active_model			
          			xa = X_AXIS
          			ya = Y_AXIS
          			za = Z_AXIS
          			ents = mod.entities
          			str_grp = ents.add_group()
          			str_grp.name = "dbStairs"
          			sents = str_grp.entities
          			prompts = ["Stair Height Total", "Stair Width", "Tread Thickness"]
          			results = UI.inputbox prompts, [@tht,@wid,@trd], "db Stair Builder"
          				if results
          					@tht,@wid,@trd = results; mod.start_operation "db Window Opening"
          					p @tht
          					p @wid
          			        testrisers = @tht / 220.mm
          					risers = testrisers.ceil
                              p testrisers
                              p risers
                              riser = @tht / risers
          					p "Riser = " + riser.to_mm.to_s
          					tread = riser / Math.tan(42.degrees)
          					p "Tread = " + tread.to_mm.to_s
          					p0 = [org]
          					p "ok"
          					p1 = p0.offset(xa, @wid)
          					p "ok2"
          					p2 = p1.offset(ya, tread)
          					p3 = p0.offset(ya, tread)
          					step = sents.add_face(p0,p1,p2,p3)
          					step.pushpull @trd
          					
          					mod.commit_operation
          			    end
          		end
          	end
          end
          unless file_loaded?("dbstairbuilder")
          	UI.menu("Plugins").add_item("db Stair Builder") { DeanBy7;;Stair_Builder.main }
          	file_loaded("dbstairbuilder")
          end
          
          1 Reply Last reply Reply Quote 0
          • D Offline
            Deanby7
            last edited by

            Spotted my error.... p0 = [org] , should be p0 = org
            I had 0,0,0 in there before changing it to a variable. Apologies for wasting forum time!!!

            1 Reply Last reply Reply Quote 0
            • TIGT Offline
              TIG Moderator
              last edited by

              Of course you can use...
              org = ORIGIN
              BUT... if you want to change org later on, then use
              org = ORIGIN.clone

              TIG

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                To get the working model axes there is a hack for older versions of SU - if you only need the direction. You aren't able to obtain the origin though.

                Here's a snippet directly from Vertex Tools:

                
                    # SU7+ only - incorrect in older versions.
                    # A hack to get the current model axis.
                    #
                    # @return [Array<Vector3d,Vector3d,Vector3d>]
                    # @since 1.0.0
                    def get_local_axis
                      if FEATURE_MOVING_AXIS
                        # SketchUp 8+
                        tr = get_local_transformation
                      elsif @model.respond_to?( ;edit_transform )
                        # SketchUp 7
                        if @model.active_path
                          tr = @model.edit_transform
                        else
                          tr = get_local_transformation
                        end
                      else
                        # SketchUp 6
                        tr = Geom;;Transformation.new
                      end
                      [ tr.xaxis, tr.yaxis, tr.zaxis ]
                    end
                
                    # SU7+ only - incorrect in older versions.
                    # A hack to get the current model axis.
                    #
                    # @return [Array<Vector3d,Vector3d,Vector3d>]
                    # @since 1.1.0
                    def get_local_transformation
                      @model.start_operation('Get Local Transformation (Hack)')
                      entities = @model.active_entities
                      tr = entities.add_group(entities.add_group).transformation
                      # (?) SketchUp bug?
                      #     The transformation returned has X, Y and Z set to 1.0e+030!
                      #     Why this high value? Overflow bug?
                      Geom;;Transformation.new( tr.xaxis, tr.yaxis, tr.zaxis, ORIGIN )
                    ensure
                      @model.abort_operation
                    end
                
                

                That FEATURE_MOVING_AXIS constant comes from a check if the SU version is 8 or higher.

                Thomas Thomassen — SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

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

                Advertisement