create light object in python scripting & blender

Votes : 5
1422
bpy.ops.object.lamp_add( 
    type='POINT', 
    view_align=False, 
    location=(0.0, 0.0, 0.0), 
    rotation=(0.0, 0.0, 0.0), 
    layers=( False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False)
)        
typetype ( enum in [‘POINT’, ‘SUN’, ‘SPOT’, ‘HEMI’, ‘AREA’], (optional) ) –
Type
POINT Point, Omnidirectional point light source.
SUN Sun, Constant direction parallel ray light source.
SPOT Spot, Directional cone light source.
HEMI Hemi, 180 degree constant light source.
AREA Area, Directional area light source.
view_align (boolean, (optional)) – Align to View, Align the new object to the view
location (float array of 3 items in [-inf, inf], (optional)) – Location, Location for the newly added object
rotation (float array of 3 items in [-inf, inf], (optional)) – Rotation, Rotation for the newly added object
layers (boolean array of 20 items, (optional)) – Layer

Samples

.1 There will be create sun lamp located at 5 to x-axis, 2 to y-axis and 1 to z-axis.

bpy.ops.object.lamp_add(type='SUN',location=(5,2,1))

.2 Create spot lamp with location and rotation parameters. Assign current active object into lamp1 object variable. And then add name to current active lamp object.

bpy.ops.object.lamp_add(
    type='SPOT',
    location=(-0.7,-0.5,0.3),
    rotation=(1.223,-0.960),
)
lamp1 = bpy.context.active_object.data
lamp1.name="key Light"

.3 Change lamp type, If lamp will be sky or environment.

if light_type in ['SKY', 'ENV']:
        lamp.type = 'HEMI'

.4 First calculate rotation by using math library, then create area lamp by using rotation parameters.

import bpy
from math import pi

bpy.ops.object.lamp_add(type='AREA', ... ,  rotation=(0, (pi * degrees / 180), 0))

.5 Change last lamp energy.

bpy.data.lamp[-1].energy = 0.6
asked 4 months,13 days ago

What is the codrate ?

codrate.com is a standard, fast cross browsing and highly versatile site. It is useful for many large number of Program Development Industries. So you can get support form Codrators , who are the codrate's joiners around world to help your program developments, You can answer other codrator's questions. Communicate with them. Share your knowledge with them. Do you have an interest in programming, So publish your articles about programming. It will help to maintain your professional co-profile. Actually codrate.com is not such as a regular web site. It will be gave new experience, best narrow cross-browser view, reduce processing time to receive browsing request, it's mean do not wasting your time to browsing codrate's web pages because it has been upgrade always modern coding ways. So, what do you waiting for ?. Try your own.

Copyright 2015 Pride - Company. Design by Esila