Importing file to layer - appears impossible

Is is possible to “import” a file into a target file so that the layers and objects in the imported file are sublayers under a selected layer in the target file? So far all efforts result in the imported objects being in previously existing layers in the target file, not in separate layers. I have tried Import, Insert, and creating a worksession with files to be imported as attached files and then using Copy with the Inplace option.

I have four files, each with the same layer names and structure. Let’s name them BoatA, BoatB, BoatC and BoatD.

I create a new file named AllBoats, and in the file I create layers A, B, C and D.

I want to import the layers and objects in source file BoatA into AllBoats and have them under layer A in AllBoats. Next I want to import the layers and objects in source file BoatB into AllBoats and have them under layerB in AllBoats. And so forth.

This appears impossible to do.
:confounded: :grimacing:

I’ll see if I can make something that works…

See if this does it -
ImportUnderCurrentLayer.py (1.2 KB)

Works in a simple case at least… I can make it so you choose a layer as well if that is easier.

To use the Python script use RunPythonScript, or a macro:

_-RunPythonScript "Full path to py file inside double-quotes"

-Pascal

It doesn’t work.

The first time I run the script the file to be imported is put in the current layer of the open file.

The second time I run the script the layer in the open file which now has sublayers with the same names as the layers in the file to be imported is put in the now current layer of the open file, and the objects in the file to be imported are put into the existing layers with the same names.

Do you need a simple set of example files?

Yeah, probably - my test was ultra simple, though, it ought not to matter, I guess it does…

-Pascal

@davidcockey that is what is expected - as I mentioned, I can make it ask you for a layer. Does it work to the extent that you set the right layer current before running it?

-Pascal

@pascal Here is an example:

Source files:
Updated source files below.

Destination File:
All In One.3dm (2.8 MB)

Desired outcome:
All In One Desired.3dm (3.0 MB)

I see, OK - so you have the top level layer in the incoming file and in the parent file as well… so I need to ditch the top level layer in one or the other. Bringing in a file without that top level layer seems OK.
image

I’ll see if I can sort that out.

-Pascal

@pascal Incorrect. The “top level layer” is not in the file being imported. The name of the “top level layer” may or may not be the same as as name of the file being imported into that layer. In the example files I provided one source file is Rowboat11 and it needs to be imported under Rowboat.

well, where it looks like it is choking is here-
image

If I lose that Canoe layer in the incoming file and make Canoe current, it seems OK. That is one problem, there may be others…

-Pascal

@Pascal My mistake. I meant to eliminate the top layers in the example source files. Below are revised source files.
Canoe.23dm.3dm (2.9 MB)
Rowboat112.3dm (2.8 MB)
Kayak2.3dm (2.9 MB)

In an ideal world I’d like to not have problems if a top level layer of the file being imported matches a top level layer in the target file.

Yeah, it can be done, I just need to scratch those few remaining brain cells.
@davidcockey - I had another go at it - updated above - is that any better?

-Pascal

my workflow / workarround for stuff like this:
open / import file to a separate document,
prepare / arrange layers
copy paste to target document

I have tried that. All objects being pasted are put in the current layer. Only the objects are copied and pasted, not the layer structure.

drawing some curves on a frist document
copy paste
rename parent layer doc1 → doc2
move objects
copy back
… result is as expected here - layer structure kept

i am missing something ?
did not find any preferences that might influence this behavior

I need to copy layer structure and objects from one file to another. When I do that the objects go into the current layer.

If I want to create a new set of layers with copies of objects in a single file I use “Duplicate layer and objects” and select the appropriate options.

Still not as desired.

I opened All In One.3dm.

Selected Canoe as current layer.
RunPythonScript and selected Canoe2.3dm as file to import.
As desired, objects and layers from Canoe2.3dm appear under layer Canoe in All In One.3dm. This is as desired.

Select Rowboat as current layer.
RunPythonScript and selected Rowboat112.3dm as file to import.
Objects from Rowboat112.3dm appear in corresponding layers under layer Canoe in All In One.3dm
Desire was for the imported objects and layer structure from Rowboat112.3dm to appear under current layer of Rowboat in All In One.3dm

Select Kayak as current layer.
RunPythonScript and selected Kayak2.3dm as file to import.
Objects from Kayak2.3dm appear in corresponding layers under layer Canoe in All In One.3dm
Desire was for the imported objects and layer structure from Kayak2.3dm to appear under current layer of Kayak in All In One.3dm

Results from above (corrected):Wrong files uploaded

Hm… I get this structure if I make each layer current in turn:

that is what we are shooting for, right?

-Pascal

@Pascal That is what I want but not what I get after making each original layer current in turn.

I uploaded a couple of wrong files. Too many iterations. Now corrected.

Saved results after following the steps described above and making each original layer current in turn:
What I get file.3dm (3.1 MB)

What I see on the screen:

Rhino 7 SR11 2021-10-5 (Rhino 7, 7.11.21278.07001, Git hash:master @ f37a05078eef4d95a64a348c29da91be62159921)
License type: Commercial, build 2021-10-05
License details: Cloud Zoo

Windows 10.0.19043 SR0.0 or greater (Physical RAM: 64Gb)

Computer platform: DESKTOP

Standard graphics configuration.
Primary display and OpenGL: NVIDIA GeForce RTX 2080 Ti (NVidia) Memory: 11GB, Driver date: 8-5-2021 (M-D-Y). OpenGL Ver: 4.6.0 NVIDIA 471.68
> Accelerated graphics device with 4 adapter port(s)
- Windows Main Display attached to adapter port #0

OpenGL Settings
Safe mode: Off
Use accelerated hardware modes: On
Redraw scene when viewports are exposed: On
Graphics level being used: OpenGL 4.6 (primary GPU’s maximum)

Anti-alias mode: 4x
Mip Map Filtering: Linear
Anisotropic Filtering Mode: High

Vendor Name: NVIDIA Corporation
Render version: 4.6
Shading Language: 4.60 NVIDIA
Driver Date: 8-5-2021
Driver Version: 30.0.14.7168
Maximum Texture size: 32768 x 32768
Z-Buffer depth: 24 bits
Maximum Viewport size: 32768 x 32768
Total Video Memory: 11 GB

Rhino plugins that do not ship with Rhino
C:\Program Files\Orca3D V2\Orca3D.rhp “Orca3D” 2.0.22.0

Rhino plugins that ship with Rhino
C:\Program Files\Rhino 7\Plug-ins\Commands.rhp “Commands” 7.11.21278.7001
C:\Program Files\Rhino 7\Plug-ins\rdk.rhp “Renderer Development Kit”
C:\Program Files\Rhino 7\Plug-ins\RhinoRenderCycles.rhp “Rhino Render” 7.11.21278.7001
C:\Program Files\Rhino 7\Plug-ins\rdk_etoui.rhp “RDK_EtoUI” 7.11.21278.7001
C:\Program Files\Rhino 7\Plug-ins\rdk_ui.rhp “Renderer Development Kit UI”
C:\Program Files\Rhino 7\Plug-ins\NamedSnapshots.rhp “Snapshots”
C:\Program Files\Rhino 7\Plug-ins\RhinoCycles.rhp “RhinoCycles” 7.11.21278.7001
C:\Program Files\Rhino 7\Plug-ins\Toolbars\Toolbars.rhp “Toolbars” 7.11.21278.7001
C:\Program Files\Rhino 7\Plug-ins\3dxrhino.rhp “3Dconnexion 3D Mouse”
C:\Program Files\Rhino 7\Plug-ins\Displacement.rhp “Displacement”
C:\Users\dcock\AppData\Roaming\McNeel\Rhinoceros\packages\7.0\PanelingTools\2021.3.2.446\PanelingTools.rhp “PanelingTools”
C:\Users\dcock\AppData\Roaming\McNeel\Rhinoceros\packages\7.0\SectionTools\2021.4.21.831\SectionTools.rhp “SectionTools”

I tried again with Orca not loaded - same results.

@Pascal - can you upload your latest script.

Hi David - here’s what seems to work here -

ImportUnderCurrentLayer.py (1.1 KB)

-Pascal