Axes vectors in Sketchup 8
-
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.axesThe Ruby API shows 2016+ in the reference document.
Is there another way of doing this? -
SketchUp comes with several built in Constants
ORIGIN X_AXIS Y_AXIS Z_AXISwhich are, in effect...
[0,0,0] [1,0,0] [0,1,0] [0,0,1]I think you are over thinking this...
-
Trying to follow your example from the holeinthewall!!
I seem to get hung up on the simplest of things!! I am gettingError: #<ArgumentError: wrong number of values in array>between p "ok" and p "ok2" lines of code!! Grrrrrrmodule 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 -
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!!! -
Of course you can use...
org = ORIGIN
BUT... if you want to changeorglater on, then use
org = ORIGIN.clone -
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 endThat FEATURE_MOVING_AXIS constant comes from a check if the SU version is 8 or higher.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement