Coordinate Systems

Coordinate Systems
 1# This example creates a circle in a block that has a centre at different
 2# coordinates depending on the coordinate impact.system being used.
 3
 4# Create a local variable for the output toolbox
 5ot = impact.gui.output_toolbox
 6
 7# Clear the output toolbox
 8ot.clear()
 9
10# Create a local variable for the active drawing
11ad = impact.active_drawing
12
13# check there is an active drawing
14if ad.isNone():
15
16    # display a message in the output toolbox
17    ot.add("Unable to continue: there is no active drawing")
18
19else:
20
21    # create a local variable for the active block
22    ab = ad.active_layer.active_block
23
24    # move to a point that isn't the origin
25    ab.move_ad(100, 100)
26
27    # create a vector for the offset
28    offset = impact.creator.vector(0, 0)
29
30    # create a circle of radius 10
31    arc1 = ab.arc(offset, 10, 0, 0)
32    arc1.selected = True
33
34    # create a block with the circle in and make it active
35    block = ab.block("Block", "description", ipBlockPosition.bpLeft)
36    block.activate()
37
38    # create a local variable for the new active block
39    ab2 = ad.active_layer.active_block
40
41    for ent in ab2.entities:
42        if ent.entity_type == ipEntityType.etArc:
43            ent_casted = IArc(ent._com_obj)
44
45            ot.add("We'll set the coordinate impact.system to use world coordinates.")
46            ad.coordinate_system.mode = ipCoordinateMode.cmWorld
47            ot.add("The centre of the circle is reported as:")
48            ot.add(ent_casted.centre.to_string())
49            ot.add("This is always in user coordinates (now same as world coordinates).")
50            ot.add("We can convert this into block coordinates:")
51            ot.add(ad.convert_coords(ent_casted.centre, ipCoordinateMode.cmUser, ipCoordinateMode.cmBlock).to_string())
52            ot.add("We can convert this into world coordinates:")
53            ot.add(ad.convert_coords(ent_casted.centre, ipCoordinateMode.cmUser, ipCoordinateMode.cmWorld).to_string())
54            ot.add("We'll set the coordinate impact.system to use block coordinates.")
55            ad.coordinate_system.mode = ipCoordinateMode.cmBlock
56            ot.add("The centre of the circle is reported as")
57            ot.add(ent_casted.centre.to_string())
58            ot.add("This is always in user coordinates (now same as block coordinates).")
59            ot.add("We can convert this into block coordinates:")
60            ot.add(ad.convert_coords(ent_casted.centre, ipCoordinateMode.cmUser, ipCoordinateMode.cmBlock).to_string())
61            ot.add("We can convert this into world coordinates:")
62            ot.add(ad.convert_coords(ent_casted.centre, ipCoordinateMode.cmUser, ipCoordinateMode.cmWorld).to_string())