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 = 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 if entity_insert.insert_type == ipInsertType.itSymbol:
16 entity_casted = ISymbolInsert(entity_insert._com_obj)
17 if entity_casted.inserted_block.full_name == base_point_string:
18 base_point = entity_casted.origin
19
20# Get the required settings from the database
21palette_settings = active_database.find_master_tool_setting("<Default>", ipMasterSettingType.mst3DPalettes)
22board_settings = active_database.find_master_tool_setting("Carton|Carton - Silk Board", ipMasterSettingType.mst3DBoard)
23varnish_settings = active_database.find_master_tool_setting("Gloss - High", ipMasterSettingType.mst3DVarnish)
24foil_settings = active_database.find_master_tool_setting("Gold", ipMasterSettingType.mst3DFoil)
25template_settings = active_database.find_master_tool_setting("RPC Presentation - White Lights", ipMasterSettingType.mst3DTemplate)
26
27if not layer.layer_type == "THREE_D":
28 name_string = "New 3D Layer"
29 type_string = "THREE_D"
30
31 # Add a new 3d layer and get the scene
32 new_layer = drawing.layers.add(name_string, type_string, layer)
33 scene = new_layer.scene
34
35 if not scene.isNone():
36
37 # Create options for adding a 3d model
38 options = impact.creator.three_d().create_model_options()
39
40 options.layer = layer
41 options.name = "New Model"
42 options.origin = base_point
43 options.fold_angle = 90
44 options.palette_settings = palette_settings
45 options.board_settings = board_settings
46 options.varnish_settings = varnish_settings
47 options.foil_settings = foil_settings
48 options.template_settings = template_settings
49 options.quality = ip3DTextureQuality.tq3DMedium
50 options.flags.board = True
51 options.flags.artwork = True
52 options.flags.varnish = True
53 options.flags.foiling = True
54 options.flags.embossing = True
55 options.flags.rule_definition = True
56
57 # Add a 3d model and get the instance
58 instance = scene.instances.add(ip3DObjectType.ot3DModel, options)
59
60 if not instance.isNone():
61 impact.gui.output_toolbox.add("Created instance:")
62 impact.gui.output_toolbox.add(instance.name)
63 impact.gui.output_toolbox.add(instance.guid)
64
65 # Set the instances properties
66 # instance.selected = True
67 # instance.visible = True
68
69 model = instance.object()
70
71 if not model.isNone():
72
73 # Configure the model
74 # model.flatten()
75 model.fold()
76
77 else:
78 impact.gui.output_toolbox.add("Model could not be retreived from the instance")
79
80 # Set the camera view
81 scene.view_extents(ip3DViewType.vt3DReference)
82
83 # scene.view_instance() instance, ip3DViewType.vt3DReference
84
85 else:
86 impact.gui.output_toolbox.add("Instance could not be created")
87
88 else:
89 impact.gui.output_toolbox.add("No 3d scene")
90
91else:
92 impact.gui.output_toolbox.add("not a 2d layer")
93