Example Use Of Hatcher And Hatcher Options

Example Use Of Hatcher And Hatcher Options
 1# This example shows how to use the Hatch and HatchOptions
 2# functionality to create a hatched area from a shape
 3
 4if impact.active_drawing.isNone():
 5    impact.gui.output_toolbox.add("Unable to continue: no active drawing")
 6else:
 7
 8    # Get hold of the insert from which we want to create a shape
 9    # (we are assuming that block1 contains a closed path of entities)
10    insert = None
11    layer = impact.active_drawing.active_layer
12    for ent in layer.entities:
13        if ent.entity_type == ipEntityType.etInsert:
14            ent_insert = IInsertEntity(ent._com_obj)
15            if ent_insert.insert_type == ipInsertType.itBlock:
16                ent_casted = IBlockInsert(ent_insert._com_obj)
17                if ent_casted.inserted_block.full_name == "block1":
18                    insert = ent_casted
19                    break
20
21    # Just check that we found one
22    if insert is None or (hasattr(insert, "isNone") and insert.isNone()):
23        impact.gui.output_toolbox.add("No insertion found for block 'block1'")
24    else:
25
26        # Get hold of the Shape impact.creator and create a shape from the insert
27        shape_creator = impact.creator.shape_creator()
28        shape_creator.entities = insert.inserted_block.entities
29        shape_creator.matrix = insert.matrix
30        shape = shape_creator.perform(ipShapeCreationType.sctInsert)
31
32        # Create the Hatcher and Hatcher Options
33        hatcher = impact.creator.hatcher()
34        hatch_options = hatcher.create_hatch_options()
35
36        # This allows the hatch options to match an existing Master Tool Setting
37        db = impact.active_database
38        ms = db.find_master_tool_setting("Non Print", ipMasterSettingType.mstHatch)
39        if not ms.isNone():
40            hatch_options.apply_master_setting(ms)
41
42        # Can also adjust the values manually
43        hatch_options.hatch_mode = ipHatchMode.hmSingleLine
44        hatch_options.offset1 = 8.0
45        hatch_options.angle1 = 130.0
46        hatch_options.use_palette = True
47        hatch_options.palette_name = "Non print"
48
49        # Set the hatch options and shape to hatch
50        hatcher.hatch_options = hatch_options
51        hatcher.shape = shape
52        hatcher.block_name = "HatchBlock"
53
54        # Perform the hatch operation and get the newly created block insertion
55        hatched_insert = hatcher.perform(ipHatchCreationType.hctShape)
56