Class: Autocad::PlotConfiguration

Inherits:
Element
  • Object
show all
Defined in:
lib/autocad/plot_configuration.rb

Direct Known Subclasses

Layout

Instance Attribute Summary

Attributes inherited from Element

#acad_type, #app, #ole_obj, #original

Instance Method Summary collapse

Methods inherited from Element

#[], #app_ole_obj, #clone, convert_item, #delete, #do_update, #each_complex, #get_property_handler, #in_cell?, #initialize, #method_missing, #move, #move_ole, #move_x, #move_y, #ole_cell, ole_object?, #property_handler, #redraw, #updated?

Methods included from ElementTrait

#autocad_type, #block_reference?, #bounds, #cell?, #def, #drawing, #explode, #graphical?, #has_tags?, #highlight, #id_from_record, #inspect, #line?, #model, #parent, #pviewport?, #select, #text?, #to_ole, #visible?

Constructor Details

This class inherits a constructor from Autocad::Element

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Autocad::Element

Instance Method Details

#ansi_b_landscapeObject

ANSI B landscape paper size name



142
143
144
# File 'lib/autocad/plot_configuration.rb', line 142

def ansi_b_landscape
  'ANSI_B_(17.00_x_11.00_Inches)'
end

#ansi_d_landscapeObject



146
147
148
# File 'lib/autocad/plot_configuration.rb', line 146

def ansi_d_landscape
  'ANSI_D_(34.00_x_22.00_Inches)'
end

#canonical_media_nameObject

The current device_name for printing as its Canonomical Name use this name when changing



175
176
177
# File 'lib/autocad/plot_configuration.rb', line 175

def canonical_media_name
  @ole_obj.CanonicalMediaName
end

#canonomical_media_name=(name) ⇒ Object



179
180
181
# File 'lib/autocad/plot_configuration.rb', line 179

def canonomical_media_name=(name)
  @ole_obj.CanonicalMediaName = name
end

#color_style_mode?Boolean

Check if using color-dependent plot styles

Returns:

  • (Boolean)


80
81
82
# File 'lib/autocad/plot_configuration.rb', line 80

def color_style_mode?
  plot_style_mode == :color_style_mode
end

#copy_plot_configuration(pc) ⇒ Object

Copy settings from another configuration



124
125
126
# File 'lib/autocad/plot_configuration.rb', line 124

def copy_plot_configuration(pc)
  ole_obj.CopyFrom(pc.ole_obj)
end

#custom_scaleObject



211
212
213
214
215
216
# File 'lib/autocad/plot_configuration.rb', line 211

def custom_scale
  numerator = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_BYREF | WIN32OLE::VARIANT::VT_R8)
  denominator = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_BYREF | WIN32OLE::VARIANT::VT_R8)
  @ole_obj.GetCustomScale(numerator, denominator)
  [numerator.value, denominator.value]
end

#device_nameObject

Get the current plot device configuration name



18
19
20
# File 'lib/autocad/plot_configuration.rb', line 18

def device_name
  @ole_obj.ConfigName
end

#device_name=(name) ⇒ Object

Set the plot device configuration file



12
13
14
# File 'lib/autocad/plot_configuration.rb', line 12

def device_name=(name)
  @ole_obj.ConfigName = name
end

#device_namesObject

The media devices available to for plotting



167
168
169
170
# File 'lib/autocad/plot_configuration.rb', line 167

def device_names
  refresh
  @ole_obj.GetPlotDeviceNames
end

#display_setupObject

Print current configuration to console



116
117
118
119
# File 'lib/autocad/plot_configuration.rb', line 116

def display_setup
  original.each { |k, v| puts "#{k}: #{v}" }
  puts "plot_style_mode: #{plot_style_mode}"
end

#locale_media_nameObject



192
193
194
# File 'lib/autocad/plot_configuration.rb', line 192

def locale_media_name
  @ole_obj.GetLocaleMediaName(canonical_media_name)
end

#media_namesObject

Note:

Call refresh() first if device was changed

The available paper sizes for the configured device. Use this when setting the media_name:



187
188
189
190
# File 'lib/autocad/plot_configuration.rb', line 187

def media_names
  refresh
  @ole_obj.GetCanonicalMediaNames
end

#nameObject

Get the name of the plot configuration



5
6
7
# File 'lib/autocad/plot_configuration.rb', line 5

def name
  @ole_obj.Name
end

#named_style_mode?Boolean

Check if using named plot styles

Returns:

  • (Boolean)


86
87
88
# File 'lib/autocad/plot_configuration.rb', line 86

def named_style_mode?
  plot_style_mode == :named_style_mode
end

#paper_unitsObject

Get current paper units



226
227
228
# File 'lib/autocad/plot_configuration.rb', line 226

def paper_units
  paper_units_from_ole(@ole_obj.PaperUnits)
end

#paper_units_scale_factorObject

Conversion factor to millimeters based on paper units

Examples:

inches: 25.4 (mm per inch)
pixels: 25.4/96 (mm per pixel at 96 DPI)


235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/autocad/plot_configuration.rb', line 235

def paper_units_scale_factor
  unit = paper_units
  case unit

  when :inches
    25.4

  when :mm
    1

  # pixel to mm
  when :pixels
    25.4 / 96.0
  end
end

#paper_units_typesObject

The different paper units



220
221
222
# File 'lib/autocad/plot_configuration.rb', line 220

def paper_units_types
  %i[inches mm pixels]
end

#plot_originObject

Get plot origin point in millimeters



47
48
49
# File 'lib/autocad/plot_configuration.rb', line 47

def plot_origin
  Point3d.new(ole_obj.PlotOrigin)
end

#plot_origin=Object

Set plot origin point

Raises:

  • (ArgumentError)

    For invalid coordinate values



55
56
57
58
59
60
# File 'lib/autocad/plot_configuration.rb', line 55

def plot_origin=(...)
  origin = Point3d.new(...)
  ole_obj.PlotOrigin = origin.to_ole
rescue StandardError => e
  app.error_proc.call(e, self)
end

#plot_style_modeObject

Get current plot style mode



64
65
66
67
68
69
70
71
72
# File 'lib/autocad/plot_configuration.rb', line 64

def plot_style_mode
  style = drawing.get_variable('pstylemode')
  case style
  when 0
    :named_style_mode
  else
    :color_style_mode
  end
end

#plot_style_mode=(sym) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
# File 'lib/autocad/plot_configuration.rb', line 128

def plot_style_mode=(sym)
  style = case sym
  when :named, :named_style, :named_style_mode
    0
  when :color, :color_style, :color_style_mode
    1
  else
    raise 'need either :named or :color'
  end
  drawing.set_variable('pstylemode', style)
end

#plot_style_mode_variableObject



74
75
76
# File 'lib/autocad/plot_configuration.rb', line 74

def plot_style_mode_variable
  drawing.get_variable('pstylemode')
end

#plot_style_table_namesObject

Returns the different plot tables. Use one of these when setting style_sheet



199
200
201
202
# File 'lib/autocad/plot_configuration.rb', line 199

def plot_style_table_names
  refresh
  @ole_obj.GetPlotStyleTableNames
end

#plot_typesObject

The different plot bounds or types



206
207
208
# File 'lib/autocad/plot_configuration.rb', line 206

def plot_types
  %i[display extents layout limits view window]
end

#read_ole(ole = nil) ⇒ Object

Read current configuration properties from OLE object



24
25
26
27
28
29
30
31
# File 'lib/autocad/plot_configuration.rb', line 24

def read_ole(ole = nil)
  {device_name: ole_obj.ConfigName,
   media_name: ole_obj.CanonicalMediaName,
   style_sheet: ole_obj.StyleSheet,
   plot_type: plot_type_ole_to_sym(ole_obj.PlotType),
   rotation: rotation_ole_to_degree(ole_obj.PlotRotation),
   paper_units: paper_units_from_ole(ole_obj.PaperUnits)}
end

#refreshObject

Note:

Required after changing device configurations

Refresh plot device information



153
154
155
# File 'lib/autocad/plot_configuration.rb', line 153

def refresh
  @ole_obj.RefreshPlotDeviceInfo
end

#setupObject

Configure multiple plot settings at once

Examples:

Configure for PDF output

setup(
  device_name: "AutoCAD PDF.pc3",
  media_name: "ANSI_D",
  style_sheet: "monochrome.ctb",
  plot_type: :layout
)


100
101
102
# File 'lib/autocad/plot_configuration.rb', line 100

def setup(...)
  write_ole(...)
end

#style_sheetObject



161
162
163
# File 'lib/autocad/plot_configuration.rb', line 161

def style_sheet
  ole_obj.StyleSheet
end

#style_sheet=(style) ⇒ Object



157
158
159
# File 'lib/autocad/plot_configuration.rb', line 157

def style_sheet=(style)
  ole_obj.StyleSheet = style
end

#update(value) ⇒ Object

Update configuration with merged values



107
108
109
110
111
112
# File 'lib/autocad/plot_configuration.rb', line 107

def update(value)
  merged_value = original.merge(value)
  super(merged_value)
rescue StandardError => e
  binding.irb
end

#write_ole(value) ⇒ Object

Write configuration settings to OLE object



36
37
38
39
40
41
42
43
# File 'lib/autocad/plot_configuration.rb', line 36

def write_ole(value)
  ole_obj.ConfigName = value[:device_name]
  ole_obj.CanonicalMediaName = value[:media_name]
  ole_obj.StyleSheet = value[:style_sheet]
  ole_obj.PlotType = plot_type_to_ole(value[:plot_type])
  ole_obj.PlotRotation = rotation_degree_to_ole(value[:rotation])
  ole_obj.PaperUnits = paper_units_to_ole(value[:paper_units])
end