"ayırın ve nesne modunda seçin" için kod
bu yüzden, editör modunda seçimi ayırmaktan bir makro oluşturuyorum ve daha sonra nesne modunda ayrılmış ağı seçiyorum ... Ne yaptığım hakkında çok az bilgim var, ama bunu asla daha az yapmıyorum. ..
bu yüzden biraz yardıma ihtiyacım var. Nesne modundan çıktıktan sonra son ayrılmış ağı seçmek için kod ne olmalıdır? bu mantıklı değilse özür dilerim. Keşke blender, siz ayırdıktan hemen sonra nesne modunda ayrılmış ağı seçse. Ayrılmış ağı temelde nasıl bulacağımı bilmiyorum.
Herhangi bir nesneyle her seferinde işe yaraması için bunu nasıl yapabilirim? Teşekkürler
Yanıtlar
Çözüm, önce seçtiğiniz nesne adını saklamak ve ardından ağı ayırdıktan sonra seçimini kaldırmaktır.
Bunun gibi bir şey:
org_obj_list = {obj.name for obj in context.selected_objects}
# This is a Set comprehension in Python,
# which create a set of name from the context.selected_objects
# context.selected_objects will be a Iterable collection of some object
bpy.ops.mesh.separate(type = 'SELECTED')
# This will call the separate operator in your code directly
# the type can be a enum string in ['SELECTED', 'LOOSE', 'MATERIAL']
bpy.ops.object.editmode_toggle()
# Switch back to object mode from edit mode
# Those separated object will also be selected now
# We then check if selected object is the one we saved before, then deselect it.
for obj in context.selected_objects:
if obj and obj.name in org_obj_list:
# Deselect selected object
obj.select_set(False)
else:
# Set the new created object to active
context.view_layer.objects.active = obj
Bunun en iyi uygulama olduğundan emin değilim, ama işe yarıyor.
Özel bir operatör:
import bpy
class SeparateSelectionActive(bpy.types.Operator):
"""Separate object by selection and set it as active object."""
bl_idname = "mesh.select_separate_active"
bl_label = "Separate Selection Active"
# An enum for prompt dialog
separate_method: bpy.props.EnumProperty(
items = {
('SELECTED', 'Selected', "Selected mesh"),
('MATERIAL', 'Material', "Based on material"),
('LOOSE', 'Loose', "Based on loose part")
},
name = "Separate Method",
description = "Choose a method to separate mesh",
default = 'SELECTED'
)
@classmethod
def poll(cls, context):
return context.object is not None and context.mode == 'EDIT_MESH'
def invoke(self, context, event):
# Prompt to ask a method to separate
return context.window_manager.invoke_props_dialog(self)
def execute(self, context):
org_obj_list = {o.name for o in context.selected_objects}
# Separate using selected method
bpy.ops.mesh.separate(type = self.separate_method)
bpy.ops.object.editmode_toggle()
for obj in context.selected_objects:
if obj and obj.name in org_obj_list:
# Deselect everything selected before
obj.select_set(False)
else:
# Set the new created object to active
context.view_layer.objects.active = obj
self.report({'INFO'},f"Set active object to: {obj.name}")
return {'FINISHED'}
# A menu inject into View3D > Edit > Mesh tab
def _menu_func(self, context):
self.layout.operator(SeparateSelectionActive.bl_idname)
def register():
bpy.utils.register_class(SeparateSelectionActive)
bpy.types.VIEW3D_MT_edit_mesh.append(_menu_func)
def unregister():
bpy.utils.unregister_class(SeparateSelectionActive)
bpy.types.VIEW3D_MT_edit_mesh.remove(_menu_func)
if __name__ == "__main__":
register()
# test call
bpy.ops.mesh.select_separate_active()
Operatör olarak kaydettikten sonra, bu operatörü 3B alan içinde düzenleme modunda arayabilir ve çalıştırabilirsiniz :

Veya View3d> düzenleme modu> ağ> Ayrı Seçim Aktif'te , Blender 2.90'da aranabilir hale getirmek için yeni bir menü işlevi ekledikten sonra.

Bir ayırma yöntemi soran bir uyarı görmelisiniz:

Bu seçenekler, orijinal ayrı operatörle tamamen aynıdır.
Ve bu işleç onu ayıracak, orijinal ağın seçimini kaldıracak, yeni oluşturulan ağı etkin hale getirecektir:

Not: Ayrı işlem, aktif olmasını istediğinizi değiştirmeden yaparsa, bu operatör yanlış ağı etkinleştirecektir, çünkü hala aynı ada sahip orijinal ağdır.