How to draw an edge with an angle and distance
-
Assuming that
ents=model.active_entities
etc has been set earlier...
Try something likece=face.bounds.center en=ce.offset(Z_AXIS, 500.mm) cl90=ents.add_cline(ce, en)### a vertical line tr=Geom;;Transformation.rotation(ce, Y_AXIS, 45.degrees) en.transform!(tr) cl45=ents.add_cline(ce, en)### a 45 deg line tr=Geom;;Transformation.rotation(ce, Y_AXIS, -90.degrees) en.transform!(tr) cl135=ents.add_cline(ce, en)### a 135 deg line
You can substitute
add_line
if you want a 'real edge'... -
It needs to be transformed to -90 as we have just rotated 'en' 45 and now want it at -45...
-
Ok gotcha...
-
@morci429 said:
i looked at the links and i still can't see how can i specify an angle
Sorry, I left out the link to
Geom::Transformation
class,
... and TIG showed how to use it (above,)EDIT. (TIG had it right,) Disregard this:except that the second tranform should be -45.degrees (not -90.degrees,) so you have an angle 135 degrees off the face's plane.
@morci429 said:
P.S i don't know the coordinates of the point the arrow going to stop at
After you transform the end points, you can save the
en
var and you have the end points, OR you also have vars referencing the new clines.
You can get the endpoints using the.end()
instance method forSketchup::ConstructionLine
class, ie:
ep45 = cl45.end
-
Thank you so much guys I’m starting to feel like you are magicians
-
Guys sorry i don't mean to be pushy, put after i fired the arrow from centroid I’m looking for a built in function in either add_cline or even add_line to retrieve all the faces that intersect with my line.
-
@morci429 said:
Guys sorry i don't mean to be pushy, but after i fired the arrow from centroid I’m looking for a built in function in either add_cline or even add_line to retrieve all the faces that intersect with my line.
At each step as you add the 'line' you have two points '
ce
' and 'en
', the vector 'vec=ce.vector_to(en)
' returns the 'arrow'.
Now 'dist=ce.distance(en)
' will help us keep track of how far we are going from 'ce
'
New use a 'raytest' to find the intersections...<span class="syntaxdefault">hits</span><span class="syntaxkeyword">=[]<br /></span><span class="syntaxdefault">pe</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">ce</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">clone </span><span class="syntaxcomment">### set up a copy of the point to raytest from<br /></span><span class="syntaxdefault">goon</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">true<br />while goon<br /> rayt</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">raytest</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">pe</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> vec</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> goon</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">false if not rayt<br /> pt</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">rayt</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault"> hit</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">rayt</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">][</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault"> goon</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">false if ce</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">distance</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">pt</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">></span><span class="syntaxdefault"> dist<br /> hits </span><span class="syntaxkeyword"><<</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[</span><span class="syntaxdefault">pt</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> hit</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault"> pe</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">pt </span><span class="syntaxcomment">### look from last hit point...<br /></span><span class="syntaxdefault">end</span><span class="syntaxcomment">#while<br /></span><span class="syntaxdefault"> </span>
'
hits
' is an array of arrays of the points and what was hit at each one...
Repeat this for each 'ray' you are making.
If you want to find ALL intersections forget the 'dist
' test... -
-
You're right - my daft typo... I've corrected the original
hit=rayt[1][0]
-
When done.. you will need to test the
hits
array members and retrieve objects that are certain types.<span class="syntaxdefault">hit_faces </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> hits</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">select </span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">|</span><span class="syntaxdefault"> e</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">][</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">instance_of</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Face</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault">hit_comps </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> hits</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">select </span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">|</span><span class="syntaxdefault"> e</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">][</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">instance_of</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">ComponentInstance</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">}</span><span class="syntaxdefault"> </span>
..etc ...
@TIG: I think
hit=rayt[0][0]
would return thex
coordinate ofpt
? -
Hey you missed my boo-boo I had written
hits.each
instead ofhits.select
(corrected the code..) -
morc ... use [ code=php ] and [ /code ] tags around your sourcecode when you post it here.
I sent you a PrivateMessage, explaining how.
You are missing 2
end
statements at the bottom, just before the**}**
closing of the block. -
Tig it isn't working.
guys could u have a look at the code and tell me what do you think?require 'sketchup.rb' UI.menu("PlugIns").add_item("Fire Arrows") { ents = Sketchup.active_model.entities Sketchup.active_model.selection.each do |e| if e.is_a? Sketchup;;Face ce=e.bounds.center en=ce.offset(e.normal, 100000.mm) cl90=ents.add_cline(ce, en) #a vertical line tr=Geom;;Transformation.rotation(ce, Z_AXIS, 45.degrees) en.transform!(tr) cl45=ents.add_line(ce, en) #a 45 deg line vec=ce.vector_to(en) dist=ce.distance(en) hits=[] pt = Geom;;Point3d.new pe=ce.clone ### set up a copy of the point to raytest from goon=true while goon rayt= Sketchup.active_model.raytest(pe, vec) goon=false if not rayt pt=rayt[0] hit=rayt[1][0] goon=false if ce.distance(pt) > dist hits << [pt, hit] pe=pt ### look from last hit point... end#while hits.each do |s| if s[1][0].is_a? Sketchup;;Face hit_face = s.bounds zmin = hit_face.min.z zmax = hit_face.max.z h = zmax - zmin h = h.to_m UI.messagebox s[1][0] UI.messagebox h end end tr=Geom;;Transformation.rotation(ce, Z_AXIS, -90.degrees) en.transform!(tr) cl135=ents.add_cline(ce, en) #a 135 deg line #en=ce.offset(Z_AXIS, 5000.mm) #tr=Geom;;Transformation.rotation(ce, X_AXIS, -45.degrees) #en.transform!(tr) #cl135=ents.add_cline(ce, en) #a 135 deg line #tr=Geom;;Transformation.rotation(ce, X_AXIS, 90.degrees) #en.transform!(tr) #cl135=ents.add_cline(ce, en) #a 135 deg line end end }
Thanks Dan,
i added the two end statements. but the complier doesn't like line 31 ]pt=rayt[0]
thanks again Dan
-
@morci429 said:
Tig it isn't working.
Error messages?
Unexpected behaviour?It always help to be specific to what isn't working.
-
Error: #<NoMethodError: undefined method
[]' for nil:NilClass> C:/PROGRA~1/Google/GOOGLE~3/Plugins/Fire Arrows.rb:31 C:/PROGRA~1/Google/GOOGLE~3/Plugins/Fire Arrows.rb:7:in
each'
C:/PROGRA~1/Google/GOOGLE~3/Plugins/Fire Arrows.rb:7
C:/PROGRA~1/Google/GOOGLE~3/Plugins/Fire Arrows.rb:3:in `call'Sorry if i wasn't clear enough
-
Try adding a test after the
goon=false if not rayt
like
next if not rayt
that way it will jump.I notice that your 'line' creation is a bit muddled - you a make one then transform the end_point [en] BUT doing so around the Z_AXIS leaves it where it is - do it around the X_AXIS or Y_AXIS...
-
morc..
EDIT:The problem is that the API doc does not say that if the ray does not hit anything, the raytest method just returns nil.
rayt= Sketchup.active_model.raytest(pe, vec)
If you read the API for Model.raytest(), you'll see that the first argument must be an
Array
; the second optional argument (added in SU8.0M1,) is the wysiwyg_flag that sets whether to hit hidden geometry.EDIT:Actually the method is smart enough to know what you mean... you don't really need an Array arg, unless you want to use the wysiwyg_flag %(#BF4000)[argument.
So you can to call it this way:]
rayt= Sketchup.active_model.raytest( **[**pe, vec**]** )
-
Tig it isn't working.
guys could u have a look at the code and tell me what do you think?...*[snip]*... reposted [in later post](http://forums.sketchucation.com/viewtopic.php?f)
-
Added a note at the bottom of the API doc page for
Model.raytest()
informing readers of thenil
return value, when no geometry is "hit." -
guys i think you are right, the hits array is empty. the ray isn't hitting any geometry. Still trying to find out why though
Advertisement