Repository navigation
Expand file tree
/
Copy pathcreate_specific_rendermaterial.py
More file actions
55 lines (48 loc) · 1.68 KB
/
Copy pathcreate_specific_rendermaterial.py
File metadata and controls
55 lines (48 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# DO NOT EDIT THIS FILE DIRECTLY. This is generated from a literate program
# with the VSCode extension Literate Programming (jesterking.literate).
#
# These literate programs are Rhino 3D scripts explaining how scripting works
# in Rhino 3D with Python.
#
# Read the literate programs at:
# https://jesterking.github.io/literate
#
# This code is part of the repository:
# https://github.com/jesterKing/rhipy
#
# The Literate Programming extension repository is at:
# https://github.com/jesterKing/literate
#
# Licensed under Apache 2.0
# See https://github.com/jesterKing/rhipy/blob/master/LICENSE
#
# Copyright (C) Nathan 'jesterKing' Letwory
#
import System
import Rhino.Display
import Rhino.Render
import scriptcontext
import random
# get object selection
object_selection = [ob for ob in scriptcontext.doc.Objects if ob.IsSelected(False)]
# only if we have a selection do the work
if object_selection:
# create material
render_material = Rhino.Render.RenderContent.Create(
Rhino.Render.RenderMaterial.PaintMaterialGuid,
Rhino.Render.RenderContent.ShowContentChooserFlags.None,
scriptcontext.doc)
render_material.BeginChange(Rhino.Render.RenderContent.ChangeContexts.Program)
render_material.Name = "PYSCRIPTCREATED " + System.Guid.NewGuid().ToString()
random_color = Rhino.Display.Color4f(
random.random(),
random.random(),
random.random(),
1.0)
render_material.SetParameter("color", random_color)
render_material.EndChange()
# assign
for ob in object_selection:
print("Adding material", render_material.Name, "to", ob)
ob.RenderMaterial = render_material
ob.CommitChanges()