This is driving me crazy and now I've spent nearly another full day on it. Arrgh!
I can draw Camera Ray lines just fine. But not clines unless there is an object to reference.
I can get one, single unreferenced cline. Once a cline fails to get an input point because of a lack of a reference object, I cannot get another valid @ip for a line, only for clines that have reference objects. Doesn't matter if I reload the file, I have to restart SU to clear this state.
I thought I could draw the line first, and then use its endpoints to create the vector (that works) and the cline (that doesn't work).
To demonstrate, I have two files. The only difference between them is that in the first one, some code is commented out: the single line of code that creates a cline from a point and a vector and some following messages to report on it.
Both versions create a vector from the original line and that appears to work fine.
Here's the version that creates plain old ordinary edge lines. I call it rayL.txt:
class Clf_august_lines;
def onMouseMove(flags, x, y, view);
@ip = view.inputpoint(x,y);
view.invalidate;
end;
def onLButtonUp(flags, x, y, view);
line1 = Sketchup.active_model.active_entities\
.add_line(view.camera.eye, @ip.position);
if (line1)
UI.messagebox "line1 SUCCESS\n
view.camera.eye = " + view.camera.eye.to_s + "\n
@ip.position = " + @ip.position.to_s else
else
UI.messagebox "line1 Failure\n
view.camera.eye = " + view.camera.eye.to_s + "\n
@ip.position = " + @ip.position.to_s
end
vector1 = line1.start.position\
.vector_to(line1.end.position);
if (vector1)
UI.messagebox "vector 1 = " + vector1.to_s
else
UI.messagebox "vector1 Failure"
end
#cline1 = Sketchup.active_model.active_entities\
#.add_cline(line1.start.position, vector1);
# if (cline1)
# UI.messagebox "cline1 = " + cline1.to_s
# line1.erase!
# else
# UI.messagebox "cline1 Failure"
# end
end;
def draw(view);
@ip.draw view;
end;
end;
Sketchup.active_model.select_tool\
(Clf_august_lines.new)
And here's the version that creates a line, then uses that line's endpoints to create a vector, which works in both versions, and then creates a cline from one endpoint of the line and the vector. It is this cline which initiates the problem.
I call this one rayLC.txt because it attempts to create a line and then a cline:
class Clf_august_lines;
def onMouseMove(flags, x, y, view);
@ip = view.inputpoint(x,y);
view.invalidate;
end;
def onLButtonUp(flags, x, y, view);
line1 = Sketchup.active_model.active_entities\
.add_line(view.camera.eye, @ip.position);
if (line1)
UI.messagebox "line1 SUCCESS\n
view.camera.eye = " + view.camera.eye.to_s + "\n
@ip.position = " + @ip.position.to_s
else
UI.messagebox "line1 Failure!\n
view.camera.eye = " + view.camera.eye.to_s + "\n
@ip.position = " + @ip.position.to_s
end
vector1 = line1.start.position\
.vector_to(line1.end.position);
if (vector1)
UI.messagebox "vector 1 = " + vector1.to_s
else
UI.messagebox "vector1 Failure"
end
cline1 = Sketchup.active_model.active_entities\
.add_cline(line1.start.position, vector1);
if (cline1)
UI.messagebox "cline1 = " + cline1.to_s
# line1.erase!
else
UI.messagebox "cline1 Failure"
end
end;
def draw(view);
@ip.draw view;
end;
end;
Sketchup.active_model.select_tool\
(Clf_august_lines.new)
If I open a new SU drawing and load 'rayL.txt', it will draw lines whereever I click. But unless there is an object for them to reference, they stop at the bounding planes of the near quadrant.
If I then either load 'rayLC.txt' or open a new SU file and load it, I can draw clines that reference existing objects, e.g., Sang, and there is no problem.
But when I attempt to draw a cline that does not reference an existing object, I can create just that one, single cline and then all subsequent attmpts to create clines will fail because @ip.position is stuck at the camera.eye position or line1.start.position.
Even if I load rayL.txt again to create just lines, they fail, referencing Sang, the origin, or whatever. After one cline, @ip.position is stuck on camera.eye.
I have tried TIG's suggestion of inserting @ip = nil but everywhere I have tried it produces error messages.
This doesn't seem like it should be this hard.
I have been poring over the SketchUp Ruby doc about view and inputpoint etc. and unfortunatley it all seems written for those who already get it. It also says things like the inputpoint should "normally" be obtained using [ruby:11qtfq9b]pick[/ruby:11qtfq9b], but I've followed those examples and not even gotten a working start. At least this one based on Chris Fullmer's version works sometimes.
It appears to be one of three things:
- It really is this hard.
- I'm overlooking something very basic.
- There is a bug in creating
clines from a point and a vector.
Can someone help me figure out which it is, and/or possibly suggest a workaround?
Thanks,
August