Created
June 23, 2017 00:07
-
-
Save RohanBhanderi/9865cd02e109a3ede697866cb202660d to your computer and use it in GitHub Desktop.
Blender Plugin for Adobe Stock
This file contains hidden or 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 | |
import requests | |
import json | |
class GetOperator(bpy.types.Operator): | |
"""Tooltip""" | |
bl_idname = "object.get_operator" | |
bl_label = "Search" | |
@classmethod | |
def poll(cls, context): | |
return context.active_object is not None | |
def execute(self, context): | |
json_data = self.__get_stock_data("http://httpbin.org/ip") | |
print(json_data["origin"]) | |
print(context.scene.search_stock) | |
# TODO get .obj file from Adobe Stock | |
# TODO call self.__render_object(file_loc) to render the .obj file | |
return {'FINISHED'} | |
def __get_stock_data(self, url): | |
try: | |
print(url) | |
return requests.get(url).json() | |
except requests.exceptions.HTTPError as e: | |
print("HTTP error: %d" % e.code) | |
def __render_object(self, file_loc): | |
imported_object = bpy.ops.import_scene.obj(filepath=file_loc) | |
bpy.ops.view3d.camera_to_view_selected() | |
class AdobeStockPanel(bpy.types.Panel): | |
"""Creates a Panel in the Object properties window""" | |
bl_label = "Adobe Stock" | |
bl_idname = "OBJECT_PT_ASTOCK" | |
bl_space_type = 'VIEW_3D' | |
bl_region_type = 'TOOLS' | |
bl_context = "objectmode" | |
def draw(self, context): | |
layout = self.layout | |
row = layout.row() | |
row.label(text="Adobe Stock", icon='WORLD_DATA') | |
row = layout.row() | |
row.prop(context.scene, "search_stock") | |
row = layout.row() | |
row.operator(GetOperator.bl_idname) | |
def register(): | |
bpy.utils.register_class(GetOperator) | |
bpy.utils.register_class(AdobeStockPanel) | |
bpy.types.Scene.search_stock = bpy.props.StringProperty( | |
name="", | |
description="Search 3D objects from Adobe Stock", | |
default="Search" | |
) | |
def unregister(): | |
bpy.utils.unregister_class(GetOperator) | |
bpy.utils.unregister_class(AdobeStockPanel) | |
if __name__ == "__main__": | |
register() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment