microstation 0.4.1
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.
- data/.autotest +23 -0
- data/.gemtest +0 -0
- data/.rspec +2 -0
- data/Gemfile +17 -0
- data/History.txt +6 -0
- data/Manifest.txt +60 -0
- data/README.txt +75 -0
- data/Rakefile +30 -0
- data/bin/dgn2pdf +37 -0
- data/lib/microstation.rb +88 -0
- data/lib/microstation/app.rb +286 -0
- data/lib/microstation/attributes.rb +35 -0
- data/lib/microstation/cad_input_queue.rb +25 -0
- data/lib/microstation/configuration.rb +57 -0
- data/lib/microstation/dir.rb +252 -0
- data/lib/microstation/drawing.rb +189 -0
- data/lib/microstation/enumerator.rb +29 -0
- data/lib/microstation/ext/pathname.rb +25 -0
- data/lib/microstation/extensions/hash.rb +27 -0
- data/lib/microstation/pdf_support.rb +40 -0
- data/lib/microstation/properties.rb +57 -0
- data/lib/microstation/scan/color.rb +38 -0
- data/lib/microstation/scan/criteria.rb +85 -0
- data/lib/microstation/scan/klass.rb +43 -0
- data/lib/microstation/scan/level.rb +38 -0
- data/lib/microstation/scan/line_style.rb +45 -0
- data/lib/microstation/scan/line_weight.rb +33 -0
- data/lib/microstation/scan/subtype.rb +40 -0
- data/lib/microstation/scan/type.rb +109 -0
- data/lib/microstation/scanner.rb +24 -0
- data/lib/microstation/tag.rb +58 -0
- data/lib/microstation/tag_set.rb +280 -0
- data/lib/microstation/template.rb +84 -0
- data/lib/microstation/text.rb +54 -0
- data/lib/microstation/text_node.rb +74 -0
- data/lib/microstation/ts/attribute.rb +139 -0
- data/lib/microstation/ts/instance.rb +112 -0
- data/lib/microstation/types.rb +91 -0
- data/lib/microstation/wrap.rb +214 -0
- data/plot/pdf-bw.plt +164 -0
- data/plot/pdf.plt +163 -0
- data/plot/png.plt +383 -0
- data/plot/tiff.plt +384 -0
- data/plot/wmbw.tbl +66 -0
- data/plot/wmcolor.tbl +62 -0
- data/spec/app_spec.rb +267 -0
- data/spec/configuration_spec.rb +122 -0
- data/spec/drawing_spec.rb +247 -0
- data/spec/drawings/new_drawing.dgn +0 -0
- data/spec/drawings/test.dgn +0 -0
- data/spec/drawings/test1.dgn +0 -0
- data/spec/drawings/testfile.pdf +0 -0
- data/spec/enumerator_spec.rb +60 -0
- data/spec/microstation_spec.rb +36 -0
- data/spec/scanner_spec.rb +155 -0
- data/spec/spec_app.rb +11 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/tag_set_spec.rb +123 -0
- data/spec/text_node_spec.rb +92 -0
- data/spec/text_spec.rb +62 -0
- metadata +241 -0
data/.autotest
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'autotest/restart'
|
4
|
+
|
5
|
+
# Autotest.add_hook :initialize do |at|
|
6
|
+
# at.extra_files << "../some/external/dependency.rb"
|
7
|
+
#
|
8
|
+
# at.libs << ":../some/external"
|
9
|
+
#
|
10
|
+
# at.add_exception 'vendor'
|
11
|
+
#
|
12
|
+
# at.add_mapping(/dependency.rb/) do |f, _|
|
13
|
+
# at.files_matching(/test_.*rb$/)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# %w(TestA TestB).each do |klass|
|
17
|
+
# at.extra_class_map[klass] = "test/test_misc.rb"
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
|
21
|
+
# Autotest.add_hook :run_command do |at|
|
22
|
+
# system "rake build"
|
23
|
+
# end
|
data/.gemtest
ADDED
File without changes
|
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
# DO NOT EDIT THIS FILE. Instead, edit Rakefile, and run `rake bundler:gemfile`.
|
4
|
+
|
5
|
+
source "https://rubygems.org/"
|
6
|
+
|
7
|
+
gem "methadone", ">=0.0.0"
|
8
|
+
gem "liquid", ">0.0.0"
|
9
|
+
gem "virtus", ">0.0.0"
|
10
|
+
|
11
|
+
gem "minitest", "~>4.6", :group => [:development, :test]
|
12
|
+
gem "rdoc", "~>3.10", :group => [:development, :test]
|
13
|
+
gem "rspec", ">0.0.0", :group => [:development, :test]
|
14
|
+
gem "pry-nav", ">0.0.0", :group => [:development, :test]
|
15
|
+
gem "hoe", "~>3.5", :group => [:development, :test]
|
16
|
+
|
17
|
+
# vim: syntax=ruby
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
.autotest
|
2
|
+
.rspec
|
3
|
+
Gemfile
|
4
|
+
History.txt
|
5
|
+
Manifest.txt
|
6
|
+
README.txt
|
7
|
+
Rakefile
|
8
|
+
bin/dgn2pdf
|
9
|
+
lib/microstation.rb
|
10
|
+
lib/microstation/app.rb
|
11
|
+
lib/microstation/attributes.rb
|
12
|
+
lib/microstation/cad_input_queue.rb
|
13
|
+
lib/microstation/configuration.rb
|
14
|
+
lib/microstation/dir.rb
|
15
|
+
lib/microstation/drawing.rb
|
16
|
+
lib/microstation/enumerator.rb
|
17
|
+
lib/microstation/ext/pathname.rb
|
18
|
+
lib/microstation/extensions/hash.rb
|
19
|
+
lib/microstation/pdf_support.rb
|
20
|
+
lib/microstation/properties.rb
|
21
|
+
lib/microstation/scan/color.rb
|
22
|
+
lib/microstation/scan/criteria.rb
|
23
|
+
lib/microstation/scan/klass.rb
|
24
|
+
lib/microstation/scan/level.rb
|
25
|
+
lib/microstation/scan/line_style.rb
|
26
|
+
lib/microstation/scan/line_weight.rb
|
27
|
+
lib/microstation/scan/subtype.rb
|
28
|
+
lib/microstation/scan/type.rb
|
29
|
+
lib/microstation/scanner.rb
|
30
|
+
lib/microstation/tag.rb
|
31
|
+
lib/microstation/tag_set.rb
|
32
|
+
lib/microstation/template.rb
|
33
|
+
lib/microstation/text.rb
|
34
|
+
lib/microstation/text_node.rb
|
35
|
+
lib/microstation/ts/attribute.rb
|
36
|
+
lib/microstation/ts/instance.rb
|
37
|
+
lib/microstation/types.rb
|
38
|
+
lib/microstation/wrap.rb
|
39
|
+
plot/pdf-bw.plt
|
40
|
+
plot/pdf.plt
|
41
|
+
plot/png.plt
|
42
|
+
plot/tiff.plt
|
43
|
+
plot/wmbw.tbl
|
44
|
+
plot/wmcolor.tbl
|
45
|
+
spec/app_spec.rb
|
46
|
+
spec/configuration_spec.rb
|
47
|
+
spec/drawing_spec.rb
|
48
|
+
spec/drawings/new_drawing.dgn
|
49
|
+
spec/drawings/test.dgn
|
50
|
+
spec/drawings/test1.dgn
|
51
|
+
spec/drawings/testfile.pdf
|
52
|
+
spec/enumerator_spec.rb
|
53
|
+
spec/microstation_spec.rb
|
54
|
+
spec/scanner_spec.rb
|
55
|
+
spec/spec_app.rb
|
56
|
+
spec/spec_helper.rb
|
57
|
+
spec/tag_set_spec.rb
|
58
|
+
spec/text_node_spec.rb
|
59
|
+
spec/text_spec.rb
|
60
|
+
|
data/README.txt
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
= microstation
|
2
|
+
|
3
|
+
http://github.com/dsisnero/microstation
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
this is a gem that wraps Bentley Microstation using the WIN32OLE
|
8
|
+
library.
|
9
|
+
|
10
|
+
== FEATURES/PROBLEMS:
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
== SYNOPSIS:
|
15
|
+
text_in_drawing = []
|
16
|
+
Microstation.run do |app|
|
17
|
+
sc = create_scanner do
|
18
|
+
include_color(3)
|
19
|
+
include_level(3)
|
20
|
+
end
|
21
|
+
app.open_drawing('./test.dgn') do |drawing|
|
22
|
+
drawing.scan_text do |text|
|
23
|
+
text.reverse! if text =~ /Reverse/ # things that modify thetext_in_drawing
|
24
|
+
puts text.to_s
|
25
|
+
end
|
26
|
+
drawing.scan( sc) do |ele|
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
drawing.save_as_pdf
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
== REQUIREMENTS:
|
36
|
+
|
37
|
+
An installed version of Microstation
|
38
|
+
|
39
|
+
== INSTALL:
|
40
|
+
|
41
|
+
* sudo gem install microstation
|
42
|
+
|
43
|
+
== DEVELOPERS:
|
44
|
+
|
45
|
+
After checking out the source, run:
|
46
|
+
|
47
|
+
$ rake
|
48
|
+
|
49
|
+
This task will install any missing dependencies, run the tests/specs,
|
50
|
+
and generate the RDoc.
|
51
|
+
|
52
|
+
== LICENSE:
|
53
|
+
|
54
|
+
(The MIT License)
|
55
|
+
|
56
|
+
Copyright (c) 2012 FIX
|
57
|
+
|
58
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
59
|
+
a copy of this software and associated documentation files (the
|
60
|
+
'Software'), to deal in the Software without restriction, including
|
61
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
62
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
63
|
+
permit persons to whom the Software is furnished to do so, subject to
|
64
|
+
the following conditions:
|
65
|
+
|
66
|
+
The above copyright notice and this permission notice shall be
|
67
|
+
included in all copies or substantial portions of the Software.
|
68
|
+
|
69
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
70
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
71
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
72
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
73
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
74
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
75
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake/clean'
|
5
|
+
require 'hoe'
|
6
|
+
#require 'hoe/git'
|
7
|
+
|
8
|
+
require 'rake/testtask'
|
9
|
+
|
10
|
+
CLEAN.include("**/#*.*#")
|
11
|
+
Hoe.plugin :bundler
|
12
|
+
Hoe.plugin :minitest
|
13
|
+
Hoe.plugin :git
|
14
|
+
# Hoe.plugin :rubyforge
|
15
|
+
|
16
|
+
Hoe.spec 'microstation' do
|
17
|
+
developer('Dominic Sisneros', 'dsisnero@gmail.com')
|
18
|
+
clean_globs << '**/#*.*#'
|
19
|
+
dependency('rspec', '> 0.0.0', :dev)
|
20
|
+
dependency('methadone','>= 0.0.0')
|
21
|
+
dependency('liquid', '> 0.0.0')
|
22
|
+
dependency('virtus', '> 0.0.0')
|
23
|
+
dependency('pry-nav', '>0.0.0',:dev)
|
24
|
+
|
25
|
+
# self.rubyforge_name = 'microstation' # if different than 'microstation'
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
# vim: syntax=ruby
|
data/bin/dgn2pdf
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'methadone'
|
5
|
+
require 'microstation'
|
6
|
+
|
7
|
+
class App
|
8
|
+
include Methadone::Main
|
9
|
+
include Methadone::CLILogging
|
10
|
+
|
11
|
+
main do |directory, output_dir|
|
12
|
+
|
13
|
+
directory_path = Pathname.new(directory).expand_path
|
14
|
+
exit_now! "arg directory: #{directory_path} doesn't exist" unless directory_path.directory?
|
15
|
+
|
16
|
+
Microstation.dgn2pdf(directory_path, output_dir)
|
17
|
+
# your program code here
|
18
|
+
# You can access CLI options via
|
19
|
+
# the options Hash
|
20
|
+
end
|
21
|
+
|
22
|
+
# supplemental methods here
|
23
|
+
|
24
|
+
# Declare command-line interface here
|
25
|
+
|
26
|
+
description "Convert a directory of Microstation files (*.dgn) to pdf"
|
27
|
+
|
28
|
+
on("-o","--output_dir","Output Dir")
|
29
|
+
|
30
|
+
|
31
|
+
arg :directory
|
32
|
+
arg :output_dir, :optional
|
33
|
+
|
34
|
+
use_log_level_option
|
35
|
+
|
36
|
+
go!
|
37
|
+
end
|
data/lib/microstation.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'win32ole'
|
2
|
+
require 'microstation/app'
|
3
|
+
require 'microstation/drawing'
|
4
|
+
require 'microstation/configuration'
|
5
|
+
require 'microstation/ext/pathname'
|
6
|
+
require 'microstation/cad_input_queue'
|
7
|
+
require 'microstation/scan/criteria'
|
8
|
+
require 'microstation/enumerator'
|
9
|
+
require 'microstation/text'
|
10
|
+
require 'microstation/text_node'
|
11
|
+
require 'microstation/template'
|
12
|
+
require 'microstation/tag_set'
|
13
|
+
require 'microstation/tag'
|
14
|
+
require 'microstation/dir'
|
15
|
+
|
16
|
+
require 'erb'
|
17
|
+
|
18
|
+
module Microstation
|
19
|
+
VERSION = '0.4.1'
|
20
|
+
|
21
|
+
def self.root
|
22
|
+
Pathname.new( File.dirname(__FILE__)).parent
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
def self.app
|
27
|
+
Microstation::App.new
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def self.plot_driver_directory
|
32
|
+
root + "plot"
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.use_template(template,context)
|
36
|
+
def context.binding
|
37
|
+
binding
|
38
|
+
end
|
39
|
+
opts = {:read_only => true}
|
40
|
+
Microstation::App.run do |app|
|
41
|
+
tmpfile = Tempfile.new('drawing')
|
42
|
+
app.new_drawing(tmpfile,template) do |drawing|
|
43
|
+
drawing.scan_text do |text|
|
44
|
+
compiled_template = ERB.new(text)
|
45
|
+
new_text = compiled_template.result(context.binding)
|
46
|
+
text = new_text
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
tempfile.read
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.drawings_in_dir(dir)
|
54
|
+
dirpath = Pathname.new(dir).expand_path
|
55
|
+
drawings = Pathname.glob("#{dirpath}/*.d{gn,wg}")
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.dgn2pdf(dir,output = dir)
|
59
|
+
drawings = drawings_in_dir(dir)
|
60
|
+
self.with_drawings(drawings) do |drawing|
|
61
|
+
drawing.save_as_pdf(drawing.name,output)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.open_drawing(drawing,options = {}, &block)
|
66
|
+
Microstation::App.open_drawing(drawing,options,&block)
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.with_drawings_in_dir(dir,&block)
|
70
|
+
drawings = self.drawings_in_dir(dir)
|
71
|
+
self.with_drawings(drawings,&block)
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.with_drawings(*files, &block)
|
75
|
+
Microstation::App.with_drawings(*files,&block)
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.run(options={}, &block)
|
79
|
+
options = {:visible => false}.merge(options)
|
80
|
+
begin
|
81
|
+
app = Microstation::App.new(options)
|
82
|
+
block.arity < 1 ? app.instance_eval(&block) : block.call(app)
|
83
|
+
ensure
|
84
|
+
app.quit
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,286 @@
|
|
1
|
+
require_relative 'wrap'
|
2
|
+
|
3
|
+
module Windows
|
4
|
+
|
5
|
+
class FileSystem
|
6
|
+
|
7
|
+
def self.windows_path(path)
|
8
|
+
obj = new
|
9
|
+
obj.windows_path(path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def fs_object
|
13
|
+
@fs_object ||= WIN32OLE.new('Scripting.FileSystemObject')
|
14
|
+
end
|
15
|
+
|
16
|
+
def windows_path(path)
|
17
|
+
path = path.to_path if path.respond_to? :to_path
|
18
|
+
fs_object.GetAbsolutePathName(path.to_str)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module Microstation
|
25
|
+
|
26
|
+
module MSD
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.win_fs
|
30
|
+
@windows_fs ||= Windows::FileSystem.new
|
31
|
+
end
|
32
|
+
|
33
|
+
class App
|
34
|
+
|
35
|
+
include Wrap
|
36
|
+
|
37
|
+
def self.run(options={})
|
38
|
+
begin
|
39
|
+
the_app = new(options)
|
40
|
+
|
41
|
+
yield the_app
|
42
|
+
ensure
|
43
|
+
the_app.quit
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.open_drawing(drawing,options={},&block)
|
48
|
+
self.run(options) do |app|
|
49
|
+
app.open_drawing(drawing,options,&block)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.with_drawings(*files,&block)
|
54
|
+
files = files[0] if files[0].kind_of? Array
|
55
|
+
opts = {:read_only => true}
|
56
|
+
self.run do |app|
|
57
|
+
files.each do |file|
|
58
|
+
puts "opening #{file}.."
|
59
|
+
app.open_drawing(file,opts) do |draw|
|
60
|
+
block.call draw
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def load_constants
|
68
|
+
WIN32OLE.const_load(@ole_obj, MSD) unless MSD.constants.size > 0
|
69
|
+
end
|
70
|
+
|
71
|
+
attr_reader :scanners
|
72
|
+
|
73
|
+
def initialize(options = {})
|
74
|
+
visible = options.fetch(:visible){ true }
|
75
|
+
|
76
|
+
@ole_obj = WIN32OLE.new('MicrostationDGN.Application')
|
77
|
+
@windows = Windows::FileSystem.new
|
78
|
+
make_visible(visible)
|
79
|
+
@scanners = []
|
80
|
+
end
|
81
|
+
|
82
|
+
def visible?
|
83
|
+
@visible
|
84
|
+
end
|
85
|
+
|
86
|
+
def project_dir
|
87
|
+
@project_dir
|
88
|
+
end
|
89
|
+
|
90
|
+
def project_dir=(dir)
|
91
|
+
@project_dir = dir ? Pathname.new(dir) : dir
|
92
|
+
end
|
93
|
+
|
94
|
+
def base_dir
|
95
|
+
project_dir ? project_dir : Pathname.getwd
|
96
|
+
end
|
97
|
+
|
98
|
+
def normalize_name(name)
|
99
|
+
name = Pathname.new(name) unless name.kind_of? Pathname
|
100
|
+
name = name.ext('.dgn') unless name.extname.to_s == /\.(dgn|dwg)$/
|
101
|
+
return (base_dir + name).expand_path
|
102
|
+
end
|
103
|
+
|
104
|
+
def make_visible(visible)
|
105
|
+
@visible = visible
|
106
|
+
@ole_obj.Visible = @visible
|
107
|
+
end
|
108
|
+
|
109
|
+
attr_reader :ole_obj
|
110
|
+
|
111
|
+
# def method_missing(name,*args,&block)
|
112
|
+
# @ole_obj.send(name,*args,&block)
|
113
|
+
# end
|
114
|
+
|
115
|
+
def with_drawing(drawing)
|
116
|
+
begin
|
117
|
+
yield drawing
|
118
|
+
ensure
|
119
|
+
drawing.close
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def with_template(template)
|
124
|
+
template = Template.new(template,self)
|
125
|
+
yield template
|
126
|
+
template = nil
|
127
|
+
end
|
128
|
+
|
129
|
+
def open_drawing(filename,options = {})
|
130
|
+
filename = Pathname(filename)
|
131
|
+
raise FileNotFound unless filename.file?
|
132
|
+
readonly = options.fetch(:read_only){ false}
|
133
|
+
ole = @ole_obj.OpenDesignFile(windows_path(filename), "ReadOnly" => readonly)
|
134
|
+
drawing = drawing_from_ole(ole)
|
135
|
+
return drawing unless block_given?
|
136
|
+
begin
|
137
|
+
yield drawing
|
138
|
+
rescue
|
139
|
+
puts "got error"
|
140
|
+
ensure
|
141
|
+
drawing.close
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
def windows_path(path)
|
147
|
+
@windows.windows_path(path)
|
148
|
+
end
|
149
|
+
|
150
|
+
def active_workspace
|
151
|
+
@ole_obj.ActiveWorkspace
|
152
|
+
end
|
153
|
+
|
154
|
+
def configuration
|
155
|
+
@config ||= Microstation::Configuration.new(self)
|
156
|
+
end
|
157
|
+
|
158
|
+
def username
|
159
|
+
configuration["USERNAME"]
|
160
|
+
end
|
161
|
+
|
162
|
+
# seedfile A String expression. The name of the seed file. Should not include a path. The default extension is ".dgn".
|
163
|
+
# Typical values are "seed2d" or "seed3d".
|
164
|
+
# open
|
165
|
+
# If the open argument is True, CreateDesignFile returns the newly-opened DesignFile object; this is the same value as
|
166
|
+
# ActiveDesignFile. If the Open argument is False, CreateDesignFile returns Nothing.
|
167
|
+
def new_drawing(filename, seedfile=nil ,open = true,&block)
|
168
|
+
#drawing_name = normalize_name(filename)
|
169
|
+
seedfile = determine_seed(seedfile)
|
170
|
+
windows_name = windows_path(filename)
|
171
|
+
ole = @ole_obj.CreateDesignFile(seedfile, windows_name, open)
|
172
|
+
drawing = drawing_from_ole(ole)
|
173
|
+
return drawing unless block_given?
|
174
|
+
begin
|
175
|
+
yield drawing
|
176
|
+
rescue
|
177
|
+
ensure
|
178
|
+
drawing.close
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
def drawing_from_ole(ole)
|
184
|
+
Drawing.new(self,ole)
|
185
|
+
end
|
186
|
+
|
187
|
+
def determine_seed(seedfile)
|
188
|
+
return "seed2d" unless seedfile
|
189
|
+
return windows_path( File.expand_path(seedfile))
|
190
|
+
end
|
191
|
+
|
192
|
+
def eval_cexpression(string)
|
193
|
+
@ole_obj.GetCExpressionValue(string)
|
194
|
+
end
|
195
|
+
|
196
|
+
def quit
|
197
|
+
active_design_file.close if active_file?
|
198
|
+
@scanners.each{|sc| sc.close}
|
199
|
+
@ole_obj.quit
|
200
|
+
end
|
201
|
+
|
202
|
+
def active_design_file
|
203
|
+
ole = @ole_obj.ActiveDesignFile rescue nil
|
204
|
+
drawing_from_ole(ole) if ole
|
205
|
+
end
|
206
|
+
|
207
|
+
def current_drawing
|
208
|
+
active_design_file
|
209
|
+
end
|
210
|
+
|
211
|
+
# alias :current_drawing :active_design_file
|
212
|
+
|
213
|
+
def close_active_drawing
|
214
|
+
active_design_file.close if active_design_file
|
215
|
+
end
|
216
|
+
|
217
|
+
def active_file?
|
218
|
+
!!active_design_file
|
219
|
+
end
|
220
|
+
|
221
|
+
def file_exists?(file)
|
222
|
+
File.file?( File.expand_path(file) )
|
223
|
+
end
|
224
|
+
|
225
|
+
def create_scanner(&block)
|
226
|
+
Microstation::Scan::Criteria.create_scanner(self,&block)
|
227
|
+
end
|
228
|
+
|
229
|
+
def find_by_id(id)
|
230
|
+
model = active_model_reference.GetElementById64(id)
|
231
|
+
wrap(model)
|
232
|
+
end
|
233
|
+
|
234
|
+
def scan(criteria = nil)
|
235
|
+
result = []
|
236
|
+
raise 'NoActiveModel' unless active_model_reference
|
237
|
+
if criteria
|
238
|
+
criteria.resolve
|
239
|
+
ee = active_model_reference.Scan(criteria.ole_obj)
|
240
|
+
else
|
241
|
+
ee = active_model_reference.Scan(nil)
|
242
|
+
end
|
243
|
+
scan_result = Microstation::Enumerator.new ee
|
244
|
+
return scan_result.to_enum unless block_given?
|
245
|
+
scan_result.each do |item|
|
246
|
+
yield item
|
247
|
+
end
|
248
|
+
nil
|
249
|
+
end
|
250
|
+
|
251
|
+
def cad_input_queue
|
252
|
+
queue = init_cad_input_queue
|
253
|
+
return queue unless block_given?
|
254
|
+
begin
|
255
|
+
yield queue
|
256
|
+
rescue
|
257
|
+
|
258
|
+
ensure
|
259
|
+
queue.close
|
260
|
+
queue = nil
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
def can_open?(filename)
|
265
|
+
ext = File.extname(filename)
|
266
|
+
(ext == ".dwg") || (ext == ".dgn")
|
267
|
+
end
|
268
|
+
|
269
|
+
def active_model_reference
|
270
|
+
@ole_obj.ActiveModelReference rescue nil
|
271
|
+
end
|
272
|
+
|
273
|
+
private
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
|
278
|
+
def init_cad_input_queue
|
279
|
+
Microstation::CadInputQueue.new(@ole_obj.CadInputQueue)
|
280
|
+
end
|
281
|
+
|
282
|
+
|
283
|
+
end
|
284
|
+
|
285
|
+
end
|
286
|
+
|