-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreate_doublesided_rendermaterial.py
79 lines (70 loc) · 2.58 KB
/
create_doublesided_rendermaterial.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# 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(
System.Guid("E6CD1973-B739-496E-AB69-32957FA48492"),
Rhino.Render.RenderContent.ShowContentChooserFlags.None,
scriptcontext.doc)
render_material.BeginChange(Rhino.Render.RenderContent.ChangeContexts.Program)
render_material.Name = "Double-Sided Material " + System.Guid.NewGuid().ToString()
front_material = Rhino.Render.RenderContent.Create(
Rhino.Render.RenderMaterial.MetalMaterialGuid,
render_material,
"front",
Rhino.Render.RenderContent.ShowContentChooserFlags.None,
scriptcontext.doc)
back_material = Rhino.Render.RenderContent.Create(
Rhino.Render.RenderMaterial.PlasterMaterialGuid,
render_material,
"back",
Rhino.Render.RenderContent.ShowContentChooserFlags.None,
scriptcontext.doc)
random_color1 = Rhino.Display.Color4f(
random.random(),
random.random(),
random.random(),
1.0)
random_color2 = Rhino.Display.Color4f(
random.random(),
random.random(),
random.random(),
1.0)
# set color for front material
front_material.BeginChange(Rhino.Render.RenderContent.ChangeContexts.Program)
front_material.SetParameter("color", random_color1)
# set color for back material
back_material.BeginChange(Rhino.Render.RenderContent.ChangeContexts.Program)
back_material.SetParameter("color", random_color2)
render_material.EndChange()
# assign
for ob in object_selection:
print("Adding material", render_material.Name, "to", ob)
ob.RenderMaterial = render_material
ob.CommitChanges()