Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDEA Improvement: Need Help to recursively import RDCs from a Folder and store each element into a Collection #128

Closed
fpibbs opened this issue Jan 10, 2021 · 2 comments
Labels
discussion This is not really an issue but a thread for the users to exchange about teh software

Comments

@fpibbs
Copy link

fpibbs commented Jan 10, 2021

As written in the title and kindly need @eliemichel help, my script is almost ready but I have some troubles because it stores only the first element on the collection under its named from file.
Hope it can help:

import bpy
import os
import sys
import glob

directory_im = 'C:/Users/fcapp/Desktop/LowPoly2/'
files = glob.glob(directory_im + ".rdc")
for f in files:
head, tail = os.path.split(f)
collection_name = tail.replace('.rdc', '')
bpy.ops.import_rdc.google_maps(filepath=(f), filter_glob="
.rdc", max_blocks=-1)
myCol = bpy.data.collections.new(collection_name)
bpy.context.scene.collection.children.link(myCol)
for ob in bpy.context.selected_objects:
myCol.objects.link(ob)

image

Where am I wrong? Need to solve that...

Current Configuration:
Blender 2.91, Maps Model Importer 0.3.5, RenderDOC 1.10, Chrome X64 on Windows Pro 87.0.4280.141( 64 bit)

@fpibbs
Copy link
Author

fpibbs commented Jan 11, 2021

Solved by RainerTrummer- (https://devtalk.blender.org/t/need-help-to-recursively-import-rdcs-from-a-folder-and-store-each-element-into-a-collection/17019/9?u=frankiepibbs) on Blender Forum:

import bpy
import os
import sys
import glob

directory_im = 'C:\\LowPoly2\\'
files = glob.glob(directory_im + "*.rdc")

# helper method to create a new LayerCollection
# also setting it to the active LayerCollection
# the Google Maps importer then puts the objects into that LayerCollection automatically
def create_coll(parent_layer_collection, collection_name):
	new_col = bpy.data.collections.new(collection_name)
	parent_layer_collection.collection.children.link(new_col)
	new_child_layer_coll = parent_layer_collection.children.get(new_col.name)
	
	bpy.context.view_layer.active_layer_collection = new_child_layer_coll
	
	return new_child_layer_coll
	

# create a master collection to batch import the files to, or re-use the currently active collection in the scene - up to you
master_collection =  bpy.context.view_layer.active_layer_collection

# iterate over files
for f in files:
	head, tail = os.path.split(f)
	collection_name = tail.replace('.rdc', '')
	
	# create a new LayerCollection to import the objects to
	# I am storing the reference to it here in case you need to run further actions on it
	# e.g. changing color etc etc
	myCol = create_coll(master_collection, collection_name)

	# run the importer, it will work within the new sub-collection
	bpy.ops.import_rdc.google_maps(filepath=(f), filter_glob=".rdc", max_blocks=-1)

Hope this Helps

@eliemichel eliemichel added the discussion This is not really an issue but a thread for the users to exchange about teh software label Jan 16, 2021
eliemichel added a commit that referenced this issue Jan 16, 2021
@eliemichel
Copy link
Owner

Thanks for sharing this, I've added a link to this issue in the readme to help interested people to find it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion This is not really an issue but a thread for the users to exchange about teh software
Projects
None yet
Development

No branches or pull requests

2 participants