Class: Autocad::Drawing
- Inherits:
-
Object
- Object
- Autocad::Drawing
- Includes:
- Common, Faa::Cleanup
- Defined in:
- lib/autocad/drawing.rb,
lib/faa/cleanup.rb
Overview
Represents an AutoCAD drawing document and provides interface for:
-
File operations (save/open/close)
-
Space management (Model/Paper)
-
Layer/block/text management
-
Plot configuration
-
User interaction
-
Selection sets
-
System variables
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
Class Method Summary collapse
-
.from_ole_obj(app, ole) ⇒ Object
Create a Drawing instance from an OLE object.
Instance Method Summary collapse
-
#active_layer ⇒ Layer
Get the active layer in the drawing.
-
#active_layer=(layer) ⇒ Object
Set the active layer.
-
#active_layer_name ⇒ String
Get the name of the active layer.
-
#active_layout ⇒ Layout
Get the active layout.
-
#active_layout=(layout) ⇒ void
Set the active layout.
-
#active_pviewport ⇒ PViewport
Get the active paper space viewport.
-
#active_pviewport=(vport) ⇒ void
Set the active paper space viewport.
-
#active_space ⇒ ModelSpace, PaperSpace
Get the currently active space (model or paper).
-
#add_plot_configuration(name, model: false) ⇒ PlotConfiguration
Add a new plot configuration to the drawing.
-
#basename ⇒ Pathname
Get the basename of the drawing as a Pathname.
-
#block_reference_selection_set ⇒ SelectionSetAdapter
Get a selection set adapter for block references.
-
#block_references {|BlockReference| ... } ⇒ Enumerator<BlockReference>
Get all block references in the drawing &: (BlockReference) -> void.
-
#blocks {|Block| ... } ⇒ Enumerator<Block>
Get all blocks in the drawing.
-
#close(save = true) ⇒ void
Close the drawing.
-
#copy(name: nil, dir: nil) ⇒ void
Copy the drawing to a new file.
-
#create_layer(name, color = nil) ⇒ Acad::Layer
Create a new layer or get an existing one.
-
#create_selection_set(name) {|SelectionSetAdapter| ... } ⇒ SelectionSetAdapter
Create a new selection set in the drawing.
-
#dim_styles {|DimStyle| ... } ⇒ Enumerator<DimStyle>
Get all dimension styles in the drawing &: (DimStyle) -> void.
-
#dirname ⇒ Pathname
Get the directory of the drawing.
-
#event_handler ⇒ EventHandler
Get the event handler for this drawing.
-
#get_float(prompt: "Enter a float") ⇒ Float
Get a floating point input from the user.
-
#get_input_integer(prompt: "Enter a integer") ⇒ Integer
Get an integer input from the user.
-
#get_input_string(prompt: "Enter a string", spaces: true) ⇒ String
Get a string input from the user.
-
#get_point(prompt: "Get point", base_point: nil) ⇒ Point3d
Prompt the user for a point in the drawing.
-
#get_region ⇒ Array<Point3d>
Prompt the user to select a rectangular region.
-
#get_select_text_containing(str) ⇒ SelectionSetAdapter
Get a selection set containing text with the specified string.
-
#get_selection_set(name) ⇒ SelectionSet?
Get a selection set by name.
-
#get_variable(name) ⇒ Object
Get the value of a system variable.
-
#get_variables(*atts) ⇒ Array<Object>
Get the values of multiple system variables.
-
#has_pviewport? ⇒ Boolean
Check if the drawing has any paper space viewports.
-
#initialize(app, ole, requested_name = nil) ⇒ Drawing
constructor
Initialize a new Drawing instance.
-
#layers {|Layer| ... } ⇒ Enumerator<Layer>
Get all layers in the drawing.
-
#layouts {|Layout| ... } ⇒ Enumerator<Layout>
Get all layouts in the drawing.
-
#linetypes {|Linetype| ... } ⇒ Enumerator<Linetype>
Get all linetypes in the drawing.
-
#model_block_references ⇒ Enumerator<BlockReference>
Get all block references in model space.
-
#model_space ⇒ ModelSpace
(also: #model)
Get the model space of the drawing.
-
#model_space? ⇒ Boolean
Check if model space is active.
-
#modified? ⇒ Boolean
Check if the drawing has been modified since the last save.
-
#name ⇒ String
Returns the name of the drawing If the drawing hasn’t been saved yet, returns the requested name.
-
#ole_obj ⇒ WIN32OLE
Get the underlying OLE object.
-
#paper_block_references ⇒ Enumerator<BlockReference>
Get all block references in paper space.
-
#paper_space ⇒ PaperSpace
(also: #paper)
Get the paper space of the drawing.
-
#paper_space? ⇒ Boolean
Check if paper space is active.
-
#paper_space_layout ⇒ Layout
Get the first layout that is not “Model”.
-
#path ⇒ Pathname
Get the full path of the drawing.
-
#pdf_plot_config ⇒ PlotConfiguration
Get the predefined PDF plot configuration “faa_ansid_bw” Creates it if it doesn’t exist.
-
#plot ⇒ Plot
Get the plot object for this drawing.
-
#plot_configurations {|Layout| ... } ⇒ Enumerator<Layout>
Get all layouts in the drawing (duplicate method, should be removed).
-
#previously_saved? ⇒ Boolean
Check if the drawing has been saved before.
-
#prompt(message) ⇒ void
Display a message in the AutoCAD command line.
-
#read_only? ⇒ Boolean
Check if the drawing is read-only.
-
#regen(view_ports = :all) ⇒ void
Regenerate the drawing display.
-
#register_handler(event) { ... } ⇒ Object
Register an event handler.
-
#save(name: nil, dir: nil) ⇒ void
Saves the drawing If the drawing hasn’t been saved yet and no name is provided, uses the requested name.
-
#save_as_pdf(name: nil, dir: nil, model: false) ⇒ void
Save the drawing as a PDF file If name or directory is given, uses those params Otherwise uses the drawing name and directory.
-
#select_text_containing(str) ⇒ Enumerator<Element>
Select all text objects containing the specified string.
-
#selection_sets {|SelectionSetAdapter| ... } ⇒ Enumerator<SelectionSetAdapter>
Get all selection sets in the drawing.
-
#set_variable(name, value) ⇒ void
Set the value of a system variable.
-
#set_variables(names, values) ⇒ void
Set multiple system variables at once.
-
#text_styles {|TextStyle| ... } ⇒ Enumerator<TextStyle>
Get all text styles in the drawing &: (TextStyle) -> void.
-
#to_model_space ⇒ void
Switch to model space.
-
#to_paper_space ⇒ void
Switch to paper space.
-
#view_center ⇒ Point3d
Get the center point of the current view.
-
#with_system_variables(names, values) { ... } ⇒ Object
Temporarily set system variables and restore them after the block executes.
Methods included from Common
Methods included from Faa::Cleanup
#add_title_block, #cleanup_model, #cleanup_title_block, #faa_title_block, #fix_layout, #get_title_attributes, #remove_translation_text
Constructor Details
#initialize(app, ole, requested_name = nil) ⇒ Drawing
Initialize a new Drawing instance
37 38 39 40 41 42 |
# File 'lib/autocad/drawing.rb', line 37 def initialize(app, ole, requested_name = nil) @app = app @ole_obj = ole @app_event = WIN32OLE_EVENT.new(ole) @requested_name = requested_name end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Autocad::Common
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
20 21 22 |
# File 'lib/autocad/drawing.rb', line 20 def app @app end |
Class Method Details
.from_ole_obj(app, ole) ⇒ Object
Create a Drawing instance from an OLE object
26 27 28 |
# File 'lib/autocad/drawing.rb', line 26 def self.from_ole_obj(app, ole) #: Drawing new(app, ole) end |
Instance Method Details
#active_layer ⇒ Layer
Get the active layer in the drawing
286 287 288 289 |
# File 'lib/autocad/drawing.rb', line 286 def active_layer ole = ole_obj.ActiveLayer app.wrap(ole) end |
#active_layer=(layer) ⇒ Object
Set the active layer
304 305 306 307 308 309 310 311 312 |
# File 'lib/autocad/drawing.rb', line 304 def active_layer=(layer) if layer.is_a?(String) layer = ole_obj.Layers.Item(layer) elsif layer.is_a?(Autocad::Layer) layer = layer.to_ole end raise "layer not found" unless layer ole_obj.ActiveLayer = layer.to_ole end |
#active_layer_name ⇒ String
Get the name of the active layer
294 295 296 |
# File 'lib/autocad/drawing.rb', line 294 def active_layer_name ole_obj.ActiveLayer.Name end |
#active_layout ⇒ Layout
Get the active layout
336 337 338 339 |
# File 'lib/autocad/drawing.rb', line 336 def active_layout ole = ole_obj.ActiveLayout app.wrap(ole) end |
#active_layout=(layout) ⇒ void
This method returns an undefined value.
Set the active layout
348 349 350 |
# File 'lib/autocad/drawing.rb', line 348 def active_layout=(layout) ole_obj.ActiveLayout = layout.to_ole end |
#active_pviewport ⇒ PViewport
Get the active paper space viewport
326 327 328 329 330 331 |
# File 'lib/autocad/drawing.rb', line 326 def ole = ole_obj.ActivePViewport app.wrap(ole) rescue => ex app.error_proc.call(ex, self) end |
#active_pviewport=(vport) ⇒ void
This method returns an undefined value.
Set the active paper space viewport
319 320 321 |
# File 'lib/autocad/drawing.rb', line 319 def (vport) ole_obj.ActivePViewport = vport.to_ole end |
#active_space ⇒ ModelSpace, PaperSpace
Get the currently active space (model or paper)
354 355 356 357 358 359 360 361 362 363 |
# File 'lib/autocad/drawing.rb', line 354 def active_space ole = ole_obj.ActiveSpace if ole == ACAD::AcPaperSpace paper_space else model_space end end |
#add_plot_configuration(name, model: false) ⇒ PlotConfiguration
Add a new plot configuration to the drawing
162 163 164 165 166 167 168 169 |
# File 'lib/autocad/drawing.rb', line 162 def add_plot_configuration(name, model: false) plot_config = plot_configurations.find { |p| p.name == name } return plot_config if plot_config ole = @ole_obj.PlotConfigurations.Add(name, model) app.wrap(ole) rescue => ex app.error_proc.call(ex, self) end |
#basename ⇒ Pathname
Get the basename of the drawing as a Pathname
265 266 267 |
# File 'lib/autocad/drawing.rb', line 265 def basename Pathname.new(name) end |
#block_reference_selection_set ⇒ SelectionSetAdapter
Get a selection set adapter for block references
621 622 623 |
# File 'lib/autocad/drawing.rb', line 621 def block_reference_selection_set @block_reference_selection_set ||= get_block_reference_selection_set end |
#block_references {|BlockReference| ... } ⇒ Enumerator<BlockReference>
Get all block references in the drawing &: (BlockReference) -> void
581 582 583 584 585 586 587 588 589 |
# File 'lib/autocad/drawing.rb', line 581 def block_references return to_enum(__callee__) unless block_given? ss = block_reference_selection_set ss.clear ss.select ss.each do |o| yield o end end |
#blocks {|Block| ... } ⇒ Enumerator<Block>
Get all blocks in the drawing
415 416 417 418 |
# File 'lib/autocad/drawing.rb', line 415 def blocks return to_enum(__callee__) unless block_given? ole_obj.Blocks.each { |o| yield app.wrap(o) } end |
#close(save = true) ⇒ void
This method returns an undefined value.
Close the drawing
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'lib/autocad/drawing.rb', line 373 def close(save = true) # Store the name before marking as closed drawing_name = @ole_obj.respond_to?(:Name) ? @ole_obj.Name : "unknown" @drawing_closed = true begin if @ole_obj.respond_to?(:Close) @ole_obj.Close(save) elsif @ole_obj.respond_to?(:close) @ole_obj.close(save) else # If we can't close it directly, try through the app app.close_drawing(drawing_name, save) end rescue => ex # Instead of just calling error_proc, raise a specific DrawingClose error # Use drawing name instead of the drawing object raise DrawingClose.new("Failed to close drawing: #{ex.}", drawing_name) ensure @ole_obj = nil end end |
#copy(name: nil, dir: nil) ⇒ void
This method returns an undefined value.
Copy the drawing to a new file
203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/autocad/drawing.rb', line 203 def copy(name: nil, dir: nil) #: void if dir.nil? lname = name || copy_name dir_path = dirname else lname = name || self.name dir_path = Pathname.new(dir) end copy_path = dir_path + lname FileUtils.copy path.to_s, copy_path.to_s, verbose: true end |
#create_layer(name, color = nil) ⇒ Acad::Layer
Create a new layer or get an existing one
470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
# File 'lib/autocad/drawing.rb', line 470 def create_layer(name, color = nil) if name.class == Autocad::Layer name.color = Autocad.color_to_index(color) if color return name end ole_layer = begin ole_obj.Layers.Item(name) rescue nil end ole_layer ||= ole_obj.Layers.Add(name) ole_layer.Color = Autocad.color_to_index(color) if color app.wrap(ole_layer) end |
#create_selection_set(name) {|SelectionSetAdapter| ... } ⇒ SelectionSetAdapter
Create a new selection set in the drawing
61 62 63 64 65 |
# File 'lib/autocad/drawing.rb', line 61 def create_selection_set(name) ss = SelectionSet.new(name) yield ss if block_given? SelectionSetAdapter.new(self, ss) end |
#dim_styles {|DimStyle| ... } ⇒ Enumerator<DimStyle>
Get all dimension styles in the drawing &: (DimStyle) -> void
598 599 600 601 |
# File 'lib/autocad/drawing.rb', line 598 def dim_styles return to_enum(__callee__) unless block_given? ole_obj.DimStyles.each { |o| yield app.wrap(o) } end |
#dirname ⇒ Pathname
Get the directory of the drawing
272 273 274 |
# File 'lib/autocad/drawing.rb', line 272 def dirname Pathname.new(ole_obj.Path). end |
#event_handler ⇒ EventHandler
Get the event handler for this drawing
47 48 49 |
# File 'lib/autocad/drawing.rb', line 47 def event_handler #: EventHandler @event_handler ||= default_event_handler end |
#get_float(prompt: "Enter a float") ⇒ Float
Get a floating point input from the user
771 772 773 774 775 |
# File 'lib/autocad/drawing.rb', line 771 def get_float(prompt: "Enter a float") utility.GetReal(prompt) rescue => ex raise Autocad::Error.new("Error getting float input from user #{ex}") end |
#get_input_integer(prompt: "Enter a integer") ⇒ Integer
Get an integer input from the user
759 760 761 762 763 |
# File 'lib/autocad/drawing.rb', line 759 def get_input_integer(prompt: "Enter a integer") utility.GetInteger(prompt) rescue => ex raise Autocad::Error.new("Error getting integer input from user #{ex}") end |
#get_input_string(prompt: "Enter a string", spaces: true) ⇒ String
Get a string input from the user
746 747 748 749 750 |
# File 'lib/autocad/drawing.rb', line 746 def get_input_string(prompt: "Enter a string", spaces: true) utility.GetString(spaces, prompt) rescue => ex raise Autocad::Error.new("Error getting string input from user #{ex}") end |
#get_point(prompt: "Get point", base_point: nil) ⇒ Point3d
If base_point is provided, a stretched line is drawn from the base point
Prompt the user for a point in the drawing
790 791 792 793 794 795 796 797 798 799 800 801 802 |
# File 'lib/autocad/drawing.rb', line 790 def get_point(prompt: "Get point", base_point: nil) if base_point array_pt = base_point.to_ary.map { |x| x.to_f } unless base_point.nil? base_point = WIN32OLE_VARIANT.array([3], WIN32OLE::VARIANT::VT_R8) base_point[0] = array_pt[0] base_point[1] = array_pt[1] base_point[2] = array_pt[2] end pt = utility.GetPoint(base_point, prompt) Point3d.new(pt[0], pt[1], pt[2]) rescue => ex raise Autocad::Error.new("Error getting point input from user #{ex}") end |
#get_region ⇒ Array<Point3d>
Prompt the user to select a rectangular region
809 810 811 812 813 814 815 |
# File 'lib/autocad/drawing.rb', line 809 def get_region pt = get_point(prompt: "Specify first corner") prompt("X: #{pt.x}, Y: #{pt.y}, Z: #{pt.z}\n") point2 = utility.GetCorner(pt.to_ole, "Specify opposite corner: ") pt2 = Point3d(point2) [pt, pt2] end |
#get_select_text_containing(str) ⇒ SelectionSetAdapter
Get a selection set containing text with the specified string
561 562 563 564 565 566 567 568 569 570 571 |
# File 'lib/autocad/drawing.rb', line 561 def get_select_text_containing(str) name = "text_containing_#{str}" varname = "@#{name}".tr("*", "_") ss = get_selection_set(name) ss.delete if ss ss = create_selection_set(name) do |ss| ss.filter_text_containing(str) end instance_variable_set(varname, ss) ss end |
#get_selection_set(name) ⇒ SelectionSet?
Get a selection set by name
403 404 405 406 |
# File 'lib/autocad/drawing.rb', line 403 def get_selection_set(name) ole = get_ole_selection_set(name) app.wrap(ole) if ole end |
#get_variable(name) ⇒ Object
Get the value of a system variable
634 635 636 |
# File 'lib/autocad/drawing.rb', line 634 def get_variable(name) ole_obj.GetVariable(name) end |
#get_variables(*atts) ⇒ Array<Object>
Get the values of multiple system variables
705 706 707 708 709 710 711 712 713 714 |
# File 'lib/autocad/drawing.rb', line 705 def get_variables(*atts) return [] if atts.empty? if atts.first.class == Array atts = atts.first end atts.each_with_object([]) do |k, a| a << ole_obj.GetVariable(k) a end end |
#has_pviewport? ⇒ Boolean
Check if the drawing has any paper space viewports
554 555 556 |
# File 'lib/autocad/drawing.rb', line 554 def paper_space..count > 0 end |
#layers {|Layer| ... } ⇒ Enumerator<Layer>
Get all layers in the drawing
439 440 441 442 443 |
# File 'lib/autocad/drawing.rb', line 439 def layers return to_enum(__callee__) unless block_given? ole_obj.Layers.each { |o| yield app.wrap(o) } end |
#layouts {|Layout| ... } ⇒ Enumerator<Layout>
Get all layouts in the drawing
427 428 429 430 |
# File 'lib/autocad/drawing.rb', line 427 def layouts return to_enum(__callee__) unless block_given? ole_obj.Layouts.each { |o| yield app.wrap(o) } end |
#linetypes {|Linetype| ... } ⇒ Enumerator<Linetype>
Get all linetypes in the drawing
454 455 456 457 |
# File 'lib/autocad/drawing.rb', line 454 def linetypes return to_enum(__callee__) unless block_given? ole_obj.Linetypes.each { |o| yield app.wrap(o) } end |
#model_block_references ⇒ Enumerator<BlockReference>
Get all block references in model space
506 507 508 509 510 511 512 513 514 515 |
# File 'lib/autocad/drawing.rb', line 506 def model_block_references ss = selection_sets.find { it.name == "model_block_references" } ss ||= create_selection_set("model_block_references") ss.filter do |f| f.and(f.model_space, f.block_reference) end ss.clear ss.select ss.each end |
#model_space ⇒ ModelSpace Also known as: model
Get the model space of the drawing
834 835 836 |
# File 'lib/autocad/drawing.rb', line 834 def model_space app.wrap ole_obj.ModelSpace end |
#model_space? ⇒ Boolean
Check if model space is active
225 226 227 |
# File 'lib/autocad/drawing.rb', line 225 def model_space? #: bool ole_obj.ActiveSpace == ACAD::AcModelSpace end |
#modified? ⇒ Boolean
Check if the drawing has been modified since the last save
95 96 97 |
# File 'lib/autocad/drawing.rb', line 95 def modified? ole_obj.Saved == false end |
#name ⇒ String
Returns the name of the drawing If the drawing hasn’t been saved yet, returns the requested name
253 254 255 256 257 258 259 260 |
# File 'lib/autocad/drawing.rb', line 253 def name if @requested_name && !previously_saved? # Make sure we return just the basename with .dwg extension basename = File.basename(@requested_name) return basename.end_with?('.dwg') ? basename : "#{basename}.dwg" end ole_obj.Name end |
#ole_obj ⇒ WIN32OLE
Get the underlying OLE object
876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 |
# File 'lib/autocad/drawing.rb', line 876 def ole_obj if @drawing_closed || @ole_obj.nil? # Use a local variable to avoid recursive call to name method drawing_name = @ole_obj.respond_to?(:Name) ? @ole_obj.Name : "unknown" raise DrawingClose.new("Drawing is closed", drawing_name) end # Check if the ole object is still valid begin @ole_obj.Name @ole_obj rescue => e @drawing_closed = true @ole_obj = nil # Use a string directly instead of calling name method raise DrawingClose.new("Drawing is no longer valid: #{e.}", "unknown") end end |
#paper_block_references ⇒ Enumerator<BlockReference>
Get all block references in paper space
524 525 526 527 528 529 530 531 532 533 |
# File 'lib/autocad/drawing.rb', line 524 def paper_block_references ss = selection_sets.find { it.name == "paper_block_references" } ss ||= create_selection_set("paper_block_references") ss.filter do |f| f.and(f.paper_space, f.block_reference) end ss.clear ss.select ss.each end |
#paper_space ⇒ PaperSpace Also known as: paper
Get the paper space of the drawing
865 866 867 |
# File 'lib/autocad/drawing.rb', line 865 def paper_space app.wrap ole_obj.PaperSpace end |
#paper_space? ⇒ Boolean
Check if paper space is active
218 219 220 |
# File 'lib/autocad/drawing.rb', line 218 def paper_space? #: bool ole_obj.ActiveSpace == ACAD::AcPaperSpace end |
#paper_space_layout ⇒ Layout
Get the first layout that is not “Model”
191 192 193 |
# File 'lib/autocad/drawing.rb', line 191 def paper_space_layout layouts.reject { it.name == "Model" }.first end |
#path ⇒ Pathname
Get the full path of the drawing
279 280 281 |
# File 'lib/autocad/drawing.rb', line 279 def path dirname + basename end |
#pdf_plot_config ⇒ PlotConfiguration
Get the predefined PDF plot configuration “faa_ansid_bw” Creates it if it doesn’t exist
175 176 177 |
# File 'lib/autocad/drawing.rb', line 175 def pdf_plot_config #: PlotConfiguration @pdf_plot_config ||= create_pdf_plot_configutation end |
#plot ⇒ Plot
Get the plot object for this drawing
182 183 184 185 186 |
# File 'lib/autocad/drawing.rb', line 182 def plot #: Plot ole = ole_obj.Plot ole.QuietErrorMode = true app.wrap(ole_obj.Plot) end |
#plot_configurations {|Layout| ... } ⇒ Enumerator<Layout>
Get all layouts in the drawing (duplicate method, should be removed)
845 846 847 848 |
# File 'lib/autocad/drawing.rb', line 845 def plot_configurations return to_enum(__callee__) unless block_given? ole_obj.PlotConfigurations.each { |o| yield app.wrap(o) } end |
#previously_saved? ⇒ Boolean
Check if the drawing has been saved before
88 89 90 |
# File 'lib/autocad/drawing.rb', line 88 def previously_saved? ole_obj.FullName != "" end |
#prompt(message) ⇒ void
This method returns an undefined value.
Display a message in the AutoCAD command line
733 734 735 |
# File 'lib/autocad/drawing.rb', line 733 def prompt() utility.Prompt() end |
#read_only? ⇒ Boolean
Check if the drawing is read-only
81 82 83 |
# File 'lib/autocad/drawing.rb', line 81 def read_only? ole_obj.ReadOnly end |
#regen(view_ports = :all) ⇒ void
Uses AcRegenType enum from AutoCAD
This method returns an undefined value.
Regenerate the drawing display
493 494 495 496 497 498 499 |
# File 'lib/autocad/drawing.rb', line 493 def regen(view_ports = :all) vp_type = case view_ports when :all then 1 when :active then 0 end ole_obj.Regen vp_type end |
#register_handler(event) { ... } ⇒ Object
Register an event handler
74 75 76 |
# File 'lib/autocad/drawing.rb', line 74 def register_handler(event, &) #:void @event_handler.add_handler(event, &) unless event == "OnQuit" end |
#save(name: nil, dir: nil) ⇒ void
This method returns an undefined value.
Saves the drawing If the drawing hasn’t been saved yet and no name is provided, uses the requested name
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/autocad/drawing.rb', line 109 def save(name: nil, dir: nil) #: void return if read_only? # Use requested_name if no name is provided and drawing hasn't been saved yet name ||= @requested_name if !previously_saved? && @requested_name if previously_saved? && modified? && !name && !dir ole_obj.Save puts "saved #{path}" else out_name = dwg_path(name: name, dir: dir) windows_name = app.windows_path(out_name) ole_obj.SaveAs(windows_name) puts "saved #{windows_name}" # After saving, clear the requested name since it's now saved @requested_name = nil end end |
#save_as_pdf(name: nil, dir: nil, model: false) ⇒ void
This method returns an undefined value.
Save the drawing as a PDF file If name or directory is given, uses those params Otherwise uses the drawing name and directory
139 140 141 142 143 |
# File 'lib/autocad/drawing.rb', line 139 def save_as_pdf(name: nil, dir: nil, model: false) #: void out_name = pdf_path(name: name, dir: dir) print_pdf(out_name, model:) puts "saved #{out_name}" end |
#select_text_containing(str) ⇒ Enumerator<Element>
Select all text objects containing the specified string
540 541 542 543 544 545 546 547 548 549 550 |
# File 'lib/autocad/drawing.rb', line 540 def select_text_containing(str) varname = "@text_containg_#{str}".tr("*", "_") ss = if instance_variable_defined?(varname) instance_variable_get(varname) else get_select_text_containing(str) end ss.clear ss.select ss.each end |
#selection_sets {|SelectionSetAdapter| ... } ⇒ Enumerator<SelectionSetAdapter>
Get all selection sets in the drawing
824 825 826 827 |
# File 'lib/autocad/drawing.rb', line 824 def selection_sets return to_enum(__callee__) unless block_given? ole_selection_sets.each { |o| yield app.wrap(o) } end |
#set_variable(name, value) ⇒ void
This method returns an undefined value.
Set the value of a system variable
649 650 651 |
# File 'lib/autocad/drawing.rb', line 649 def set_variable(name, value) ole_obj.SetVariable(name, value) end |
#set_variables(names, values) ⇒ void
This method returns an undefined value.
Set multiple system variables at once
665 666 667 668 669 670 |
# File 'lib/autocad/drawing.rb', line 665 def set_variables(names, values) atts = names.zip(values).to_h atts.each do |k, v| set_variable(k, v) end end |
#text_styles {|TextStyle| ... } ⇒ Enumerator<TextStyle>
Get all text styles in the drawing &: (TextStyle) -> void
610 611 612 613 |
# File 'lib/autocad/drawing.rb', line 610 def text_styles return to_enum(__callee__) unless block_given? ole_obj.TextStyles.each { |o| yield app.wrap(o) } end |
#to_model_space ⇒ void
This method returns an undefined value.
Switch to model space
245 246 247 |
# File 'lib/autocad/drawing.rb', line 245 def to_model_space #: void ole_obj.ActiveSpace = ACAD::AcModelSpace end |
#to_paper_space ⇒ void
This method returns an undefined value.
Switch to paper space
235 236 237 |
# File 'lib/autocad/drawing.rb', line 235 def to_paper_space #: void ole_obj.ActiveSpace = ACAD::AcPaperSpace end |
#view_center ⇒ Point3d
Get the center point of the current view
148 149 150 151 |
# File 'lib/autocad/drawing.rb', line 148 def view_center center = get_variable("VIEWCTR") Point3d(center) end |
#with_system_variables(names, values) { ... } ⇒ Object
Temporarily set system variables and restore them after the block executes
689 690 691 692 693 694 695 696 |
# File 'lib/autocad/drawing.rb', line 689 def with_system_variables(names, values, &block) atts current_values = get_variables(names) set_variables(names, values) yield ensure set_variables(names, current_values) end |