Activate block insertion and make changes¶
Activate block insertion and make changes¶
1# This example looks for an insertion of a specific block, modifies the
2# block, then saves the changes.
3
4
5name_of_top_level_block = "dieboard attributes"
6
7ad = impact.active_drawing
8
9
10def get_dieboard_attributes_block(lay):
11 ent = None
12 _result = None
13 for ent in lay.entities:
14 if ent.entity_type == ipEntityType.etInsert:
15 ent_insert = IInsertEntity(ent._com_obj)
16
17 if ent_insert.insert_type == ipInsertType.itBlock:
18 ent_casted = IBlockInsert(ent_insert._com_obj)
19
20 if ent_casted.inserted_object.full_name == name_of_top_level_block:
21 _result = ent_casted
22 return _result
23
24if not ad.isNone():
25 lay = None; blk_ins = None
26 lay = ad.active_layer
27
28 # go into the dieboard attributes block (if found)
29 blk_ins = get_dieboard_attributes_block(lay)
30 if blk_ins is not None and (not hasattr(blk_ins, "isNone") or not blk_ins.isNone()):
31 blk_ins.activate()
32
33 # process entities in that block (for this example, just delete the first entity)
34 ab = lay.active_block
35 if ab.entities.count> 1:
36 ent = ab.entities.item(1)
37 ent.delete()
38
39 # move to the top-level, thus saving the changes
40 lay.set_active_block(ipActiveBlock.abLayer)