Write all faces id's and point information to text file
-
Assuming your face is an orthogonal rectangle then the dX=bb.width and dY=bb.height [oddly the 'Z-height' in the SKP is called the 'bb.depth' !]
Unfortunately your explanation is illogical.
Points 1 and 4 are dX apart [without recourse to finding their coordinates at all!]If the face is not flat or orthogonal or a rectangle then the issue is more complex but still solvable...
Please explain a little better...
-
@tig said:
Assuming your face is an orthogonal rectangle then the dX=bb.width and dY=bb.height [oddly the 'Z-height' in the SKP is called the 'bb.depth' !]
Unfortunately your explanation is illogical.
Points 1 and 4 are dX apart [without recourse to finding their coordinates at all!]
Points 1 and 4 are definitely dX apart but may not be in the same Y coordiante.
If the face is not flat or orthogonal or a rectangle then the issue is more complex but still solvable...
As I mentioned in my first post, the face can be of any shape.
Please explain a little better...I guess this new image will clear the question. Sorry for the confusion.
There are 2 faces in the XY plane in the image. The first face on the left, I need dX and dY between point 1 and 4. In the second face on the right, I need dX and dY between points 1 and 6. The faces can be of any shape and have as many edges as possible.
But the common thing is that all faces are in XY plane. So I need to find the edge/line that is at the bottom of the face and pick the 2 points attached to line to get the dX and dY.
-
A question along similar lines:
I am trying to write the input data to a file named like the rb file and in the same directory as the rb file. This will provide users with their on default data not what the author picked. Currently in windows the file is written to the desktop and I have not found code to change it. Where I would like it is in .....plugins\K2WS.Keith
-
Shashi
That's much clearer...
The faces are 'flat' in the Z-plane BUT can any number of vertices and you need to find the length of the edge that has a vertex that has the minimum Y value, since every vertex will have two faces the edge required is the one where its other vertex also has the minimum Y value.
One scenario not covered is what if the minimum Y vertex has two edges that both have other vertices that have the same Y - I assume we take the one with the lesser X ?
Here's some codefaces=[] Sketchup.active_model.active_entities.each{|e|faces << e if e.class==Sketchup;;Face and e.normal.z.abs>0.9999} ### == 'flat' num="1" text="No,dX,dY\n" faces.each{|face| pts=[] verts=face.vertices verts.each{|v|pts << v.position} pt=pts[0].clone minY=pt.y minX=pt.x pts.each{|p| if p.y < minY pt=p.clone minY=pt.y minX=pt.x end } ### pt is at minY vertex ve=verts[0] verts.each{|v|ve=v if v.position==pt} ### ve is minY vertex edges=ve.edges edges.each{|e|edges.delete(e) if not face.edges.include?(e)} ### 'edges' is just the face's 2 edges with 'minY' edge=edges[0] ey=edge.other_vertex(ve).position.y nedges=[] edges.each{|e| if e.other_vertex(ve).position.y <= ey nedges << e end } if not nedges[1] nedge=nedges[0] else n0=nedges[0] n1=nedges[1] if n0.other_vertex(ve).position.x <= n1.other_vertex(ve).position.x nedge=n0 else nedge=n1 end end ### 'nedge' is the required edge ps=nedge.start.position pe=nedge.end.position dX=(ps.x-pe.x).abs.to_s dY=(ps.y-pe.y).abs.to_s ### ### now add data to 'text' text << num+","+dX+","+dY+"\n" ### num.next! ### '1' >> '2' etc } ### now write the completed 'text' to a file file=File.join(Sketchup.active_model.path, Sketchup.active_model.title+"_FaceDump.txt") fi=File.open(file, "w") fi.puts(text) fi.close ### done!
this is untested - please try and report back...
-
Keith
Your separate question....
The .rb file's details are got from the special
__FILE__
variable which returns the full path the the .rb file.
So let's assume that the Ruby file is called 'keith.rb
'...
Then
rb=__FILE__ >>> 'C:\Program Files\Google\Google SketchUp 7\Plugins\K2WS\keith.rb'
To find its folder use
folder=File.dirname(rb) >>> 'C:\Program Files\Google\Google SketchUp 7\Plugins\K2WS'
To find its name use
name=File.basename(rb,".*") >>> 'keith'
To compile the path to the new matching .txt file use
txtfile=File.join(folder, name+".txt") >>> 'C:\Program Files\Google\Google SketchUp 7\Plugins\K2WS\keith.txt'
NOTE: another 'one-step' way [but somewhat less clear] would be this
txtfile=__FILE__.gsub(/.rb$/,'.txt')
Which directly returns'C:\Program Files\Google\Google SketchUp 7\Plugins\K2WS\keith.txt'
without any intermediate steps...I show the File parsing/join methods because they do have wider uses...
Remember that '
txtfile
' is only a string representing the file path and you need to use theFile.open...
etc to make the file and write to it... See the example[s] in the post[s] below...
-
Thanks TIG That should help me out. I had already worked out the file new/open etc. but found no help on directories etc.
Keith
-
Thanks TIG for the help.
There was one small typo, which I edited.
The text file is always saved to directory not in the active model path.
Need to verify that, But the main functionality works like a charm.Trying it on bigger models and will then update back.
Thanks Again
-
Shashi
Glad to hear it helped...
I hadn't tested the code as I typed it 'cold', from memory as one stream of consciousness - can you tell me were my 'typo is' - I can then edit the original code-block so that anyone else trying to use it doesn't have to fret about sorting that out... Saving the data file with the model OR to a fixed file-path is your choice - so if that's the 'typo' then I need not worry... as I just needed a 'FaceDump.txt' file to write to... -
TIG,
this is the typo
minX=py.x
needs to be changed to
minX=pt.xThanks
-
Thanks! fixed it...
Advertisement