SketchUp’s DWG import doesn’t follow the company’s own policy about raw geometry on Layer 0. It labels all raw geometry with the DWG layer it’s on and then group’s the whole file on Layer 0. If they followed their own advice, the drawing elements themselves should be Untagged/Layer 0, and then everything on each layer should be grouped with the Tag/Layer of the DWG layer, and then finally group the whole thing. A user actually has to go out of their way with DWG import to get all the raw geometry untagged, and a lot of new users especially end up with this unknowingly only to come here for help and be told they aren’t doing things right.
Why would developers choose to do it like that? Is it deliberate or because it’s difficult to do otherwise?
I wonder if it’s a legacy thing. DWG import has been around since the beginning as far as I can remember. The “keep all raw geometry on layer 0” advice seemed to evolve over time, and I only started hearing that a few years ago. Maybe no one stopped to notice or think about what the DWG importer was doing in the mean time.
Maybe have it as an option? I can think of times that I could use either. It just depends on what project I am working on.
I recall being told to leave Layer 0 associated with all raw geometry and only give other layer assignments to groups and components when I first started with SU3.
@SeanB makes a good suggestion. In the meantime I just use TIG’s Default Layer Geometry immediately after import.
Really? Wow, I was out of that loop.
Probably just had more important stuff on your mind.
Here’s a Ruby function that will take loose faces and edges with assigned tags/layers and create a group to contain them. I’ve found it useful as a first step follow-up on a DWG import that used tags in the wrong way for SketchUp, as it preserves the logical gathering by tag. It does not do anything with edges or faces that are already nested in groups or components because one of the other extensions such as mentioned above can fix those issues.
def self.group_by_layer
# gather up loose edges and faces
loose_faces = Sketchup.active_model.entities.grep(Sketchup::Face)
loose_edges = Sketchup.active_model.entities.grep(Sketchup::Edge)
# retain only edges not used by any face. Edges needed by a face
# will be handled along with the face.
loose_free_edges = loose_edges.delete_if {|edge| !edge.faces.empty?}
loose_geometry = loose_faces + loose_free_edges
# Hash with a key for each layer used by loose geometry and value
# an array of entities that use that layer. Default initializes a
# empty array so we can append items.
loose_by_layer = Hash.new {|h,k| h[k] = []}
loose_geometry.each {|entity| loose_by_layer[entity.layer] << entity}
# create a group for each used layer and put the associated geometry
# into it. Because a face must have all its edges in the same context,
# this will do two things: it will bring the bounding edges of the face
# into the group even if they weren't using this layer, and it will create
# a duplicate in the model if the edge is needed to bound a face still there.
# These new edges in model aren't in the list we built earlier but aren't needed
# because we captured only faces and free edges, not edges that bound faces.
Sketchup.active_model.start_operation("Group by layer", true)
loose_by_layer.keys.each do |layer|
begin
gp = Sketchup.active_model.entities.add_group(loose_by_layer[layer])
# use the layer from the original loose entities for the group
gp.layer = layer
# and fix the Layer0 association of the ones in the group
gp.definition.entities.each {|entity| entity.layer = nil}
rescue => e
# note: this reports the exception but lets the method
# continue to process the rest of the layers
UI.messagebox(e.message)
puts e.message
puts e.backtrace
end
end
Sketchup.active_model.commit_operation
nil
end
Similar with CAD work but there are times as we all know
I mean it could just as simply as this…
I don’t necessarily want to discard all layer information, just make all loose geometry untagged.
For me, with PowerCADD, which doesn’t support groups across layers:
- Edit all layers on
- Select All
- Group
Produces one group on each layer as preparation before exporting to SketchUp.
Steve’s ruby script sounds like it does the job. I’m not used to implementing plain text files for extensions. What’s the best way to use it? Do you run it in a command line, or can you load it like an extension?
I usually simplify and isolate the dwg work I put into SketchUp. I place in a new CAD file. Only one Layer called “Layer0” but I group what I need grouped beforehand–usually group what’s on each layer originally.
Sound like what I mostly end up doing. I created a template called dwg export with just Layer 0 in it.
What I provided was meant as a demonstration of possibility. It does evil things like adding a method to the global namespace. It could easily be wrapped as an extension if it seems useful and there is interest.
To use it as is, you would copy the code into the SketchUp Ruby Console and then type group_by_layer.
There are so many workflows or usecases or just general desires about SU integrating with DWG, it really just needs a full discussion of “what are you trying to accomplish” to build it out. I know some folks also want to use LayOut so that got beefed up a bit. I know this thread already has some PM eyeballs, but it’s great to see the workarounds here. (c:
Also… its not Layer0 anymore, it’s “untagged”. =oP
One thing “what you are trying to accomplish” is not break SketchUps unwritten rule: Don’t put raw geometry on other layers when importing (don’t TAG raw geometry). Everyone can agree with that.
I think there are a couple of cases where breaking the rule can be justified. Also, the problems with geometry on layers only pop up when you turn layers off. If you never do that, you have a sloppy model but no problems.
I know, but not everyone is on 2020, so I feel compelled to write both Layer and Tag because people could search for either. Of course, I’ve never been a fan of saying he/she because it’s more like legalese than natural speech, but I digress.