Use of Dimension Options

Use of Dimension Options
  1# this script demonstrates the use of the new DimensionOptions, DimensionDistanceFormat and DimensionAngleFormat objects
  2# along with their use in the new dimensioning methods
  3
  4if active_drawing.isNone():
  5    impact.gui.output_toolbox.add("Unable to continue: no active drawing")
  6else:
  7
  8    # Create the DimensionOptions
  9    dimension_options = impact.creator.dimension_options()
 10
 11    # We can also create our own formats for display distances and angles
 12    primary_distance_format = dimension_options.create_dimension_distance_format()
 13    primary_angle_format = dimension_options.create_dimension_angle_format()
 14
 15    # We can then set their values manually
 16    primary_distance_format.units = ipDistanceFormat.dfMillimetres
 17    primary_distance_format.suffix = "mm"
 18    primary_distance_format.decimal_places = 2
 19    primary_distance_format.remove_trailing_zeros = True
 20    primary_distance_format.display_fractions = False
 21    primary_distance_format.reduce_denominator = False
 22    primary_distance_format.denominator = 64
 23
 24    primary_angle_format.units = ipAngleFormat.afDegrees
 25    primary_angle_format.suffix = "deg"
 26    primary_angle_format.decimal_places = 1
 27    primary_angle_format.remove_trailing_zeros = True
 28    primary_angle_format.display_fractions = False
 29    primary_angle_format.reduce_denominator = False
 30    primary_angle_format.denominator = 64
 31
 32    # Then set the formats in the DimensionOptions
 33    dimension_options.primary_distance_format = primary_distance_format
 34    dimension_options.primary_angle_format = primary_angle_format
 35
 36    # Get a text style
 37    text_style_sheet_name = "Palette Default"
 38    text_style_sheet = impact.active_drawing.text_style_sheets.item(text_style_sheet_name)
 39
 40    dimension_options.text_style = text_style_sheet.text_style
 41
 42    # Setup the rest of DimensionOptions
 43    dimension_options.add_lines = True
 44    dimension_options.terminator_style = ipTerminatorStyle.tsClosedFilledArrow
 45    dimension_options.terminator_size = 2.0
 46    dimension_options.leader_length = 2.0
 47    dimension_options.show_radial_lines = True
 48    dimension_options.parallel_offset = 10.0
 49    dimension_options.dimension_gap = 10.0
 50    dimension_options.projection_ascent = 10.0
 51    dimension_options.force_palette_colour = False
 52    dimension_options.format_specifier = "%1 (%2)"
 53    dimension_options.dim_text_parallel = False
 54    dimension_options.text_position = ipDimensionTextPosition.dtAboveLine
 55    dimension_options.radius_prefix = "Radius"
 56    dimension_options.diameter_prefix = "Diameter"
 57    dimension_options.display_tolerances = True
 58    dimension_options.display_tolerances_plus_minus = True
 59    dimension_options.tolerance_upper_limit = 2.0
 60    dimension_options.tolerance_lower_limit = 2.0
 61    dimension_options.auto_size = False
 62
 63    # Instead of that you can apply a master tool setting instead
 64    db = impact.active_database
 65    ms = db.find_master_tool_setting("Standard Dimensions", ipMasterSettingType.mstDimension)
 66    if not ms.isNone():
 67        impact.gui.output_toolbox.add("Applying MTS")
 68        dimension_options.apply_master_setting(ms)
 69
 70    # DimensionHorizontal2 as an example
 71    # The new dimensioning methods take the same arguments as the old ones
 72    # plus the addition of the new DimensionOptions object
 73
 74    # create a local variable for the active block
 75    ab = impact.active_drawing.active_layer.active_block
 76
 77    # create an array of points to dimension
 78    points = [None] * 4
 79
 80    points[0] = impact.creator.vector(0,0)
 81    points[1] = impact.creator.vector(21,0)
 82    points[2] = impact.creator.vector(40,0)
 83    points[3] = impact.creator.vector(60,0)
 84
 85    # create some local variables to store the dimensions returned,
 86    # projection length, projection side, etc.
 87    dimensions = None
 88    projection_length = 10
 89    projection_side = ipProjectionSide.psLeft
 90    dimension_mode = ipDimensionMode.dmSingle
 91
 92    # create the horizontal dimensions
 93    dimensions = ab.dimension_horizontal2(points, projection_length, projection_side, dimension_mode, dimension_options)
 94
 95    # Wrap variant return items with Impact.py wrapper
 96    if dimensions is not None:
 97        dimensions = [ILinearDimension(item) for item in dimensions]
 98
 99    # check that some dimensions were returned
100    if dimensions:
101        for dim_ent in dimensions:
102            impact.gui.output_toolbox.add("Dimension value is " + str(dim_ent.expression_value))
103
104