ihWC4D模型
ihWC4D模型
FlipFlop是一个可以按类型独显的脚本。它可以把跟它同类型的对象隐藏,它和其他对象都保持不变。可以快速的独显灯光,模型对象或者其他的类型的对象。
ihWC4D模型
ihWC4D模型
那么如何判断类型和归类的?ihWC4D模型
我根据C4D的可操作对象类型:参数化的基础模型、各种生成器、变形器等等做了手动的划分,这样让C4D对象按照我们的习惯做出分类。
ihWC4D模型
新建一个solo类型并初始化它的参数。
ihWC4D模型
ihWC4D模型
class solo:
ihWC4D模型
def __init__(self):
ihWC4D模型
self.doc = c4d.documents.GetActiveDocument()
ihWC4D模型
# 参数化对象
ihWC4D模型
self.meshes = [5100, 5120, 5170, 5162, 5164, 5168, 5174, 5160, 5163, 5171, 5172, 5165, 5167, 5161, 5166, 5169,
ihWC4D模型
5159, 5140, 1019268,1007455]
ihWC4D模型
# 参数化样条线
ihWC4D模型
self.base_spline = [5101, 5188, 5184, 5187, 5179, 5176, 5180, 5177, 5185, 5178, 5183, 5182, 5181, 5175, 5186]
ihWC4D模型
ihWC4D模型
# 变形器
ihWC4D模型
self.deformer = [431000028, 1024542, 5129, 5131, 5145, 5133, 1021284, 5134, 1002603, 1024543, 5147, 5148,
ihWC4D模型
5108, 1024529, 1024544, 1021280, 1024476, 1001003, 1019774, 1024552, 5143, 1008982, 1008796,
ihWC4D模型
1019768, 5146, 1018685, 1019221, 1021318, 5149, 1035447, 5128, 1019358, 1019222]
ihWC4D模型
# 效率生成器
ihWC4D模型
self.resource = [1007455, 1054750, 100004007, 465002101, 1039859, 1018544,465002101]
ihWC4D模型
ihWC4D模型
# 其他生成器
ihWC4D模型
self.other_gen = [1023866, 1001002, 5150, 5125, 5142, 431000174, 1011010, 1010865, 5126, 5107, 5189, 5118, 5116,
ihWC4D模型
1019396, 5117, 1039861, 1018791, 1036557, 1018545, 440000054, 1018655]
ihWC4D模型
# 效果器
ihWC4D模型
self.effectors = [1018881, 1018561, 1018883, 1019234, 1021287, 1025800, 1018889, 440000234, 1018775, 1018643,
ihWC4D模型
1018935, 1018774, 1019351, 1021337, 440000219, 440000255]
ihWC4D模型
# 域
ihWC4D模型
self.field = [440000277, 440000269, 440000281, 1040448, 440000274, 440000282, 440000272, 440000243, 440000283,
ihWC4D模型
440000267, 1040449, 440000280, 440000268, 440000266,5119,5113,5115,5112,5111,5114,5124,5110,5119,
ihWC4D模型
1041451]
ihWC4D模型
ihWC4D模型
# 环境
ihWC4D模型
self.env = [5122, 5121, 5104]
ihWC4D模型
ihWC4D模型
# 灯光
ihWC4D模型
self.lights = [1011146, 5102, 1036751, 5105, 1036754, 5106, 5140, 1036757]
ihWC4D模型
ihWC4D模型
# 相机
ihWC4D模型
self.cameras = [5140, 5103]
ihWC4D模型
ihWC4D模型
self.dic = {"meshes": self.meshes, "base_spline": self.base_spline, "deformer": self.deformer,
ihWC4D模型
"resource": self.resource,
ihWC4D模型
"other_gen": self.other_gen, "effectors": self.effectors, "field": self.field, "env": self.env,
ihWC4D模型
"lights": self.lights,
ihWC4D模型
"cameras": self.cameras}
ihWC4D模型
ihWC4D模型
获得分类之后,根据预期的操作方法:点击icon,即可讲选中对象的同类型对象实现隐藏。并再次点击时,恢复到上一次点击之前的同类对象状态。
ihWC4D模型
接下来依次解决两个问题:
ihWC4D模型
1.找到对象的同类对象,并设置响应状态。
ihWC4D模型
2.存储原始状态的json及读取。
ihWC4D模型
ihWC4D模型
找到同类对象 ihWC4D模型
根据之前设置好的分类,通过比对选中对象的类型ID,筛选出同类。并返回同类对象列表和自定义分类中的类型种类列表。
ihWC4D模型
ihWC4D模型
def get_assorting(self):
ihWC4D模型
objs = self.doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER)
ihWC4D模型
assorting_list = []
ihWC4D模型
style_list = []
ihWC4D模型
styles = []
ihWC4D模型
ihWC4D模型
if len(objs):
ihWC4D模型
for select in objs:
ihWC4D模型
select_type = select.GetType()
ihWC4D模型
for key, value in self.dic.items():
ihWC4D模型
if select_type in value:
ihWC4D模型
style_list.append(key)
ihWC4D模型
if select_type not in style_list:
ihWC4D模型
style_list.append(select_type)
ihWC4D模型
ihWC4D模型
for style in style_list:
ihWC4D模型
if type(style) is str:
ihWC4D模型
styles = self.dic[style] + styles
ihWC4D模型
if type(style) is int:
ihWC4D模型
styles.append(style)
ihWC4D模型
styles = list(set(styles))
ihWC4D模型
ihWC4D模型
c4d.CallCommand(100004766)
ihWC4D模型
Allobj = self.doc.GetActiveObjects(1)
ihWC4D模型
self.reset_names(Allobj)
ihWC4D模型
c4d.CallCommand(12113)
ihWC4D模型
dic = {}
ihWC4D模型
for obj in Allobj:
ihWC4D模型
dic[obj.GetName()] = self.getState(obj)
ihWC4D模型
if obj.GetType() in styles and obj not in objs:
ihWC4D模型
obj.SetBit(c4d.BIT_ACTIVE)
ihWC4D模型
assorting_list.append(obj)
ihWC4D模型
ihWC4D模型
c4d.CallCommand(12113)
ihWC4D模型
for i in objs:
ihWC4D模型
i.SetBit(c4d.BIT_ACTIVE)
ihWC4D模型
ihWC4D模型
return objs, assorting_list,dic
ihWC4D模型
else:
ihWC4D模型
c4d.gui.MessageDialog("Select at least one object in the view..")
ihWC4D模型
return False
ihWC4D模型
ihWC4D模型
设置同类对象的状态 ihWC4D模型
首先,存储这这些对象的初始状态到json中。获得存放路径:
ihWC4D模型
ihWC4D模型
def path(self):
ihWC4D模型
if self.doc.GetDocumentPath():
ihWC4D模型
path = self.doc.GetDocumentPath()
ihWC4D模型
else:
ihWC4D模型
path = c4d.storage.GeGetStartupPath()
ihWC4D模型
return path
ihWC4D模型
ihWC4D模型
def name(self):
ihWC4D模型
return self.path() + "\\" + self.doc.GetDocumentName().replace(".c4d", ".json")
ihWC4D模型
ihWC4D模型
判断如果C4D文档已经有保存路径则存在统一路径下,如果还没有保存则保存在C4D的程序文件夹下。
ihWC4D模型
ihWC4D模型
另外,我这里通过记录场景中对象的名字为锚点,记录各自的参数。所以为了排除同名的情况,做了去重和更名的方法:
ihWC4D模型
ihWC4D模型
@staticmethod
ihWC4D模型
def reset_names(objs):
ihWC4D模型
num = 0
ihWC4D模型
names = []
ihWC4D模型
for obj in objs:
ihWC4D模型
name = obj.GetName()
ihWC4D模型
if name not in names:
ihWC4D模型
names.append(name)
ihWC4D模型
else:
ihWC4D模型
while True:
ihWC4D模型
new_name = name + "." + str(num)
ihWC4D模型
if new_name in names:
ihWC4D模型
num += 1
ihWC4D模型
continue
ihWC4D模型
if new_name not in names:
ihWC4D模型
obj.SetName(new_name)
ihWC4D模型
num += 1
ihWC4D模型
break
ihWC4D模型
return names
ihWC4D模型
ihWC4D模型
接下来重置同类型对象的状态,需要判断是第一次按按钮还是第二次按按钮。
ihWC4D模型
ihWC4D模型
def restore(self, objs, assorting_list,dic):
ihWC4D模型
data = {}
ihWC4D模型
isBool = os.path.exists(self.name())
ihWC4D模型
ihWC4D模型
if isBool:
ihWC4D模型
with open(self.name(), 'r') as f:
ihWC4D模型
data = json.load(f)
ihWC4D模型
else:
ihWC4D模型
with open(self.name(), 'w') as f:
ihWC4D模型
json.dump(dic, f, ensure_ascii=False)
ihWC4D模型
visible_lst = []
ihWC4D模型
obj_names = []
ihWC4D模型
for obj in objs:
ihWC4D模型
obj_names.append(obj.GetName())
ihWC4D模型
if obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] == 1 or obj[c4d.ID_BASEOBJECT_GENERATOR_FLAG] is False:
ihWC4D模型
self.setState(obj, 0)
ihWC4D模型
if assorting_list:
ihWC4D模型
for obj in assorting_list:
ihWC4D模型
visible = obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR]
ihWC4D模型
visible_lst.append(visible)
ihWC4D模型
ihWC4D模型
true_num = visible_lst.count(2) + visible_lst.count(0)
ihWC4D模型
false_num = visible_lst.count(1)
ihWC4D模型
ihWC4D模型
if true_num >= false_num:
ihWC4D模型
state = [0, 2]
ihWC4D模型
else:
ihWC4D模型
state = [1]
ihWC4D模型
ihWC4D模型
for obj in assorting_list:
ihWC4D模型
if obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] in state:
ihWC4D模型
if state == [0, 2]:
ihWC4D模型
self.setState(obj)
ihWC4D模型
else:
ihWC4D模型
if data:
ihWC4D模型
lst = data[obj.GetName()]
ihWC4D模型
self.setState(obj, editor=lst[0], render=lst[1],
ihWC4D模型
flag=lst[2])
ihWC4D模型
else:
ihWC4D模型
self.setState(obj, 2, 2, True)
ihWC4D模型
ihWC4D模型
ihWC4D模型
if data:
ihWC4D模型
os.unlink(self.name())
ihWC4D模型
return True
ihWC4D模型
ihWC4D模型
如果是第一次使用则生成json并记录对象属性。如果是第二次点击,则读取json恢复属性,并删除json文件。
ihWC4D模型
ihWC4D模型
【脚本安装】 ihWC4D模型
1.打开C4D,shift+F11打开【脚本管理器】,点击“文件”→“导入脚本”,选择文件夹中的FlipFlop_V2.0.py文件。
ihWC4D模型
2.导入.py文件之后,shift+F12打开【命令管理器】,在搜索框中输入FlipFlop。
ihWC4D模型
3.将词条拖入C4D的窗口合适的位置,并保存窗口布局方便使用。 【4】也可以设置快捷键。
ihWC4D模型
ihWC4D模型
【使用步骤】ihWC4D模型
1.选中要独显的一个或多个对象
ihWC4D模型
2.点击脚本按钮即可。
ihWC4D模型
3.再次点击切换状态。
ihWC4D模型
ihWC4D模型
【版本信息】C4DR19及以上。
ihWC4D模型
【作者信息】西技大神
C4D脚本:C4D一键独显指定类型对象脚本FlipFlop 2.0(C4D脚本,独显,FlipFlop,一键独显,独显对象,指定独显),版本为FlipFlop 2.0,分类属于常规辅助,软件语言为中文,支持PC(Windows) , MAC(Mac OS)系统平台,安装好的脚本会出现在CINEMA 4D软件的脚本菜单下拉位置,附件大小约277.58 KB,下载方式为本地下载。更多不错常规辅助下载,尽在C4D模型-C4D.COM。
[使用声明]:《C4D一键独显指定类型对象脚本FlipFlop 2.0》插件仅供个人或学生测试试用,商业用途请前往插件官网购买正版。该插件严禁商用、传播或转载,请在下载后24小时内予以删除。常规辅助脚本来源于网络,如果侵犯了你的权利,请提供作品书面证明,请联系网站客服:2427120@qq.com删除下架处理。