Yes, I got that.
Thx!
Ok, I see. That also explains why find_faces
didn´t work on neither of the edges.
So add_face(edgearray) doesn´t work on API created egdes? Or is there a command that forces edges to merge to loops if possible?
But I can´t see the face on your screen, only four edges?
Here ist what it looks like when I execute the code on my machine. Maybe it´s a difference, because I use Ruby Code Editor?
[xxl-img:xg9qtt3f]http://www.steffenblome.de/add_face.jpg[/xxl-img:xg9qtt3f]
as you can see I used
ent = mod.entities
but I just tried
ent = mod.active_entities
with the same results.
And thanks for that advice on how to create a face with a hole, I´m going to use that.
In the Ruby API it says that youn can create a face by passing an array of edges as an argument:
@unknownuser said:
Entities.add_faceSketchUp 6.0+
The add_face method is used to create a face. You can call this method a number of ways:entities.add_face(edge1, edge2, edge3, ...)
entities.add_face(edgearray)
entities.add_face(pt1, pt2, pt3, ...)
entities.add_face([pt1, pt2, pt3,...])
entities.add_face(curve)
I tried it like this
punkteArray = []
edgeArray =[]
punkteArray.push(Geom;;Point3d.new(0,0,0))
punkteArray.push(Geom;;Point3d.new(100,0,0))
punkteArray.push(Geom;;Point3d.new(100,0,100))
punkteArray.push(Geom;;Point3d.new(0,0,100))
punkteArray.push(Geom;;Point3d.new(0,0,0))
edgeArray = ents.add_edges punkteArray
face = ents.add_face(edgeArray)
but that returned nil and no edges were drawn at all. I know that I could have used
face = ent.add_face(punkteArray)
but I was hoping to be able to create a face with a hole in it by passing an array with the outer and inner loop edegs to the add_face method, but not even passing a single loops seems to work.
Since I now have working code I better not change it, but I´ll keep your advices in mind for further projects. I´m afraid I won´t be able to explain all my goals, since my English isn´t that good and it´s hard to explain just by text. (And actually I just wanted to know how to reverse edges, but of course any further information is welcome!)
Thanks for your support!
I already deleted the old code, but it was something like this:
edgeUses = loop.edgeuses
firstEdge=edgeUses[0]
currentEdgeUse = firstEdgeUse
nextEdgeUse = currentEdgeUse.next
while (currentEdgeUse.edge.end != firstEdgeUse.edge.start)
endPoint = currentEdgeUse.edge.end
if ((endPoint != nextEdgeUse.edge.start) && (endPoint != nextEdgeUse.edge.end))
puts "current Edge and next Edge not connected!"
end
...
wrap nextEdgeUse.edge and swap start and end if necessary
...
currentEdgeUse = nextEdgeUse
nextEdgeUse = currentEdgeUse.next
end #of loop
This code does not reflect using the wrapper class. just assume that edge.start and edge.end are in correct (continous) order. My point is, that using that code on the six faces of a cube the if-statement was true several times which to me means, that you can´t be sure "next" returns an adjacent edge(use). (Of course I could be wrong!)
My goal is (simplified) to let the user redefine the coordinates of vertices. Therefore I pick one vertex (point 1) which can not be modified as a reference point and then the user can edit the coordinates of the next point (point 2) relatively to point 1, so point 2 also has fixed coordinates. Then the user can edit point 3 relatively to point 2 and so on.
This works fine, now I´m trying to deal with faces with holes in them, respectively faces with more than one loop.
I used EdgeUses, but they are useless...
At least for my purpose. The reason is, that the "next"-method doesn´t necessarily seem to return an edge which is adjacent to the edge on which the method is called.
I solved my problem like this:
first I wrote a method to traverse through the edges of a loop in one direction until returning to the first edge.
While doing so, I saved all edges in an Array, but before I wrapped the edges in a class "EdgeWrapper". This class has three attributes: the edge-object and two vertices called "start" and "end". EgdeWrapper.start is initialized with EdgeWrapper.edge.start an EdgeWrapper.end with EdegWrapper.edge.end. If I want to change the edge orientation i can assign EdgeWrapper.edge.start to EdgeWrapper.end and EgdeWrapper.egde.end to EdgeWrapper.start.
Of course creating a class inherited from "Edge" with additional start and end vertices would also have been possible (and maybe better), but for my needs the above works fine.
Hi there!
I need to swap start and end points of edges, for I need the orientation of edges on a face to be a contnious loop. (I´m aware of the outer_loop method of faces, but for certain reasons it doesn´t fit my needs.)
In a single face the edges are continous (which in my definition means every start point of an edge is the end point of exactly one other edge), but if you look at the side faces of a cube, both vertical edges seem to be oriented in positive z-direction.
Therefore I´m trying to implement same sort of "reverse"-method for edges.
my attempts so far:
new_edge = ents.add_edges edge_to_reverse.end.position, edge_to_reverse.start.position
edge_to_reverse.erase!
that didn´t work, for when erasing the original edge, the newly created edge will also be erased.
My second approach was to save the original edge´s vertices, delete the edge and then draw a new one using the saved Points:
new_start = edge_to_reverse.end
new_end = edge_to_reverse.start
edge_to_reverse.erase!
new_edge = ents.add_edges new_start.position, new_end.position
this work quite well, but the face is beeing erased when deleting the old edge. Not a big deal, I just added the face again using the find_faces-method:
new_edge.find_faces
So that is nearly what I wanted to achieve, but there is (at least) one problem: if there is a face with a hole in it, the find_faces method might eventually fill this hole with a face.
any suggestions?
I didn´t know about that possibility and it really seems to be just what I´m looking for. I will definitely give it try.
Thanks!
Thanks for your advices. I have tested the post_url method before, but I guess you can only submit the values of <input> elements like text areas or buttons in the url, no images. I decided to drop that feature for now, may I will implement it later. There seem´s to be another approach using the flash file upload abbility, may be I´ll give it a try then.
Hi!
I´m trying to send a jpeg file from the webdialog to a php-script to save it server-side. The background is, that I want to create a little preview of the Sketchup model with the write_image function which shall be used for further purposes. I already found out, that I can´t upload a file with javascript for security reasons, so I use a form within the Webdialog. Inside this form there is a filechosser and an invisible iframe. The invisible iframe will recieve the php answer, so that the webdialog won´t reload or some other unwanted behaviour will occur.
Now my problem is, when clicking the submit button the php-script ist not beeing called, nor is the onsubmit event beeing triggered and it looks like the ruby script creating the webdialog reloads. I searched this forum for solutions and found that probably it´s not possbile to submit forms with an
<input type="submit"/>
element.
Of course I could use a normal button instead and bind a function to it, but how will I get the chosen image-file within the form to be uploaded to the php-script?
Any ideas?
This is my html code so far:
<form id="frm_icon_upload" action="icon_upload.php" method="post" enctype="mulitpart/form-data" onsubmit="debugAlert()">
<input type="submit" name="action" value="Upload"/>
<input type="file" name="icon" id="icon"/>
<iframe id="upload_target" name="puload_target" src="" style"..."></iframe>
</form>
Thanks for your advice, I denfinateley will keep that in mind...or at least try to...
In case I follow your tip with collecting all points first and then create all edges with one single add_edges-command I would still have the problem of the duplicate points. That could quite easily be solved by an own "uniq"-method for Point3d-objects, but then the order of the points in that array could became disarranged, depending on which duplicte entry will be deleted. So I´m afraid my square could easily end up as an sandclock-shaped drawing.
Since I have to draw about 20 faces at most, I will try the edge-by-edge method first.
I just found out the answer to question number 1:
since "add_edges" returns an Array of edge (also only 1 edge ist created), only the first (and only) value of the return value must be put into the Array of edges:
wrong:
kante = entities.add_edges anfangsPunkt, endPunkt kantenArray << kante
correct:
kante = entities.add_edges anfangsPunkt, endPunkt kantenArray << kante.first
Hi!
I´m trying to create a face consisting of four edges. Therefore I create the four (connected) edges with the enitites.add_edge method and store the resulting edge-objects in an array. When I try to draw a face by entities.add_face with the array containing the four edges I receive the following error:
Error; #<ArgumentError; wrong number of values in array>
which is strange, because this is what´s in the Array:
[[#<Sketchup;;Edge;0xb7c1ba8>], [#<Sketchup;;Edge;0xb7c189c>], [#<Sketchup;;Edge;0xb7c1590>], [#<Sketchup;;Edge;0xb7c1284>]]
Then I tried to draw the face using all the Point3d-objects by collecting them in an Array while drawing the four edges. When I try to draw the face with the Array of points as an argument I get the error that there are duplicate points in the Array. I tried to remove the duplicate points with the uniq-method, but that doesn´t work. I assume, uniq only works with primitive-datatypes and not with points since the array contains only referneces?
So my three questions are:
Why cant the face be drawn with the Array of edges as an argument?
Is there an easy way/plugin to delete duplicate points from an array?
Is there a better approach to achieve my goal of drawing a face with four given edges?
Here is my so far code:
<span class="syntaxdefault"></span><span class="syntaxkeyword">require </span><span class="syntaxstring">'sketchup.rb'<br /><br /></span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">send_action </span><span class="syntaxstring">"showRubyPanel;"<br /><br /></span><span class="syntaxdefault">model </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model<br />entities </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_entities<br /><br /><br />UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">menu</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"PlugIns"</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">add_item</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Bauteile"</span><span class="syntaxkeyword">) {<br /> <br /> </span><span class="syntaxdefault">dialog </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">UI</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">WebDialog</span><span class="syntaxkeyword">.new(</span><span class="syntaxstring">"Bauteile"</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">false</span><span class="syntaxkeyword">, </span><span class="syntaxstring">"SketchUp"</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">460</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">600</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">100</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">100</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">false</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">dialog</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">set_file </span><span class="syntaxstring">"C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/bauteile/frontend_bauteilerstellung.html"<br /> <br /> </span><span class="syntaxdefault">testString </span><span class="syntaxkeyword">=</span><span class="syntaxstring">"0p0p0ae10p0p0k10p0p0ae10p10p0k10p10p0ae0p10p0k0p10p0ae0p0p0"<br /> </span><span class="syntaxdefault">kantenStrings </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">testString</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">split</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"k"</span><span class="syntaxkeyword">)<br /> <br /> <br /> </span><span class="syntaxdefault">kantenArray </span><span class="syntaxkeyword">= Array.new<br /> </span><span class="syntaxdefault">punktArray </span><span class="syntaxkeyword">= Array.new<br /> <br /> </span><span class="syntaxdefault">kantenStrings</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each </span><span class="syntaxkeyword">do |</span><span class="syntaxdefault">k</span><span class="syntaxkeyword">|<br /> </span><span class="syntaxdefault">punkteString </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">k</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">split</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"ae"</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">anfangsPunktString </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">punkteString</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">split</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"p"</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">endPunktString </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">punkteString</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">split</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"p"</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">anfangsPunkt </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Point3d</span><span class="syntaxkeyword">.new(</span><span class="syntaxdefault">anfangsPunktString</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">to_i</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">anfangsPunktString</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">to_i</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">anfangsPunktString</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">2</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">to_i</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">endPunkt </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Point3d</span><span class="syntaxkeyword">.new(</span><span class="syntaxdefault">endPunktString</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">to_i</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">endPunktString</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">to_i</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">endPunktString</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">2</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">to_i</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">punktArray </span><span class="syntaxkeyword"><< </span><span class="syntaxdefault">anfangsPunkt<br /> punktArray </span><span class="syntaxkeyword"><< </span><span class="syntaxdefault">endPunkt<br /> kante </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_edges anfangsPunkt</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">endPunkt<br /> kantenArray </span><span class="syntaxkeyword"><< </span><span class="syntaxdefault">kante<br /> end<br /> <br /> puts kantenArray</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">inspect<br /> puts punktArray</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">inspect<br /> punktArray </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">punktArray</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">uniq<br /> puts punktArray</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">inspect<br /> <br /> flaeche </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_face kantenArray<br /> </span><span class="syntaxcomment">#flaeche = entities.add_face punktArray<br /> <br /> </span><span class="syntaxdefault">dialog</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_action_callback</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"zeichne_flaeche"</span><span class="syntaxkeyword">) {|</span><span class="syntaxdefault">dialog</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">params</span><span class="syntaxkeyword">|<br /> }<br /> </span><span class="syntaxdefault">dialog</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">show<br /></span><span class="syntaxkeyword">} </span><span class="syntaxdefault"></span>
"testString" is just a...well testString which simulates the data I will later receive from the webDialog. It´s then parsed into edges. That works, since I can see a square in Sketchup.
"kantenArray" is the Array containing the four edges
"punktArray" is the Array containing eight Points, with four of them having the same coordinates
Of course you´re right, I only browsed the Entity-Classes, not the Collection-classes, although I already created some faces using add_face...shame on me.
thx for your quick response!
Searching this Forum and the Sketchup-API I couldn´t find a way to create a text-object, but only found methods to manipulate existing text-objects.
What I´m trying to do ist creating labels for faces and edges to identitfy them, like "Edge_01". I´m aware of the fact, that there is no easy way to attach these labels to the corresponding entity by ruby, but that wouldn´t be to bad, since the labels will just disappear when the model or the camera-view changes.
But is there really no way to create a text-object using ruby?
Thank you for your detailed answer. I think I will go with the seperate View solution. although it might be a bit confusing to have a preview in a different window which might get lost behind other windows and stuff. But on the other hand it seems far more attractive than dealing with javascript behaviour on different browsers (versions). Maybe the model in the preview View is even natively zoom- and rotateable? That would certainly be a nice feature. I will catch up on that, thank you so far.
Hi there,
my name ist Steffen, I´m from Germany and currently developing a Sketchup-Plugin as a bachelor thesis. As I don´t have any experience in using Sketchup or ruby, I´ll probably have a "few" questions in the near future...
and here´s already the first one: in my Plugin (which btw. will be about generating civil-engineering-construction-parts out of templates by specifying numerical parameters) I use a WebDialog as a GUI. Not much of a surprise, I guess. In this GUI the user will be able to specify some numerical parameters, like height, width, length and so on. Before generating the final model from this values and place it in Sketchup, I would like to show a little preview of the model in an area within the WebDialog. I certainly could do this via Javascript and some library like "three.js", but since I will "build" the model for Sketchup anyway, it would be a work-safer to use this model as a preview, too.
Is there a common way to display real-time-generated models within a WebDialog?