microstation 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'virtus'
|
2
|
+
|
3
|
+
module Microstation
|
4
|
+
|
5
|
+
module Attribute
|
6
|
+
|
7
|
+
|
8
|
+
class Base < Virtus::Attribute::Object
|
9
|
+
|
10
|
+
accept_options :is_hidden, :prompt, :readonly
|
11
|
+
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
class String < Base
|
16
|
+
|
17
|
+
primitive ::String
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
class Integer < Base
|
22
|
+
end
|
23
|
+
|
24
|
+
class Float < Base
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Microstation
|
2
|
+
|
3
|
+
|
4
|
+
class CadInputQueue
|
5
|
+
|
6
|
+
def initialize(ole_obj)
|
7
|
+
@ole_obj = ole_obj
|
8
|
+
end
|
9
|
+
|
10
|
+
def <<(string)
|
11
|
+
send_keyin(string)
|
12
|
+
end
|
13
|
+
|
14
|
+
def send_keyin(string)
|
15
|
+
@ole_obj.SendKeyin(string)
|
16
|
+
end
|
17
|
+
|
18
|
+
def close
|
19
|
+
@ole_ojb = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Microstation
|
2
|
+
|
3
|
+
class VariableDefined < ::StandardError
|
4
|
+
end
|
5
|
+
|
6
|
+
class Configuration
|
7
|
+
|
8
|
+
def initialize(app)
|
9
|
+
@app = app
|
10
|
+
end
|
11
|
+
|
12
|
+
def [](variable)
|
13
|
+
return nil unless exists? variable
|
14
|
+
value(variable)
|
15
|
+
end
|
16
|
+
|
17
|
+
def should_update?(key,options={force: false})
|
18
|
+
return true unless exists? key
|
19
|
+
force = options.fetch(:force){ false}
|
20
|
+
return !!force
|
21
|
+
end
|
22
|
+
|
23
|
+
def remove_variable(variable)
|
24
|
+
workspace.RemoveConfigurationVariable variable
|
25
|
+
end
|
26
|
+
|
27
|
+
def set(key,value,options = {})
|
28
|
+
raise Microstation::VariableDefined unless should_update?(key,options)
|
29
|
+
workspace.AddConfigurationVariable(key,value)
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def []=(key,value)
|
34
|
+
set(key,value)
|
35
|
+
end
|
36
|
+
|
37
|
+
def value(variable)
|
38
|
+
workspace.ConfigurationVariableValue(variable)
|
39
|
+
end
|
40
|
+
|
41
|
+
def exists?(value)
|
42
|
+
workspace.IsConfigurationVariableDefined(value)
|
43
|
+
end
|
44
|
+
|
45
|
+
def expand(string)
|
46
|
+
workspace.ExpandConfigurationVariable(string)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
def workspace
|
51
|
+
@app.active_workspace
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,252 @@
|
|
1
|
+
require_relative 'pdf_support'
|
2
|
+
require 'fileutils'
|
3
|
+
module Microstation
|
4
|
+
|
5
|
+
class Dir
|
6
|
+
|
7
|
+
include PdfSupport
|
8
|
+
include FileUtils::Verbose
|
9
|
+
|
10
|
+
attr_reader :dir, :relative_pdf_path
|
11
|
+
|
12
|
+
def initialize(dir,pdf_path=nil)
|
13
|
+
@dir = Pathname(dir).expand_path
|
14
|
+
@relative_pdf_path = set_relative_pdf_path(pdf_path)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.Dir(path)
|
18
|
+
case path
|
19
|
+
when Microstation::Dir
|
20
|
+
path
|
21
|
+
else
|
22
|
+
new(Pathname(path))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def ==(other)
|
27
|
+
self.dir == other.dir && self.relative_pdf_path == other.relative_pdf_path
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_path
|
31
|
+
@dir.to_path
|
32
|
+
end
|
33
|
+
|
34
|
+
def path
|
35
|
+
@dir
|
36
|
+
end
|
37
|
+
|
38
|
+
def directory?
|
39
|
+
path.directory?
|
40
|
+
end
|
41
|
+
|
42
|
+
def exist?
|
43
|
+
path.exist?
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
def mkdir
|
48
|
+
@dir.mkdir
|
49
|
+
end
|
50
|
+
|
51
|
+
def mkpath
|
52
|
+
@dir.mkpath
|
53
|
+
end
|
54
|
+
|
55
|
+
def +(other)
|
56
|
+
self.class.new( self.path + other)
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def copy(drawing,dir)
|
61
|
+
cp drawing, dir
|
62
|
+
end
|
63
|
+
|
64
|
+
def select_by_name( re)
|
65
|
+
re = Regexp.new(re)
|
66
|
+
drawing_files.select{|n| n.to_path =~ re}
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def find_by_name(re)
|
71
|
+
re = Regexp.new(re)
|
72
|
+
drawing_files.find{|n| n.to_path =~ re}
|
73
|
+
end
|
74
|
+
|
75
|
+
def drawings
|
76
|
+
Pathname.glob(@dir + "*.d{gn,wg}")
|
77
|
+
end
|
78
|
+
|
79
|
+
def sort_by(&block)
|
80
|
+
@sort_by = block
|
81
|
+
end
|
82
|
+
|
83
|
+
def sort(array_of_files)
|
84
|
+
sort_lambda = @sort_by || lambda{|f| f.path.to_s}
|
85
|
+
array_of_files.sort_by(&sort_lambda)
|
86
|
+
end
|
87
|
+
|
88
|
+
def drawing_files
|
89
|
+
return @drawing_files if @drawing_files
|
90
|
+
set_drawing_files(drawings.map{|dwg| Microstation::Drawing::File.new(dwg)} )
|
91
|
+
@drawing_files
|
92
|
+
end
|
93
|
+
|
94
|
+
def set_drawing_files(dfiles)
|
95
|
+
@drawing_files = sort(dfiles)
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
def pdf_generation_complete?
|
100
|
+
drawing_files.all?{|d| not d.needs_pdf?}
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
def pdf_files(dir = pdf_dirname)
|
105
|
+
sort(drawing_files).map{|p| p.pdf_name(dir)}
|
106
|
+
end
|
107
|
+
|
108
|
+
def concat_pdfs(files)
|
109
|
+
Pdftk.concat(files)
|
110
|
+
end
|
111
|
+
|
112
|
+
def drawing_files_needing_pdf(dir = pdf_dirname)
|
113
|
+
drawing_files.select{|d| d.needs_pdf?(dir) }
|
114
|
+
end
|
115
|
+
|
116
|
+
def print_pdfs(dir = pdf_dirname)
|
117
|
+
with_drawing_files( drawing_files_needing_pdf) do |drawing|
|
118
|
+
drawing.save_as_pdf(:dir => dir)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def generate_pdfs(dir = pdf_dirname)
|
123
|
+
print_pdfs(dir)
|
124
|
+
concat_pdfs(pdf_files(dir), dir + "dir.combined.drawings.pdf")
|
125
|
+
end
|
126
|
+
|
127
|
+
def find_pdftk(dirs = nil)
|
128
|
+
require 'pdf_forms'
|
129
|
+
@pdftk = PdfForms.new('e:/tools/pdftk-1.44/bin/pdftk.exe')
|
130
|
+
end
|
131
|
+
|
132
|
+
def pdftk
|
133
|
+
@pdftk ||= find_pdftk(dirs= nil)
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
def concat_pdfs(files,name)
|
138
|
+
pdftk.cat(files,name.to_s)
|
139
|
+
puts "generated #{name}"
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
def get_meta_for_drawings
|
145
|
+
@drawing_files = nil
|
146
|
+
files = []
|
147
|
+
with_drawing_files( drawings) do |drawing|
|
148
|
+
files << Microstation::Drawing::File.from_drawing(drawing)
|
149
|
+
end
|
150
|
+
set_drawing_files(files)
|
151
|
+
end
|
152
|
+
|
153
|
+
def with_drawing_files(dwgs = drawing_files, &block)
|
154
|
+
Microstation.with_drawings(dwgs,&block)
|
155
|
+
end
|
156
|
+
|
157
|
+
def pdf_dirname
|
158
|
+
if relative_pdf_path.absolute?
|
159
|
+
relative_pdf_path
|
160
|
+
else
|
161
|
+
dir + relative_pdf_path
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def set_relative_pdf_path(path)
|
166
|
+
rel_path = path.nil? ? "." : path
|
167
|
+
Pathname(rel_path)
|
168
|
+
end
|
169
|
+
|
170
|
+
|
171
|
+
def relative_pdf_path=(path)
|
172
|
+
@relative_pdf_path = set_relative_path(path)
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
module Microstation
|
181
|
+
|
182
|
+
class Drawing
|
183
|
+
|
184
|
+
class File
|
185
|
+
|
186
|
+
include PdfSupport
|
187
|
+
|
188
|
+
attr_reader :keywords, :creator, :path
|
189
|
+
|
190
|
+
def self.from_drawing(drawing)
|
191
|
+
file = new(drawing.path)
|
192
|
+
file.get_meta(drawing)
|
193
|
+
file
|
194
|
+
end
|
195
|
+
|
196
|
+
def to_path
|
197
|
+
@path.to_path
|
198
|
+
end
|
199
|
+
|
200
|
+
|
201
|
+
def initialize(path)
|
202
|
+
@path = Pathname(path)
|
203
|
+
end
|
204
|
+
|
205
|
+
def basename
|
206
|
+
@path.basename
|
207
|
+
end
|
208
|
+
|
209
|
+
def dirname
|
210
|
+
@path.dirname
|
211
|
+
end
|
212
|
+
|
213
|
+
def drawing=(drawing)
|
214
|
+
@drawing = drawing
|
215
|
+
end
|
216
|
+
|
217
|
+
def mtime
|
218
|
+
self.path.mtime
|
219
|
+
end
|
220
|
+
|
221
|
+
def title
|
222
|
+
@title ||= get_meta
|
223
|
+
end
|
224
|
+
|
225
|
+
def app_open_drawing(app, &block)
|
226
|
+
draw = app.open_drawing(self.path,&block)
|
227
|
+
end
|
228
|
+
|
229
|
+
def open_drawing(&block)
|
230
|
+
Microstation.open_drawing(self.path,&block)
|
231
|
+
end
|
232
|
+
|
233
|
+
def get_meta(dwg)
|
234
|
+
@title = dwg.title
|
235
|
+
@keywords = dwg.keywords
|
236
|
+
@creator = dwg.creator
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
|
@@ -0,0 +1,189 @@
|
|
1
|
+
require_relative 'properties'
|
2
|
+
require 'pry'
|
3
|
+
module Microstation
|
4
|
+
|
5
|
+
class Drawing
|
6
|
+
|
7
|
+
include Properties
|
8
|
+
|
9
|
+
attr_reader :app
|
10
|
+
|
11
|
+
def initialize(app, ole)
|
12
|
+
@app = app
|
13
|
+
@ole_obj = ole
|
14
|
+
end
|
15
|
+
|
16
|
+
def active?
|
17
|
+
@ole_obj.IsActive
|
18
|
+
end
|
19
|
+
|
20
|
+
def cad_input_queue(&block)
|
21
|
+
@app.cad_input_queue(&block)
|
22
|
+
end
|
23
|
+
|
24
|
+
def save_as_pdf(name = nil, dir = nil)
|
25
|
+
out_name = pdf_name(name,dir)
|
26
|
+
windows_name = app.windows_path(out_name)
|
27
|
+
cad_input_queue do |q|
|
28
|
+
q << "Print Driver #{pdf_driver}"
|
29
|
+
q << "Print Papername ANSI D"
|
30
|
+
q << "Print BOUNDARY FIT ALL"
|
31
|
+
q << "Print ATTRIBUTES BORDER OUTLINE OFF"
|
32
|
+
q << "Print Attributes Fenceboundary Off"
|
33
|
+
q << "Print Execute #{windows_name}"
|
34
|
+
end
|
35
|
+
puts "saved #{windows_name}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def pdf_name_from_options(options = {})
|
39
|
+
name = options.fetch(:name){ basename.ext('.pdf')}
|
40
|
+
dir = options.fetch(:dir){ dirname}
|
41
|
+
(dir + name).expand_path
|
42
|
+
end
|
43
|
+
|
44
|
+
# alias_method :title, :title=
|
45
|
+
|
46
|
+
def create_scanner(&block)
|
47
|
+
app.create_scanner(&block)
|
48
|
+
end
|
49
|
+
|
50
|
+
def scan(scanner = nil,&block)
|
51
|
+
app.scan(scanner,&block)
|
52
|
+
end
|
53
|
+
|
54
|
+
def scan_graphical(&block)
|
55
|
+
sc = create_scanner
|
56
|
+
sc.ExcludeNonGraphical
|
57
|
+
app.scan(sc,&block)
|
58
|
+
end
|
59
|
+
|
60
|
+
def scan_text(&block)
|
61
|
+
sc = create_scanner do
|
62
|
+
include_textual
|
63
|
+
end
|
64
|
+
app.scan(sc,&block)
|
65
|
+
end
|
66
|
+
|
67
|
+
def scan_tags(&block)
|
68
|
+
sc = create_scanner do
|
69
|
+
include_tags
|
70
|
+
end
|
71
|
+
app.scan(sc,&block)
|
72
|
+
end
|
73
|
+
|
74
|
+
def modified_date
|
75
|
+
@ole_obj.DateLastSaved
|
76
|
+
end
|
77
|
+
# alias_method :keywords , :keywords=x
|
78
|
+
|
79
|
+
def dimensions
|
80
|
+
eval_cexpression("tcb->ndices")
|
81
|
+
end
|
82
|
+
|
83
|
+
# def fullname
|
84
|
+
# @ole_obj.FullName
|
85
|
+
# end
|
86
|
+
|
87
|
+
def two_d?
|
88
|
+
dimensions == 2
|
89
|
+
end
|
90
|
+
|
91
|
+
def three_d?
|
92
|
+
dimensions == 3
|
93
|
+
end
|
94
|
+
|
95
|
+
def name
|
96
|
+
@ole_obj.Name
|
97
|
+
end
|
98
|
+
|
99
|
+
def basename
|
100
|
+
Pathname(name)
|
101
|
+
end
|
102
|
+
|
103
|
+
def dirname
|
104
|
+
Pathname(@ole_obj.Path).expand_path
|
105
|
+
end
|
106
|
+
|
107
|
+
def path
|
108
|
+
dirname + basename
|
109
|
+
end
|
110
|
+
|
111
|
+
def revision_count
|
112
|
+
@ole_obj.DesignRevisionCount
|
113
|
+
end
|
114
|
+
|
115
|
+
def eval_cexpression(string)
|
116
|
+
app.eval_cexpression(string)
|
117
|
+
end
|
118
|
+
|
119
|
+
def close
|
120
|
+
@ole_obj.Close
|
121
|
+
end
|
122
|
+
|
123
|
+
def ole_obj
|
124
|
+
@ole_obj
|
125
|
+
end
|
126
|
+
|
127
|
+
def pdf_name(lname = nil,dir=nil)
|
128
|
+
dname = lname ? Pathname(lname) : Pathname(self.basename)
|
129
|
+
pdfname = dname.ext('.pdf')
|
130
|
+
dirname = dir ? Pathname(dir) : Pathname(self.dirname)
|
131
|
+
pdfname = (dirname + pdfname).expand_path
|
132
|
+
end
|
133
|
+
|
134
|
+
def pdf_driver
|
135
|
+
app.windows_path( (Microstation.plot_driver_directory + "pdf-bw.plt").to_s)
|
136
|
+
end
|
137
|
+
|
138
|
+
def tagset_names
|
139
|
+
tagsets.map{|ts| ts.name}
|
140
|
+
end
|
141
|
+
|
142
|
+
def tagsets
|
143
|
+
@tagsets = TagSets.new(ole_obj_tagsets)
|
144
|
+
end
|
145
|
+
|
146
|
+
def create_tagset(name,&block)
|
147
|
+
ts = tagsets.create(name)
|
148
|
+
block.call ts if block
|
149
|
+
ts
|
150
|
+
end
|
151
|
+
|
152
|
+
def create_tagset!(name,&block)
|
153
|
+
remove_tagset(name)
|
154
|
+
create_tagset(name,&block)
|
155
|
+
end
|
156
|
+
|
157
|
+
def remove_tagset(name)
|
158
|
+
tagsets.remove(name)
|
159
|
+
end
|
160
|
+
|
161
|
+
def find_tagset(name)
|
162
|
+
ts = tagsets[name]
|
163
|
+
ts.create_instances(scan_tags)
|
164
|
+
end
|
165
|
+
|
166
|
+
protected
|
167
|
+
def ole_obj_tagsets
|
168
|
+
@ole_obj.TagSets
|
169
|
+
end
|
170
|
+
|
171
|
+
def ensure_tags(tags)
|
172
|
+
tags.map{|t| t.class == WIN32OLE ? app.wrap(t) : t }
|
173
|
+
end
|
174
|
+
|
175
|
+
# def create_tagset_instances(name,groups)
|
176
|
+
# ts = tagsets[name]
|
177
|
+
# ts.add_instance(group) if ts
|
178
|
+
# end
|
179
|
+
|
180
|
+
def save
|
181
|
+
@ole_obj.Save
|
182
|
+
end
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|