Face.clone
16 posts
• Page 1 of 1
Face.cloneIs there something that will achieve a face.clone or face.copy? Eventually I want something that will copy all information, including materials, textures, etc. At the moment, I'm just trying to copy the geometry. See the image below. The image on the left is the original face. The image in the middle is the result of creating a new face using entities.add_face(face.outer_loop.vertices). The outer geometry is maintained, but not the hole in the middle. Using entities.add_face(face.vertices) results in the shape to the right - not right at all.
As always, Thanks! -- Karen Re: Face.cloneSo apparently, you can do face.clone, the challenge is having the face around long enough to do anything with it. I would like to add the cloned face to a group. Entities.add_face only accepts arrays of edges or points, not actual faces, is there any way to add an already defined face to a group? I if so, I might be able to determine what is happening with face.clone
-- Karen Re: Face.cloneI'd create a copy face using the outer loop first, then iterate the remaining loops and add then, removing the inner face if the original doesn't have one.
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
Re: Face.clonebtw, are you generating the face yourself? If so, could you not create it as a group and copy it as many times you need then explode the groups?
what is the scenario here? Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
Re: Face.cloneForget about loops and the like...
First off you need to add the desired face to a temporary group tgp=Sketchup.active_model.active_entities.add_group(face) copy that group, fgp=tgp.copy explode the original temporary group so that the original face is put back unchanged. tgp.explode Now you have a group (fgp) containing a clone of the original face with its location, material[s], layer and attributes etc... ![]() TIG
Re: Face.cloneI thought adding existing geometry to groups made SU go rampage and bugsplat?
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
Re: Face.cloneI think that creating it as a group (and I may have a few faces), copying the group and then exploding the group is my best option. I don't want to use the first method because if I have another face (or sub-face if you want to think of it that way) in the hole, and I copied the sub-face first, then deleting the center of the hole will delete the face in the middle.
It just seemed to me that there should be a simpler way to do this. I just tried TIG's method, and it works, although I have had a problem creating and exploding groups using the webconsole. The exact same script that will splat in the webconsole will run fine if I create an external rb file. I think this may be fixed in the next release? Thanks as always for your help!! -- Karen Re: Face.cloneHi,
Here is my code for it, i used it a while ago and it seems to do its job, no matter the number of holes in the face ![]() Call with: clone_face=face.copy(v,d,ents) assuming face is a face objet, v param is a vector3d object (direction of copy), d is a distance of copy along vector v, and ents is an entities object (in what entities collection to add the copied face). Normal is preserved.
Hope this helps, Didier Bur
Ecole Nationale Supérieure d'Architecture de Nancy (F) Re: Face.clone
It does, BUT NOT if you make, copy and explode the group immediately - many of my tools use this method without issues. It will Bugsplat if you try and do too much with these grouping, and especially if you try and group entities across sets - try and see -it won't splat... ![]() PS: The advantage of this method is that the face's material[s], layer and attributes are kept automatically. TIG
Re: Face.cloneA little OT but this code will avoid bugsplat when creating a bunch of empty groups at once:
Didier Bur
Ecole Nationale Supérieure d'Architecture de Nancy (F) Re: Face.clone
Karen, The .clone and .dup methods come from standard Ruby class Object, and create "shallow" copies. Ie, (from the book,) "the instance variables of the obj are copied, but not the objects they reference." Anyway.. it does NOT matter, because all of the Sketchup::Entity and Sketchup::Drawingelement subclasses are NOT pure Ruby objects. They are C++ objects, that are only exposed to Ruby in whatever manner (ie methods,) that the API makers decide(d). They do not really have Ruby attributes (instance variables,) they have C++ properties that we can access only if the API exposes them (thru a getter or setter method.) If you attempt to use the .clone or .dup methods on any C++ object, you will see a special "boo-boo" class returned: f.selection[0] #<Sketchup::Face:0x6023f54> f2=f.clone #<Deleted Entity:0x6020188> So don't use them. Really in the API they (.clone and .dup) should have been undefined for all the Sketchup subclasses that they don't work with, or overrriden with versions that do work (such as Didier's examples above.)
Re: Face.clone
.add_group(entities) should work fine as long as the entities are from model.active_entities. Re: Face.cloneOR any single 'entities' set - e.g. definition.entities.add_group(entities_already_in_the_definition_entities)
TIG
Re: Face.clone
but then you have to explode it right away (at least that's what it sounded like). If you only use active_entities, you can create it without having to worry about exploding it or bug-splatting SketchUp. Re: Face.cloneYes you can create a group from entities immediately, and leave it made - just keep the entities-set the same fro all entities and the group itself
You don't have to use 'active_entities' - BUT just use one set fro all of the entities for the group and geometry... Cross-threading entities causes splats. How do you think some of my EEbyxxx tools work ? What I was saying was, to to clone a face you can group it, copy the face-group and immediately explode the original group - that way the face is back where it was, and you have a group with an exact copy of the face in it - materials/layer/attributes etc... TIG
Re: Face.cloneDidier - thanks for posting this. For my current purposes, I sometimes have another face bounded by the inner loops that I don't want to erase, so If I copy a bunch of faces together, and copy the inner loop faces first, then they'll get deleted when I copy the outer faces. So, creating a group, copying the group, and immediately exploding the original group is the best method for me.
Dan - thanks for the info on face.clone and face.dup. I saw <Deleted Entity: xxxxxxxxx> pop up in the ruby console, but I just assumed that the face was immediately deleted because it was placed on top of the other face. -- Karen
16 posts
• Page 1 of 1
|
Who is online
Users browsing this forum: berkernbilgin and 10 guests