Last active
January 26, 2022 21:18
-
-
Save jimmac/c486eb3be7e5afee156f20671d3ca212 to your computer and use it in GitHub Desktop.
import SVG symbolic icons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
from pathlib import Path | |
import numpy as np | |
import os | |
p = Path('/var/home/jimmac/SparkleShare/wallpaper-assets/43/experiments/svg-icons') | |
scene = bpy.context.scene | |
collections = set(scene.collection.children) | |
offset = np.array([0.0, 0.0, 0.0]) | |
delta = np.array([0.1, 0.0, 0.0]) # visibly offset them | |
col_icons = bpy.data.collections['icons'] | |
for f in sorted(p.glob('*.svg')): | |
bpy.ops.import_curve.svg(filepath=str(f)) | |
new_collection = set(scene.collection.children) - collections | |
collections = set(scene.collection.children) | |
for aCollection in new_collection: | |
for object in aCollection.objects: | |
object.select_set(True) | |
bpy.ops.transform.resize(value=(10,10,0)) #scale up | |
bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='MEDIAN') | |
bpy.ops.object.location_clear(clear_delta=False) | |
bpy.ops.transform.translate(value=(offset)) #offset a little | |
offset = offset + delta | |
for object in aCollection.objects: | |
# set icon material | |
object.material_slots[0].material = bpy.data.materials['icon'] | |
# Loop through all collections the obj is linked to | |
for coll in object.users_collection: | |
# Unlink the object | |
coll.objects.unlink(object) | |
# Link each object to the target collection | |
col_icons.objects.link(object) | |
object.name = str(os.path.basename(f)) | |
object.select_set(False) | |
bpy.data.collections.remove(aCollection) #remove the original collection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment