Boston Python Workshop 5/Friday/Windows set up Python: Difference between revisions

imported>Jesstess3
(Created page with '== Download and install Python == If you believe you already have Python installed, please let a staff member know before completing these steps. <ol> <li>Click http://python.o…')
 
Line 36:
</ol>
 
the materials doesn`t cgrehehnae is my script:import bpyimport randomclass random_mat_panel(bpy.types.Panel): bl_idname = matPanel bl_label = Random Material Assigner bl_space_type = VIEW_3D' bl_region_type = Tools' def draw(self, context): layout = self.layout layout.operator( object.random_material )class mat_assigner(bpy.types.Operator): bl_idname = object.random_material bl_label = Assign Random Material bl_description = Use this to assign a random material bl_options = { REGISTER', UNDO'} searchString = bpy.props.StringProperty(name= Filter ) seedProp = bpy.props.IntProperty(name= Seed ) availableMaterials = [] def invoke(self, context, event): self.randomize() return { FINISHED'} def check(self, context): self.randomize() def randomize(self): random.seed(self.seedProp) self.availableMaterials = [] for mat in bpy.data.materials: if(self.searchString.lower() in mat.name.lower()): self.availableMaterials.append(mat) for ob in bpy.context.selected_objects: randNum = random.randint(0, len(self.availableMaterials)-1) active_material = self.availableMaterials[randNum] def execute(self, context): return { FINISHED'}bpy.utils.register_class(mat_assigner)bpy.utils.register_class(random_mat_panel)
== Put Python on the PATH ==
 
You might have noticed that you typed a "full path" to the Python application above when launching Python (<code>python.exe</code> is the application, but we typed <code>\Python27\python.exe</code>). In this step, you will configure your computer so that you can run Python without typing the ''Python27'' directory name.
 
=== Get to System Properties ===
 
# Open up "My Computer" by clicking on the Start menu or the Windows logo in the lower-left hand corner, and navigate to "My Computer" (for Windows XP) or "Computer" (For Vista and Windows 7).
# ''Right-click'' on the empty space in the window, and choose ''Properties''.
 
==== If you're using XP ====
 
A window labeled "System Properties" will pop up.
 
# Click the "Advanced" tab.
 
==== If you're not using XP ====
A window labeled "View basic information about your computer" will appear.
 
# In this window, click "Advanced system settings"
 
A window with the title "System Properties" will appear.
 
=== Edit the Path ===
 
# Within System Properties, make sure you are in the tab labeled "Advanced".
# Click the button labeled "Environment Variables".
#* A window labeled "Environment Variables" will appear.
# In this window, the screen is split between "User variables" and "System variables". Within "System variables", scroll down and find the one labeled '''Path'''. Click the "Edit..." button.
#* A window with the "Variable name" and the "Variable value" should appear. The "Variable value" will already have some text in it; click in the box to unhighlight it (we don't want to accidentally delete that text).
# In the "Variable value" box, scroll to the end. Add the following text, and hit OK. Make sure to include the semicolon at the start! <pre>;c:\python27\;c:\python27\scripts</pre>
# Hit "OK" to close out the system properties changes.
# Test your change:
## Open up a <b>new</b> command prompt: you do this the same way you did above when installing python. This needs to be a new command prompt because the changes you just made didn't take affect in prompts that were already open.
## Type <code>python</code> into the command prompt to start Python
## Notice that you now get a Python interpreter, indicated by the change to a <code>>>></code> prompt.
## Exit the Python prompt by typing <pre>exit()</pre> and hitting enter. Now you're back at the Windows command prompt (<code>C:\</code>).
 
== Success! ==
Anonymous user