3D model creation¶
3D model creation¶
1# This example creates a new 3d layer and then creates a 3d model from the original 2d layer.
2
3drawing = impact.active_drawing
4layer = drawing.active_layer
5
6base_point_string = "Centre of gravity"
7
8# Get the origin of the model from the Centre Of Gravity symbol if there is one.
9base_point = impact.creator.vector(0,0)
10entities = active_block.recursed_entities
11for recursed in entities:
12 Entity = recursed.entity
13 if Entity.entity_type == ipEntityType.etInsert:
14 Entity_insert = IInsertEntity(Entity._com_obj)
15
16 if Entity_insert.insert_type == ipInsertType.itSymbol:
17 Entity_casted = ISymbolInsert(Entity_insert._com_obj)
18
19 if Entity_casted.inserted_block.full_name == base_point_string:
20 base_point = Entity_casted.origin
21
22# Get the required settings from the database
23palette_settings = impact.active_database.find_master_tool_setting("<Default>", ipMasterSettingType.mst3DPalettes)
24board_settings = impact.active_database.find_master_tool_setting("Carton|Carton - Silk Board", ipMasterSettingType.mst3DBoard)
25varnish_settings = impact.active_database.find_master_tool_setting("Gloss - High", ipMasterSettingType.mst3DVarnish)
26foil_settings = impact.active_database.find_master_tool_setting("Gold", ipMasterSettingType.mst3DFoil)
27template_settings = impact.active_database.find_master_tool_setting("RPC Presentation - White Lights", ipMasterSettingType.mst3DTemplate)
28
29if not layer.layer_type == "THREE_D":
30 name_string = "New 3D Layer"
31 type_string = "THREE_D"
32
33 # Add a new 3d layer and get the scene
34 new_layer = drawing.layers.add(name_string, type_string, layer)
35 scene = new_layer.scene
36
37 if scene is not None:
38
39 # Create options for adding a 3d model
40 options = impact.creator.three_d().create_model_options()
41
42 options.layer = layer
43 options.name = "New Model"
44 options.origin = base_point
45 options.fold_angle = 90
46 options.palette_settings = palette_settings
47 options.board_settings = board_settings
48 options.varnish_settings = varnish_settings
49 options.foil_settings = foil_settings
50 options.template_settings = template_settings
51 options.quality = ip3DTextureQuality.tq3DMedium
52 options.flags.board = True
53 options.flags.artwork = True
54 options.flags.varnish = True
55 options.flags.foiling = True
56 options.flags.embossing = True
57 options.flags.rule_definition = True
58
59 # Add a 3d model and get the instance
60 instance = scene.instances.add(ip3DObjectType.ot3DModel, options)
61
62 if not instance.isNone():
63 impact.gui.output_toolbox.add("Created instance:")
64 impact.gui.output_toolbox.add(instance.name)
65 impact.gui.output_toolbox.add(instance.guid)
66
67 # Set the instances properties
68 # instance.selected = True
69 # instance.visible = True
70
71 model = instance.object()
72
73 if model is not None:
74
75 # Configure the model
76 # model.flatten()
77 model.fold()
78
79 else:
80 impact.gui.output_toolbox.add("Model could not be retreived from the instance")
81
82 # Set the camera view
83 scene.view_extents(ip3DViewType.vt3DReference)
84
85 # scene.view_instance() instance, ip3DViewType.vt3DReference
86
87 else:
88 impact.gui.output_toolbox.add("Instance could not be created")
89
90 else:
91 impact.gui.output_toolbox.add("No 3d scene")
92
93else:
94 impact.gui.output_toolbox.add("not a 2d layer")
95