I’ve been looking at my “Draw Wall Tool” and I really like how the tool is now able to lock onto the X and Y axis. It would be convenient if I could also somehow have it lock to the 45 deg. line or the 135 deg. line.
I’m going to play around with it tonight but I thought I might put the question out there in case someone has done this before and prevent me from wasting a lot of time on reinventing the wheel.
(As you will see in my code I’m at beginning of learning Ruby…I don’t really understand everything in it yet, and sorry if it looks a little unclear/garbage) …
…but I’ve got some idea:
In my PomPi tool (PomPi 2016 (Pompous Piping) | SketchUcation) I have been implemented a lock on perpendicular plane. (You can check the Dezmo_pompi2016_line_auto.rb) I’m using the down arrow key to switch the lock on and off.
The quickly created code below I’m assuming the @ip1 is the first point of your wall and @ip2 the second, you can project the @ip2 to line of axes (or angled line) and use that “@lock_point” instead of the inputpoint, if you have a locked status. The locked status will be periodically changing to the next angle or to "off " by pressing the down key.
Something like this:
(I did not tested this code, and it is only a kind of idea… may need to take into consideration some transformation, syntax correction etc. )
def onMouseMove(flags, x, y, view)
@ip2.pick view,x,y,@ip1
if @lock_count==0
@lock_point = @ip2.position #no lock
else
vec=Geom::Vector3d.new(1,0,0) if @lock_cuont==1 #x axis
vec=Geom::Vector3d.new(1,1,0) if @lock_cuont==2 #45
vec=Geom::Vector3d.new[0,1,0) if @lock_cuont==3 #y axis
vec=Geom::Vector3d.new(-1,1,0) if @lock_cuont==4 #135
point=@ip1.position.offset(vec)
line=[@ip1.position,point]
@lock_point = @ip2.position.project_to_line(line)
end
end
def onKeyDown(key, repeat, flags, view)
if( key == VK_DOWN )
@lock_count +=1 #0: no lock; 1:0degrees ; 2:45; 3:90; 4: 135
@lock_cuont=0 if @lock_cuont>4
end
end
def draw(view)
view.draw_line(@ip1.position,@lock_point)
view.draw_text(view.screen_coords(@ip2.position), "locked X") if @lock_cuont==1
view.draw_text(view.screen_coords(@ip2.position), "locked 45deg") if @lock_cuont==2
.
.
end
I hope it will work… (if nothing else it can be used as a bad example )
I’m trying out elements of this code and I’ve almost got it working but for some reason it requires two clicks of the alt key. The first click locks up the cursor entirely. Other than that it is working as expected.
… but unfortunately it does not influence anything… the cursor is not “jumping” . Did I missed something? I think it is only works in the native rotate tool.
(The “LengthSnapEnabled” works better.)
I just accidentally discovered some undocumented feature. If you return true in onKeyDown it will prevent the original behaviour of alt key. Something like this:
def onKeyDown(key, repeat, flags, view)
#other
#
if( key == ALT_MODIFIER_KEY)
#something
#something else
return true # prevent ALT from focusing the menu
end
#any other
#
end