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
16            if ent_insert.insert_type == ipInsertType.itBlock:
17                ent_casted = IBlockInsert(ent_insert._com_obj)
18
19                if ent_casted.inserted_block.full_name == "block1":
20                    insert = ent_casted
21                    break
22
23    # Just check that we found one
24    if insert is None or (hasattr(insert, "isNone") and insert.isNone()):
25        impact.gui.output_toolbox.add("No insertion found for block 'block1'")
26    else:
27
28        # Get hold of the Shape impact.creator and create a shape from the insert
29        ShapeCreator = impact.creator.shape_creator()
30        ShapeCreator.entities = insert.inserted_block.entities
31        ShapeCreator.matrix = insert.matrix
32        Shape = ShapeCreator.perform(ipShapeCreationType.sctInsert)
33
34        # Create the Hatcher and Hatcher Options
35        Hatcher = impact.creator.hatcher()
36        HatchOptions = Hatcher.create_hatch_options()
37
38        # This allows the hatch options to match an existing Master Tool Setting
39        db = impact.active_database
40        ms = db.find_master_tool_setting("Non Print", ipMasterSettingType.mstHatch)
41        if not ms.isNone():
42            HatchOptions.apply_master_setting(ms)
43
44        # Can also adjust the values manually
45        HatchOptions.hatch_mode = ipHatchMode.hmSingleLine
46        HatchOptions.offset1 = 8.0
47        HatchOptions.angle1 = 130.0
48        HatchOptions.use_palette = True
49        HatchOptions.palette_name = "Non print"
50
51        # Set the hatch options and shape to hatch
52        Hatcher.hatch_options = HatchOptions
53        Hatcher.shape = Shape
54        Hatcher.block_name = "HatchBlock"
55
56        # Perform the hatch operation and get the newly created block insertion
57        hatched_insert = Hatcher.perform(ipHatchCreationType.hctShape)
58
59