Import dwg elements to Layer0
-
@pbacot said:
I select the component and paste the script in ruby console. Nothing happens...
Sam's script works on raw geometry...
This one should drill down and gives a countdown as Status Text, so you know it's working...
Tig's plugin is probably better and may be faster...
##--------------------------------------------------------------------------------------- # move to Layer0 t1 = Time.now model = Sketchup.active_model defs = model.definitions grps_comps =[] defs.each{|d| next if d.image? ins=[] d.instances.each{|i|ins << i.name} grps_comps << d.instances unless ins.empty? } draw_elements = [] count = 0 grps_comps.each{|c| draw_elements << [c[0].definition.entities.find_all{|e| e.valid?}] } model.start_operation("move to 0") draw_elements.flatten!.each{|e| count+=1 e.layer='Layer0' rescue next Sketchup;;set_status_text((" #{count} of #{draw_elements.length}" ),SB_PROMPT) # break if count == 10 } model.commit_operation puts Time.now - t1 ##---------------------------------------------------------------------------------------
john
-
@pbacot said:
I select the component and paste the script in ruby console. Nothing happens. The console returns:
#<Sketchup;;Entities;0x007fde7b0884a8>
Sorry, I took raw geometry to mean all entities not in a group or component. Also, the script works on the model not a selection.
Since this is an import, I would assume that all definitions exist because at least one instance was created during the import process. Therefore, you should only need to modify the layer of the entities in the definition which will automatically redefine each instance.
So, again for the model and not a selection
Sketchup.active_model.definitions.each{|cd|cd.entities.each{|e|e.layer='Layer0'}}
-
Thanks! This seems to be working, but seems to have the same problem as "default layer" plugin. Taking a long time. I am running it while I have breakfast and see what happens. Wish there were a right way to use dwg files. SU is really behind in all aspects of working with these files.
-
@pbacot said:
...Taking a long time...
it took about 18 minutes to do 297345 edges/faces in my test file...
the problem is it has to find every one and move them one at a time...
you could run it in the background and work on a different instance of SU, on a different model...
I do that sometime when rendering, like they can on a PC...
john
-
Maybe (?) TIGs LayerWatcher can help here too?
http://sketchucation.com/plugin/1496-tig_layerwatcher -
No doubt cleaning up the DWG before import would help.
-
It took something like about that long.
I have times when I am importing my own work in dwg and I can do some things beforehand. How do you "cleanup" objects being on LayerO? with blocks on assigned layers in CAD? You can't really, if your CAD doesn't support that.
What would be best is that blocks keep their layers and entities import at layerO, just like SketchUp is supposed to be used. However the opposite is how SU makes imports.
The case I am working on is cleaning up someone file that was given to me. The third scenario is receiving a cad file from another source to import. Part of the "cleanup" should be automatic.
If one is just going to give up on the imported layers (for blocks-components) then the fastest thing to do is just delete the imported layers. Entities then go to Layer0 instantaneously.
-
Peter, if you PM me an example 'layered' dxf, there is an idea i would like to try...
may come to nothing...
john
-
Have you try to import using FreeDXF plugin? It does great job with layers.
-
No I haven't tried that plugin. I'll take a look. Usually I receive dwg files but I can ask for DXF. Peter
Advertisement