Class: Autocad::Layout

Inherits:
PlotConfiguration show all
Defined in:
lib/autocad/layout.rb

Instance Attribute Summary

Attributes inherited from Element

#acad_type, #app, #ole_obj, #original

Instance Method Summary collapse

Methods inherited from PlotConfiguration

#ansi_b_landscape, #ansi_d_landscape, #canonical_media_name, #canonomical_media_name=, #color_style_mode?, #custom_scale, #device_name, #device_name=, #device_names, #display_setup, #locale_media_name, #media_names, #named_style_mode?, #paper_units, #paper_units_scale_factor, #paper_units_types, #plot_origin, #plot_origin=, #plot_style_mode, #plot_style_mode=, #plot_style_mode_variable, #plot_style_table_names, #plot_types, #read_ole, #refresh, #setup, #style_sheet, #style_sheet=, #update, #write_ole

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, #read_ole, #redraw, #update, #updated?, #write_ole

Methods included from ElementTrait

#autocad_type, #block_reference?, #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

#add_block_reference(name, pt:, rotation: 0.0, scale: 1.0) ⇒ Object

Insert a block reference into the layout

Raises:

  • (StandardError)

    On insertion failure



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/autocad/layout.rb', line 37

def add_block_reference(name, pt:, rotation: 0.0, scale: 1.0)
  name = name.to_s
  name = app.windows_path(name) if File.file?(name)
  
  pt3d = Point3d.new(pt)
  ole_reference = ole_obj.Block.InsertBlock(pt3d.to_ole, name.to_s,
    scale.to_f, scale.to_f, scale.to_f, rotation.to_f)
  app.wrap(ole_reference)
rescue StandardError => e
  app.error_proc.call(e, self)
  nil
end

#add_pviewport(scale = :scale_to_fit) ⇒ Object

Add a paper space viewport



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/autocad/layout.rb', line 92

def add_pviewport(scale = :scale_to_fit)
  psize_width, psize_h = paper_size
  margins = paper_margins
  width_mm = psize_width - margins[0][0] - margins[1][0]
  height_mm = psize_h - margins[0][1] - margins[1][1]
  width = width_mm / paper_units_scale_factor
  height = height_mm / paper_units_scale_factor

  center = [width / 2.0, height / 2.0]
  pv = drawing.paper_space.add_pv_viewport(center, width: width, height: height)
  pv.on
  pv.standard_scale = scale
  pv
end

#boundsObject

Calculate usable area bounds with margins



74
75
76
77
78
79
80
# File 'lib/autocad/layout.rb', line 74

def bounds
  width, height = paper_size
  lower_left, upper_right = paper_margins
  lower_left_pt = lower_left
  upper_right_pt = Point3d(width, height) - upper_right
  BoundingBox.from_min_max(lower_left_pt, upper_right_pt)
end

#copy_plot_configuration(pc) ⇒ Object

Copy plot settings from another configuration



26
27
28
# File 'lib/autocad/layout.rb', line 26

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

#insert_block(block, pt: nil) ⇒ Object

Inserts a block into the layout



7
8
# File 'lib/autocad/layout.rb', line 7

def insert_block(block, pt: nil)
end

#nameObject

Get the layout name



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

def name
  @ole_obj.Name
end

#name=(str) ⇒ Object

Set the layout name



19
20
21
# File 'lib/autocad/layout.rb', line 19

def name=(str)
  @ole_obj.Name = str
end

#paper_marginsObject

Get page margins



109
110
111
112
113
114
115
116
117
118
# File 'lib/autocad/layout.rb', line 109

def paper_margins
  lower_left = nil
  upper_right = nil
  @ole_obj.GetPaperMargins lower_left, upper_right
  lower_left, upper_right = WIN32OLE::ARGV
  [lower_left, upper_right]
rescue StandardError => e
  puts "Error getting paper margins: #{e.message}"
  [[0.0, 0.0], [0.0, 0.0]]  # Return default values instead of breaking
end

#paper_sizeObject

Get paper dimensions in millimeters



65
66
67
68
69
70
# File 'lib/autocad/layout.rb', line 65

def paper_size
  width = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_BYREF | WIN32OLE::VARIANT::VT_R8)
  height = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_BYREF | WIN32OLE::VARIANT::VT_R8)
  @ole_obj.GetPaperSize(width, height)
  [width.value, height.value]
end

#paper_size_inchesObject

Get paper size in inches



84
85
86
87
# File 'lib/autocad/layout.rb', line 84

def paper_size_inches
  width, height = paper_size
  [width / 25.4, height / 25.4]
end

#tab_orderObject

Get layout tab order position



52
53
54
# File 'lib/autocad/layout.rb', line 52

def tab_order
  @ole_obj.TabOrder
end

#tab_order=(n) ⇒ Object

Set layout tab order position



59
60
61
# File 'lib/autocad/layout.rb', line 59

def tab_order=(n)
  @ole_obj.TabOrder = n
end