Select All Surfaces in a Model? Need assistance.
-
I have a project in which I will be exporting my 3D model to AutoCAD. I am using the 3D export option because it maintains components (as blocks), circles, arcs, dimensions, leaders, layers, and editable text.
However, "Faces in SketchUp are exported as a triangulated polyface meshwith interior splframe hidden lines (if applicable). This conversion helps to simulate the appearance of your native SketchUp file, even when all exported faces are triangular".
I would like to export just the edge-entities, not the faces. Does someone have a script the will dig down through the entire model (into all nested entities), select the faces, and delete the faces (so they can't be exported).
My methodology would be to: save the SU model, run the script, export the 3D model, and then either do a Restore or an Undo.
-
There is a ruby script desel.rb at http://www.crai.archi.fr/RubyLibraryDepot/Ruby/em_sel_page.htm
thanks to TBD -
Here is a simple code to select all faces at the model level
def select_all_faces model = Sketchup.active_model model.selection.clear #empty the current selection model.entities.each { |e| model.selection.add e if e.typename == 'Face' } end
Note that you cannot select entities at different levels, for instance in the first level of the model and at the same time within groups or component instances
-
Fredo,
then could the above be adapted to select all faces on the upper level, delete those faces and then edit each entity in the next level of nested entities, select and delete their faces, and then to the next level of nested entities and so on?
-
If you need to earse all faces at all levels, then you must do it differently
Here is a code sampledef process_faces model = Sketchup.active_model model.start_operation "erase all faces" process_faces_at_level model, {} model.commit_operation end def process_faces_at_level(grp, hcomp) list_entities = [] grp.entities.each do |entity| case entity.typename when 'Group' process_faces_at_level entity, hcomp when 'ComponentInstance' edef = entity.definition next if hcomp[edef.to_s] hcomp[edef] = edef process_faces_at_level edef, hcomp when 'Face' list_entities.push entity # store faces in the list end end grp.entities.erase_entities list_entities #or do what you want with the faces end
Note the specific treatment of component instances, as you must delete the face only once in its definition (which will propagate then to all instances)
-
Fred:
Thank you for the code. Not only did it work, but it seemed to do so fast. :}
One more request.
In some models, I will want to retain the faces of any smoothed surfaces (such as those made via Push-Pull, Follow-Me, or manually softed) so I believe any Softened or Smoothed edges would have to be Unsoftened and Unsmoothed first before finding and deleting faces.
Can you add code for an option to do this?
-
I am not clear on what you want.
Do you want to keep faces which have at least one edge smoothend or softened?
Or do you want to change the property of these edges, and still erase all faces? -
Then you need to add one line of code (in the When 'Face' section)to change the "soft" property of the edges bording the faces. This slows down the script a little bit, but I undersatnd why you need it.
def process_faces model = Sketchup.active_model model.start_operation "erase all faces" process_faces_at_level model, {} model.commit_operation end def process_faces_at_level(grp, hcomp) list_entities = [] grp.entities.each do |entity| case entity.typename when 'Group' process_faces_at_level entity, hcomp when 'ComponentInstance' edef = entity.definition next if hcomp[edef.to_s] hcomp[edef.to_s] = edef process_faces_at_level edef, hcomp when 'Face' list_entities.push entity # or do what you want with the face entity.edges.each { |e| e.soft = false } #Keep smooth edges end end grp.entities.erase_entities list_entities end
-
Fred:
Worked again. Many thanks.
John
-
Change the property of these edges so that when their respective faces are delected, the edges remain.
Advertisement