autocad 0.4.6 → 0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop/minitest.yml +2 -2
- data/.rubocop/strict.yml +4 -4
- data/.rubocop.yml +36 -33
- data/CHANGELOG.md +5 -5
- data/LICENSE.txt +21 -21
- data/README.md +134 -39
- data/Rakefile +26 -10
- data/exe/autocad +3 -3
- data/gemfiles/rubocop.gemfile +2 -1
- data/lib/autocad/app.rb +127 -28
- data/lib/autocad/arc.rb +3 -0
- data/lib/autocad/block.rb +11 -6
- data/lib/autocad/block_reference.rb +33 -4
- data/lib/autocad/bounding_box.rb +202 -0
- data/lib/autocad/dim_style.rb +4 -0
- data/lib/autocad/drawing.rb +873 -172
- data/lib/autocad/element.rb +217 -25
- data/lib/autocad/errors.rb +9 -0
- data/lib/autocad/filter.rb +502 -168
- data/lib/autocad/layer.rb +129 -41
- data/lib/autocad/layout.rb +120 -0
- data/lib/autocad/line.rb +154 -55
- data/lib/autocad/message_box.rb +95 -95
- data/lib/autocad/model.rb +217 -89
- data/lib/autocad/mtext.rb +189 -110
- data/lib/autocad/plot.rb +45 -0
- data/lib/autocad/plot_configuration.rb +372 -0
- data/lib/autocad/point.rb +7 -0
- data/lib/autocad/point3d.rb +18 -11
- data/lib/autocad/pviewport.rb +136 -21
- data/lib/autocad/selection_filter.rb +358 -180
- data/lib/autocad/selection_set.rb +140 -61
- data/lib/autocad/selection_set_adapter.rb +187 -8
- data/lib/autocad/spline.rb +27 -0
- data/lib/autocad/text.rb +66 -11
- data/lib/autocad/text_style.rb +4 -0
- data/lib/autocad/version.rb +1 -1
- data/lib/autocad/viewport.rb +57 -0
- data/lib/autocad.rb +126 -30
- data/lib/faa/cleanup.rb +137 -0
- data/lib/win32ole_helper.rb +52 -0
- data/rbs_collection.lock.yaml +38 -18
- data/sig/generated/autocad/app.rbs +278 -251
- data/sig/generated/autocad/arc.rbs +6 -3
- data/sig/generated/autocad/block.rbs +8 -5
- data/sig/generated/autocad/block_reference.rbs +99 -59
- data/sig/generated/autocad/bounding_box.rbs +78 -0
- data/sig/generated/autocad/dim_style.rbs +6 -0
- data/sig/generated/autocad/drawing.rbs +597 -158
- data/sig/generated/autocad/element.rbs +233 -166
- data/sig/generated/autocad/errors.rbs +29 -23
- data/sig/generated/autocad/filter.rbs +388 -60
- data/sig/generated/autocad/layer.rbs +76 -19
- data/sig/generated/autocad/layout.rbs +64 -0
- data/sig/generated/autocad/line.rbs +128 -25
- data/sig/generated/autocad/message_box.rbs +81 -81
- data/sig/generated/autocad/model.rbs +115 -41
- data/sig/generated/autocad/mtext.rbs +123 -0
- data/sig/generated/autocad/plot.rbs +26 -0
- data/sig/generated/autocad/plot_configuration.rbs +176 -0
- data/sig/generated/autocad/point.rbs +7 -0
- data/sig/generated/autocad/point3d.rbs +70 -66
- data/sig/generated/autocad/pviewport.rbs +64 -0
- data/sig/generated/autocad/selection_filter.rbs +226 -50
- data/sig/generated/autocad/selection_set.rbs +112 -37
- data/sig/generated/autocad/selection_set_adapter.rbs +235 -28
- data/sig/generated/autocad/spline.rbs +22 -0
- data/sig/generated/autocad/text.rbs +66 -7
- data/sig/generated/autocad/text_style.rbs +6 -0
- data/sig/generated/autocad/viewport.rbs +19 -2
- data/sig/generated/autocad.rbs +140 -68
- data/sig/generated/faa/cleanup.rbs +53 -0
- data/sig/generated/win32ole_helper.rbs +9 -0
- data/sig/prototype/lib/autocad/app.rbs +3 -1
- data/sig/prototype/lib/autocad/bounding_box.rbs +15 -0
- data/sig/prototype/lib/autocad/drawing.rbs +6 -0
- data/sig/prototype/lib/autocad/layer.rbs +5 -0
- data/sig/prototype/lib/autocad/viewport.rbs +7 -0
- data/sig/prototype/lib/autocad.rbs +1 -1
- metadata +29 -5
- data/event_handler.log +0 -24
- data/sig/generated/autocad/text_node.rbs +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c493af716dddb2e4096f73bca30fdb0de952bf2da0d7803bd7f707f9576ffe3f
|
4
|
+
data.tar.gz: 652b6088a00cdf198f2fc84b2391d94b42d0c37858134769518782bef51973d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65eb1d1238ab59216b526d548fde497988d13062e17338b183692812d7d45feafac9c688b954492e4382028157fd5ab5c4097f8182f05d10852376810705abda
|
7
|
+
data.tar.gz: 3eb0d132ad96e4e6dc8b85096e76c5ab90ecd9ab17775352a96c9439ecdf4c76a0958f64851f1467e1ad6a0851f533a19354be39de076834abf42655c9eb43b0
|
data/.rubocop/minitest.yml
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
- rubocop-minitest
|
1
|
+
plugins:
|
2
|
+
- rubocop-minitest
|
data/.rubocop/strict.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Lint/Debugger: # don't leave binding.pry
|
2
|
-
Enabled: true
|
3
|
-
Exclude: []
|
4
|
-
|
1
|
+
Lint/Debugger: # don't leave binding.pry
|
2
|
+
Enabled: true
|
3
|
+
Exclude: []
|
4
|
+
|
data/.rubocop.yml
CHANGED
@@ -1,33 +1,36 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
-
|
8
|
-
- standard-
|
9
|
-
-
|
10
|
-
|
11
|
-
|
12
|
-
standard
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
-
|
18
|
-
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
Layout/
|
33
|
-
|
1
|
+
|
2
|
+
inherit_mode:
|
3
|
+
merge:
|
4
|
+
- Exclude
|
5
|
+
|
6
|
+
plugins:
|
7
|
+
- rubocop-performance
|
8
|
+
- standard-custom
|
9
|
+
- standard-performance
|
10
|
+
|
11
|
+
require:
|
12
|
+
- standard
|
13
|
+
- rubocop-rbs_inline
|
14
|
+
|
15
|
+
inherit_gem:
|
16
|
+
standard: config/base.yml
|
17
|
+
standard-performance: config/base.yml
|
18
|
+
standard-custom: config/base.yml
|
19
|
+
|
20
|
+
inherit_from:
|
21
|
+
- .rubocop/minitest.yml
|
22
|
+
- .rubocop/strict.yml
|
23
|
+
|
24
|
+
AllCops:
|
25
|
+
NewCops: disable
|
26
|
+
SuggestExtensions: false
|
27
|
+
TargetRubyVersion: 3.4
|
28
|
+
Exclude:
|
29
|
+
- 'sig/**/*'
|
30
|
+
|
31
|
+
# RBS annotations allowed
|
32
|
+
Layout/LeadingCommentSpace:
|
33
|
+
AllowRBSInlineAnnotation: true
|
34
|
+
|
35
|
+
Layout/EndOfLine:
|
36
|
+
EnforcedStyle: lf
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
## [Unreleased]
|
2
|
-
|
3
|
-
## [0.1.0] - 2024-11-27
|
4
|
-
|
5
|
-
- Initial release
|
1
|
+
## [Unreleased]
|
2
|
+
|
3
|
+
## [0.1.0] - 2024-11-27
|
4
|
+
|
5
|
+
- Initial release
|
data/LICENSE.txt
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2024 Dominic Sisneros
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Dominic Sisneros
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,39 +1,134 @@
|
|
1
|
-
# Autocad
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
1
|
+
# Autocad
|
2
|
+
|
3
|
+
A Ruby library for automating AutoCAD operations through the COM interface (version 0.5).
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- Create, open, and manipulate AutoCAD drawings
|
8
|
+
- Work with layers, blocks, text, and other drawing elements
|
9
|
+
- Support for symbolic color names through ACAD::COLOR constants
|
10
|
+
- Selection sets for filtering and manipulating objects
|
11
|
+
- PDF export capabilities
|
12
|
+
- Event handling for AutoCAD events
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'autocad', '~> 0.5'
|
20
|
+
```
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
```bash
|
25
|
+
$ bundle install
|
26
|
+
```
|
27
|
+
|
28
|
+
Or install it yourself as:
|
29
|
+
|
30
|
+
```bash
|
31
|
+
$ gem install autocad
|
32
|
+
```
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
### Basic Operations
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
# Start AutoCAD and create a new drawing
|
40
|
+
Autocad.run do |app|
|
41
|
+
drawing = app.new_drawing("test.dwg")
|
42
|
+
|
43
|
+
# Create a new layer with a color
|
44
|
+
layer = drawing.create_layer("MyLayer", ACAD::COLOR::RED)
|
45
|
+
|
46
|
+
# Switch to model space
|
47
|
+
drawing.to_model_space
|
48
|
+
|
49
|
+
# Add a line to the drawing
|
50
|
+
model = drawing.model_space
|
51
|
+
pt1 = Point3d(0, 0, 0)
|
52
|
+
pt2 = Point3d(10, 10, 0)
|
53
|
+
line = model.add_line(pt1, pt2)
|
54
|
+
|
55
|
+
# Save and close the drawing
|
56
|
+
drawing.save
|
57
|
+
drawing.close
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
### Working with Colors
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
# Colors can be specified in multiple ways:
|
65
|
+
layer.color = Autocad::Color::Blue # Using constants
|
66
|
+
layer.color = :green # Using symbols
|
67
|
+
layer.color = "RED" # Using strings
|
68
|
+
layer.color = 1 # Using AutoCAD color indices
|
69
|
+
```
|
70
|
+
|
71
|
+
### Working with Layers
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
# Create a layer
|
75
|
+
layer = drawing.create_layer("NewLayer", :blue)
|
76
|
+
|
77
|
+
# Set the active layer
|
78
|
+
drawing.active_layer = layer
|
79
|
+
|
80
|
+
# Iterate through all layers
|
81
|
+
drawing.layers.each do |layer|
|
82
|
+
puts "Layer: #{layer.name}, Color: #{layer.color_name}"
|
83
|
+
end
|
84
|
+
```
|
85
|
+
|
86
|
+
### Working with Selection Sets
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
# Create a selection set
|
90
|
+
ss = drawing.create_selection_set("MySelection")
|
91
|
+
|
92
|
+
# Filter for specific objects
|
93
|
+
ss.filter do |f|
|
94
|
+
f.and(f.model_space, f.block_reference)
|
95
|
+
end
|
96
|
+
|
97
|
+
# Select objects
|
98
|
+
ss.select
|
99
|
+
|
100
|
+
# Process selected objects
|
101
|
+
ss.each do |obj|
|
102
|
+
puts obj.inspect
|
103
|
+
end
|
104
|
+
```
|
105
|
+
|
106
|
+
### Exporting to PDF
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
# Export the current drawing to PDF
|
110
|
+
drawing.save_as_pdf(dir: "output")
|
111
|
+
|
112
|
+
# Batch convert multiple drawings
|
113
|
+
Autocad.with_drawings(["drawing1.dwg", "drawing2.dwg"], read_only: true) do |drawing|
|
114
|
+
drawing.save_as_pdf(dir: "output")
|
115
|
+
end
|
116
|
+
```
|
117
|
+
|
118
|
+
## Development
|
119
|
+
|
120
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
121
|
+
|
122
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
123
|
+
|
124
|
+
## Contributing
|
125
|
+
|
126
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dsisnero/autocad. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/dsisnero/autocad/blob/main/CODE_OF_CONDUCT.md).
|
127
|
+
|
128
|
+
## License
|
129
|
+
|
130
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
131
|
+
|
132
|
+
## Code of Conduct
|
133
|
+
|
134
|
+
Everyone interacting in the Autocad project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/dsisnero/autocad/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
@@ -1,10 +1,26 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
|
6
|
-
Minitest::TestTask.create
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'minitest/test_task'
|
5
|
+
|
6
|
+
Minitest::TestTask.create
|
7
|
+
|
8
|
+
Minitest::TestTask.create :unit do |t|
|
9
|
+
t.test_globs = ['spec/unit/**/*_spec.rb']
|
10
|
+
t.warning = false
|
11
|
+
end
|
12
|
+
|
13
|
+
# Create a namespace for test tasks
|
14
|
+
namespace :test do
|
15
|
+
desc "Run unit tests"
|
16
|
+
task :unit => :unit
|
17
|
+
|
18
|
+
desc "Run specific drawing test"
|
19
|
+
task :drawing_set_variables do
|
20
|
+
sh "ruby -Ilib:spec spec/unit/autocad/drawing_spec.rb --line 117"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'standard/rake'
|
25
|
+
|
26
|
+
task default: %i[test standard]
|
data/exe/autocad
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "autocad"
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "autocad"
|
data/gemfiles/rubocop.gemfile
CHANGED
data/lib/autocad/app.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# rbs_inline: enabled
|
2
2
|
|
3
3
|
require_relative "event_handler"
|
4
|
+
require_relative "element"
|
4
5
|
require_relative "drawing"
|
5
6
|
require_relative "paths"
|
6
|
-
require_relative "element"
|
7
7
|
require_relative "line"
|
8
8
|
require_relative "text"
|
9
9
|
require_relative "mtext"
|
@@ -11,6 +11,15 @@ require_relative "pviewport"
|
|
11
11
|
require_relative "block"
|
12
12
|
require_relative "block_reference"
|
13
13
|
require_relative "selection_set"
|
14
|
+
require_relative "plot"
|
15
|
+
require_relative "plot_configuration"
|
16
|
+
require_relative "layout"
|
17
|
+
require_relative "bounding_box"
|
18
|
+
require_relative "viewport"
|
19
|
+
require_relative "point"
|
20
|
+
require_relative "dim_style"
|
21
|
+
require_relative "spline"
|
22
|
+
|
14
23
|
|
15
24
|
require "win32ole"
|
16
25
|
module Windows
|
@@ -37,9 +46,33 @@ module Autocad
|
|
37
46
|
class App
|
38
47
|
include Common
|
39
48
|
@default_error_proc = ->(e, f) {
|
40
|
-
|
41
|
-
|
42
|
-
|
49
|
+
if e.is_a?(DrawingClose)
|
50
|
+
# For DrawingClose errors, try to close via the app
|
51
|
+
drawing_name = e.drawing_name
|
52
|
+
puts "Error with drawing #{drawing_name}: #{e.message}"
|
53
|
+
begin
|
54
|
+
# Try to find and close the drawing by name
|
55
|
+
if drawing_name && !drawing_name.empty?
|
56
|
+
ole_obj.Documents.each do |doc|
|
57
|
+
if doc.Name == drawing_name
|
58
|
+
begin
|
59
|
+
doc.Close(false)
|
60
|
+
puts "Successfully closed drawing #{drawing_name} via app"
|
61
|
+
rescue => close_err
|
62
|
+
puts "Failed to close drawing #{drawing_name}: #{close_err.message}"
|
63
|
+
end
|
64
|
+
break
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
rescue StandardError => close_err
|
69
|
+
puts "Additional error during cleanup: #{close_err.message}"
|
70
|
+
end
|
71
|
+
else
|
72
|
+
puts "Couldn't open drawing #{f}" if f
|
73
|
+
debug_error if $DEBUG
|
74
|
+
raise e
|
75
|
+
end
|
43
76
|
}
|
44
77
|
|
45
78
|
class << self
|
@@ -117,11 +150,15 @@ module Autocad
|
|
117
150
|
begin
|
118
151
|
the_app.open_drawing(file, read_only:, wait_time:, wait_interval:, error_proc:, &block)
|
119
152
|
the_app.ole_obj.ole_methods # check if server still open
|
153
|
+
rescue DrawingClose => e
|
154
|
+
# Handle DrawingClose errors specifically
|
155
|
+
error_proc.call(e, e.drawing_name)
|
156
|
+
next # Continue to the next drawing
|
120
157
|
rescue => e
|
121
158
|
raise e unless error_proc
|
122
159
|
|
123
160
|
error_proc.call(e, file)
|
124
|
-
the_app = new(visible:
|
161
|
+
the_app = new(visible: visible)
|
125
162
|
end
|
126
163
|
end
|
127
164
|
ensure
|
@@ -206,11 +243,18 @@ module Autocad
|
|
206
243
|
drawing_from_ole(ole)
|
207
244
|
end
|
208
245
|
|
209
|
-
|
210
|
-
|
246
|
+
# @rbs drawing: Drawing
|
247
|
+
# @rbs return void
|
248
|
+
def active_drawing=(drawing)
|
249
|
+
ole_obj.ActiveDocument = drawing.ole_obj
|
250
|
+
end
|
251
|
+
|
252
|
+
def drawing_from_ole(ole, requested_name = nil) #: Drawing
|
253
|
+
Drawing.new(self, ole, requested_name)
|
211
254
|
end
|
212
255
|
|
213
|
-
attr_reader :
|
256
|
+
attr_reader :visible, :logger
|
257
|
+
attr_accessor :error_proc
|
214
258
|
|
215
259
|
# Constructor for app
|
216
260
|
# @rbs visible: bool -- do you want the app to be visible
|
@@ -230,6 +274,19 @@ module Autocad
|
|
230
274
|
@error_proc.call(e, nil)
|
231
275
|
end
|
232
276
|
|
277
|
+
# save the current drawing
|
278
|
+
# @rbs dir: String|Pathname -- the dir to save drawing to
|
279
|
+
# @rbs model: bool -- prints model space instead of paperspace in pdf document
|
280
|
+
# @rbs return void
|
281
|
+
def save_open_drawings(dir: Pathname.getwd, model: false)
|
282
|
+
return unless has_drawings?
|
283
|
+
drawings.each do |d|
|
284
|
+
d.copy(dir:)
|
285
|
+
d.save_as_pdf(dir:, model:)
|
286
|
+
# d.close(false)
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
233
290
|
def windows_path(path)
|
234
291
|
@windows.windows_path(path)
|
235
292
|
end
|
@@ -336,7 +393,7 @@ module Autocad
|
|
336
393
|
end
|
337
394
|
|
338
395
|
def zoom_pick_window
|
339
|
-
ole_obj.
|
396
|
+
ole_obj.ZoomPickWindow
|
340
397
|
end
|
341
398
|
|
342
399
|
def zoom_extents
|
@@ -347,7 +404,7 @@ module Autocad
|
|
347
404
|
ole_obj.ZoomPrevious
|
348
405
|
end
|
349
406
|
|
350
|
-
def zoom_scaled(magnify
|
407
|
+
def zoom_scaled(magnify = 1.0, scale_type: :relative)
|
351
408
|
scale_type = case scale_type
|
352
409
|
when :paper_space
|
353
410
|
ACAD::AcZoomScaledRelativePSpace
|
@@ -391,12 +448,43 @@ module Autocad
|
|
391
448
|
|
392
449
|
def close_all_drawings(save: false)
|
393
450
|
return unless @ole_obj
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
451
|
+
begin
|
452
|
+
# Get a count first since the collection will change as we close drawings
|
453
|
+
count = @ole_obj.Documents.Count
|
454
|
+
count.times do |i|
|
455
|
+
# Always close the first one since the collection shifts
|
456
|
+
begin
|
457
|
+
doc = @ole_obj.Documents.Item(0)
|
458
|
+
doc.Close(save) if doc
|
459
|
+
rescue StandardError => e
|
460
|
+
puts "Error closing document: #{document.name} #{e.message}"
|
461
|
+
break
|
462
|
+
end
|
463
|
+
end
|
464
|
+
rescue StandardError => e
|
465
|
+
puts "Error in close_all_drawings: #{e.message}"
|
466
|
+
end
|
467
|
+
end
|
468
|
+
|
469
|
+
# Close a specific drawing
|
470
|
+
# @rbs drawing: Drawing | String -- the drawing or drawing name to close
|
471
|
+
# @rbs save: bool -- whether to save the drawing
|
472
|
+
def close_drawing(drawing, save = true)
|
473
|
+
begin
|
474
|
+
# Get the drawing name
|
475
|
+
drawing_name = drawing.is_a?(String) ? drawing : (drawing.respond_to?(:name) ? drawing.name : nil)
|
476
|
+
return unless drawing_name
|
477
|
+
|
478
|
+
# Try to find the drawing in the Documents collection and close it
|
479
|
+
ole_obj.Documents.each do |doc|
|
480
|
+
if doc.Name == drawing_name
|
481
|
+
doc.Close(save)
|
482
|
+
puts "Successfully closed drawing #{drawing_name}"
|
483
|
+
break
|
484
|
+
end
|
399
485
|
end
|
486
|
+
rescue StandardError => e
|
487
|
+
puts "Error in close_drawing #{drawing_name}: #{e.message}"
|
400
488
|
end
|
401
489
|
end
|
402
490
|
|
@@ -427,7 +515,7 @@ module Autocad
|
|
427
515
|
# binding.break unless seedfile
|
428
516
|
windows_name = windows_path(filename)
|
429
517
|
ole = new_ole_drawing(windows_name, open: open, wait_time: opts[:wait_time], wait_interval: opts[:wait_interval])
|
430
|
-
drawing =
|
518
|
+
drawing = Drawing.new(self, ole, filename)
|
431
519
|
return drawing unless block
|
432
520
|
|
433
521
|
begin
|
@@ -454,23 +542,34 @@ module Autocad
|
|
454
542
|
file_path = Pathname.new(filename).expand_path
|
455
543
|
raise FileNotFound.new(file_path) unless file_path.file?
|
456
544
|
|
545
|
+
err_fn = error_proc || @error_proc
|
546
|
+
|
457
547
|
begin
|
458
548
|
ole = ole_open_drawing(windows_path(filename), read_only:, wait_time:, wait_interval:)
|
459
549
|
rescue DrawingError => e
|
460
550
|
raise e unless err_fn
|
461
|
-
|
462
551
|
err_fn.call(e, e.drawing)
|
552
|
+
return nil
|
463
553
|
end
|
554
|
+
|
464
555
|
drawing = drawing_from_ole(ole)
|
465
556
|
return drawing unless block_given?
|
466
557
|
|
467
558
|
begin
|
468
559
|
yield drawing
|
560
|
+
rescue DrawingClose => e
|
561
|
+
# Handle DrawingClose errors specifically
|
562
|
+
err_fn.call(e, e.drawing_name)
|
563
|
+
return nil
|
469
564
|
rescue => e
|
470
565
|
raise e unless err_fn
|
471
566
|
err_fn.call(e, filename)
|
472
567
|
ensure
|
473
|
-
|
568
|
+
begin
|
569
|
+
drawing.close unless drawing.nil? || drawing.instance_variable_get(:@drawing_closed)
|
570
|
+
rescue DrawingClose => e
|
571
|
+
err_fn.call(e, e.drawing_name)
|
572
|
+
end
|
474
573
|
end
|
475
574
|
end
|
476
575
|
|
@@ -478,16 +577,6 @@ module Autocad
|
|
478
577
|
|
479
578
|
alias_method :current_drawing, :active_drawing
|
480
579
|
|
481
|
-
def model_space
|
482
|
-
ModelSpace.new(doc_ole.ModelSpace)
|
483
|
-
end
|
484
|
-
|
485
|
-
def paper_space
|
486
|
-
PaperSpace.new(doc_ole.PaperSpace)
|
487
|
-
end
|
488
|
-
|
489
|
-
alias_method :model, :model_space
|
490
|
-
|
491
580
|
# @rbs message: String -- the String to put in Autocad prompt
|
492
581
|
def prompt(message)
|
493
582
|
doc.prompt(message)
|
@@ -576,6 +665,16 @@ module Autocad
|
|
576
665
|
ole_preferences_files.SupportPath.split(";").map { |f| Pathname.new(f) }
|
577
666
|
end
|
578
667
|
|
668
|
+
def support_path_files
|
669
|
+
return enum_for(:support_path_files) unless block_given?
|
670
|
+
|
671
|
+
support_paths.each do |path|
|
672
|
+
path.children.each do |file|
|
673
|
+
yield file if file.file?
|
674
|
+
end
|
675
|
+
end
|
676
|
+
end
|
677
|
+
|
579
678
|
# @rbs return [Array<Pathname>] all paths in Files.PrinterConfigPath
|
580
679
|
def printer_config_paths
|
581
680
|
ole_preferences_files.PrinterConfigPath.split(";").map { |f| Pathname.new(f) }
|
data/lib/autocad/arc.rb
CHANGED
@@ -2,14 +2,17 @@ require_relative "element"
|
|
2
2
|
|
3
3
|
module Autocad
|
4
4
|
class Arc < Element
|
5
|
+
# @rbs return Float
|
5
6
|
def length
|
6
7
|
@ole_obj.ArcLength
|
7
8
|
end
|
8
9
|
|
10
|
+
# @rbs return Point3d
|
9
11
|
def start_point
|
10
12
|
Point3d(ole_obj.StartPoint)
|
11
13
|
end
|
12
14
|
|
15
|
+
# @rbs return Point3d
|
13
16
|
def end_point
|
14
17
|
Point3d(ole_obj.EndPoint)
|
15
18
|
end
|