From a695741a4858b429f17db6e9cce6a171c32d769d Mon Sep 17 00:00:00 2001
From: Campbell Barton <ideasman42@gmail.com>
Date: Wed, 25 Aug 2010 01:22:50 +0000
Subject: [PATCH] updates to blender rna api

---
 io_import_images_as_planes.py   |  4 +---
 io_import_scene_mhx.py          |  6 +-----
 object_cloud_gen.py             | 13 +++++-------
 space_view3d_materials_utils.py | 36 ++++++++++++++++-----------------
 4 files changed, 24 insertions(+), 35 deletions(-)

diff --git a/io_import_images_as_planes.py b/io_import_images_as_planes.py
index 87f0c6c6a..ea6528422 100644
--- a/io_import_images_as_planes.py
+++ b/io_import_images_as_planes.py
@@ -250,9 +250,7 @@ def getTexture(path, img):
     # ... otherwise create a new one and apply mapping.
     if not tex:
         name = path.rpartition('\\')[2].rpartition('.')[0]
-        tex = bpy.data.textures.new(name=name)
-        tex.type = 'IMAGE'
-        tex = tex.recast_type()
+        tex = bpy.data.textures.new(name=name, type='IMAGE')
         tex.image = img
 
     return tex
diff --git a/io_import_scene_mhx.py b/io_import_scene_mhx.py
index a669327be..b8e54e9ba 100644
--- a/io_import_scene_mhx.py
+++ b/io_import_scene_mhx.py
@@ -779,11 +779,7 @@ def parseTexture(args, tokens):
 	global todo
 	if verbosity > 2:
 		print( "Parsing texture %s" % args )
-	name = args[0]
-	tex = bpy.data.textures.new(name)
-	typ = args[1]
-	tex.type = typ
-	tex = tex.recast_type()
+	tex = bpy.data.textures.new(name=args[0], type=args[1])
 	loadedData['Texture'][name] = tex
 	
 	for (key, val, sub) in tokens:
diff --git a/object_cloud_gen.py b/object_cloud_gen.py
index 5122871ea..4a08f4840 100644
--- a/object_cloud_gen.py
+++ b/object_cloud_gen.py
@@ -461,7 +461,7 @@ class GenerateCloud(bpy.types.Operator):
             bpy.ops.object.particle_system_add()
 
             #Particle settings setting it up!
-            cloudParticles = cloud.active_particle_system
+            cloudParticles = cloud.particle_systems.active
             cloudParticles.name = "CloudParticles"
             cloudParticles.settings.frame_start = 0
             cloudParticles.settings.frame_end = 0
@@ -507,11 +507,10 @@ class GenerateCloud(bpy.types.Operator):
 
             # Add a texture
             vMaterialTextureSlots = cloudMaterial.texture_slots
-            cloudtex = main.textures.new("CloudTex")
-            cloudMaterial.add_texture(cloudtex, 'ORCO')
-            cloudtex.type = 'CLOUDS'
+            cloudtex = main.textures.new("CloudTex", type='CLOUDS')
             cloudtex.noise_type = 'HARD_NOISE'
             cloudtex.noise_scale = 2
+            cloudMaterial.add_texture(cloudtex, 'ORCO')
 
             # Add a force field to the points.
             cloudField = bounds.field
@@ -528,10 +527,8 @@ class GenerateCloud(bpy.types.Operator):
             #bpy.ops.ptcache.bake(bake=False)
 
             # Add a Point Density texture
-            cloudPointDensity = main.textures.new("CloudPointDensity")
-            cloudPointDensity.type = 'POINT_DENSITY'
-            cloudMaterial.add_texture(cloudPointDensity, 'ORCO')
-            pDensity = vMaterialTextureSlots[1].texture
+            pDensity = main.textures.new("CloudPointDensity", 'POINT_DENSITY')
+            cloudMaterial.add_texture(pDensity, 'ORCO')
             vMaterialTextureSlots[1].use_map_density = True
             vMaterialTextureSlots[1].use_rgb_to_intensity = True
             vMaterialTextureSlots[1].texture_coords = 'GLOBAL'
diff --git a/space_view3d_materials_utils.py b/space_view3d_materials_utils.py
index 0a2abea39..d3c8252cc 100644
--- a/space_view3d_materials_utils.py
+++ b/space_view3d_materials_utils.py
@@ -398,25 +398,23 @@ def check_texture(img,mat):
     #makes a texture if needed
     #adds it to the material if it isn't there already
 
-    try: 
-        tex = bpy.data.textures[img.name]
-    except:
-        tex = bpy.data.textures.new(name=img.name)
-    finally:
-        tex.type = 'IMAGE'
-        tex = tex.recast_type()
-        tex.image = img
-
-        #see if the material already uses this tex
-        #add it if needed
-        found = False
-        for m in mat.texture_slots:
-            if m and m.texture == tex:
-                found = True
-                break
-        if not found and mat:
-            mat.add_texture(tex, texture_coordinates='UV', map_to='COLOR')
-    
+    tex = bpy.data.textures.get(img.name)
+
+    if tex is None:
+        tex = bpy.data.textures.new(name=img.name, type='IMAGE')
+
+    tex.image = img
+
+    #see if the material already uses this tex
+    #add it if needed
+    found = False
+    for m in mat.texture_slots:
+        if m and m.texture == tex:
+            found = True
+            break
+    if not found and mat:
+        mat.add_texture(tex, texture_coordinates='UV', map_to='COLOR')
+
 def texface_to_mat():
     # editmode check here!
     editmode = False
-- 
GitLab