Faces to components problem
-
I also don't have the outliner open, and it still crashes.
If you wanted to look quickly at ths code TIG I'd be quite happy. I'm pretty sure I've narroed the problem down to the loop that adds each face to a group and then turns the group into a component.
I really have not kept up with all the group and component snippets that have been written recently. So perhaps you have a snippet that would work better than:
faces.each do |e| group = entities.add_group( e ) group.to_component end
Because that is scrashing on this model. And interestingly, it doesn't crash on the first face. IT normally processes 10 to 20 faces, then crashes. So far I have not figured out what the problem is
Chris
-
I don't have a copy of the full code, BUT...
faces.each do |e| group = entities.add_group( e ) group.to_component end
Might be the problem ! It destroys the entities face/edges etc as you go ?
So some things disappear before you can process them !
Try something like this... assuming 'entities=model.active_entities' etc are predefined...groups2process=[] edges2go=[] ### first we 'clone' the faces... faces.each{|face| points=[]; face.vertices.each{|v|points<<v.position} group=entities.add_group() face2=group.entities.add_face(points) face2.reverse! if face2.normal != face.normal face2.material=face.material face2.back_material=face.back_material ### also clone attributes etc - you add this... ### also clone materials/attributes of edges etc - you do this... groups2process<<group ### stuff to go... edges2go<<face.edges face.erase! ### it's now in the group } edges2go.uniq! edges2go.each{|e|e.erase! if e.valid? and e.faces.length==0} groups2process.each{|group|group.to_component} ### this should process tidily... ;)
-
anyway to put that back into the plugin? I have no idea how to use ruby...
-
Made a few tweaks to the untested code and added undo and counter etc...
This quick ruby file makes 'selected faces into components' - put the file into your plugins folder, open the model, select the faces and type 'selectedfaces2components' in the ruby console...selectedfaces2components.rb
-
ok, I've also tried to update my code and I think it is improved. I'm not sure if its perfect. But perhaps its better? It seems to work on the UAV model now. But if TIG's is working well, you might just stick with it. I think he re-creates your geometry, whereas I am moving the original into the components (which is not recommended, but it seems to work here). Any, hope it helps.
Chris
-
@chris fullmer said:
ok, I've also tried to update my code and I think it is improved. I'm not sure if its perfect. But perhaps its better? It seems to work on the UAV model now. But if TIG's is working well, you might just stick with it. I think he re-creates your geometry, whereas I am moving the original into the components (which is not recommended, but it seems to work here). Any, hope it helps.
ChrisYou can move entities wholesale into a group:
model.active_entities.add_group(required_entities)
BUT they must include 'all_connected' geometry that's 'sensitive' to the 'move' into the group - otherwise you run the risk of perhaps moving a face into a group and not its edges, if it takes its edges they might have other connected faces, then these they are screwed by loosing an edge etc etc...So the safest way is to do something like this: where you group the required_stuff AND its all_connected, copy that group, explode one and then throw away everything that's in the remaining group that's not needed - e.g. keep required_stuff AND any faces' edges etc they are not in the set already...
-
TIG, I hacked your code to add a right click menu choice. I have a little programing expierence, but don't know Ruby. Do you mind if I mess with it in this way?
If thats OK with you, can you show me how to end up with one big component, or group made up of individual faces rather then all the seperate components?
-
TIG, Thanks, Even at my rate (slow), I'll eventually learn some Ruby, and the SU API:-)
-
@honoluludesktop said:
TIG, I hacked your code to add a right click menu choice. I have a little programing expierence, but don't know Ruby. Do you mind if I mess with it in this way?
If that's OK with you, can you show me how to end up with one big component, or group made up of individual faces rather then all the separate components?Hack as much as you want, but please ensure that any of your versions that 'get out' have explanatory text in them so as to apportion blame and not confuse the user
If you look at the code... We loop through each of the faces - first we add an empty
group
to themodel.active_entities
and then clone the face with it's properties into thatgroup
, then we erase the original face - remembering to leave any shared edges. Finally thatgroup
in made into thecomponent
.To change it so that each of the face-group-components is added into a super-group change the lines to read
### outside of the loop we make a new 'supergroup' supergroup=model.active_entities.add_group() supergroup_entities=supergroup.entities ### later in the loop for each face we change the group's 'destination'... group=supergroup_entities.add_group() ### rather than the previous 'model.active_entities' ### etc
Now all of the face-groups [which are now actually separate
components
] are inside a 'super_group'.
At the end you can name that or change it into a component itself, thus...supergroup_component=supergroup.to_component supergroup_component.definition.name="Face_SuperGroup#1" supergroup_component.name=supergroup_component.definition.name
-
thanks for your help on this guys, the right click option that you made honolulu doesn't seem to work on my computer but Chris, your updated code works so thank you very much
Advertisement