Class: Microstation::App
- Inherits:
-
Object
- Object
- Microstation::App
- Includes:
- Functions
- Defined in:
- lib/microstation/app.rb,
lib/microstation/element.rb,
lib/microstation/functions.rb,
lib/microstation/functions.rb,
lib/microstation/configuration.rb,
lib/microstation/configuration.rb,
lib/microstation/scan/criteria.rb
Class Attribute Summary collapse
-
.default_app_options ⇒ Object
Returns the value of attribute default_app_options.
Instance Attribute Summary collapse
-
#app_event ⇒ Object
readonly
Returns the value of attribute app_event.
-
#project_dir ⇒ Object
Returns the value of attribute project_dir.
-
#scanners ⇒ Object
readonly
Returns the value of attribute scanners.
-
#visible ⇒ Object
Returns the value of attribute visible.
Class Method Summary collapse
-
.open_drawing(drawing, app_options: {}, options: {}) { ... } ⇒ void
Calls #run to get an app instance then call open drawing with that app (see #open_drawing).
-
.run(options = {}) {|App| ... } ⇒ void
Initialize an instance of app with the options [source] —- App.run do |app| drawing = app.open_drawing(‘test.dgn’) drawing.scan_all_text do |model,text| puts “#model #text” end end.
-
.with_drawings(*files, visible: true, readonly: false, error_proc: ::Microstation.default_error_proc) {|Drawing| ... } ⇒ void
Runs the app, opening the filenames and yielding each open drawing to the supplied block it automatically closes the drawing and the app when done.
Instance Method Summary collapse
-
#active_design_file ⇒ Drawing
(also: #active_drawing, #current_drawing)
the active design file.
-
#active_design_file? ⇒ Boolean
(also: #current_design_file?)
True if app has an active design file open.
- #active_model_reference ⇒ Object
- #active_workspace ⇒ Object
- #base_dir ⇒ Object
-
#cad_input_queue {|CadInputQueue| ... } ⇒ void
lets you interact with the cad_input_queue.
- #can_open?(filename) ⇒ Boolean
- #capabilities(mode = :all) ⇒ Object
- #change_drawing(dgn, output_dir: nil, name: nil, options: {}, &block) ⇒ Object
-
#close_active_drawing ⇒ void
(also: #close_current_drawing)
close the active_design_file.
- #configuration ⇒ Object
-
#configured_seed_paths ⇒ String
The configuration variable MS_SEEDFILES.
-
#create_ole_point(x, y, z = 0) ⇒ WIN32OLE_RECORD
Create an WIN32OLE_RECORD of type Point3d.
- #create_ole_scan_criteria ⇒ Object
- #create_scan_criteria(name = nil, &block) ⇒ Object
- #create_scanner(name = nil, &block) ⇒ Object
- #create_text_node(origin, rotation, temp = nil) ⇒ Object
-
#default_event_handler ⇒ EventHandler
the default EventHandler.
- #default_model ⇒ Object
- #determine_seed(seedfile) ⇒ Object
- #drawing_from_ole(ole) ⇒ Object
- #drawing_opened? ⇒ Boolean
- #eval_cexpression(string) ⇒ Object
- #exit_message_looop ⇒ Object
-
#file_exists?(file) ⇒ Boolean
<Description>.
-
#find_seed(seedfile) ⇒ Pathname
find the seedfile * If the seed file is absolute and found the return the seedfile.
- #find_seed_in_seed_dirs(seedfile) ⇒ Object
-
#get_handler(event) ⇒ Proc
return a Handler.
- #get_ole_element_enumerator(model:, criteria: nil) ⇒ Object
- #has_current_drawing? ⇒ Boolean
- #init_ole_and_app_event(visible: @visible, event_handler: @event_handler, tries: 5, sleep_duration: 1) ⇒ Object
-
#initialize(visible: false, event_handler: default_event_handler) ⇒ App
constructor
Constructor for app.
- #make_visible(visible) ⇒ Object
- #method_missing(meth, *args, &block) ⇒ Object
- #my_place_line ⇒ Object
-
#new_drawing(filename, seedfile: nil, open: true, wait_time: 500, wait_interval: 1, &block) ⇒ Drawing
create a new drawing.
- #new_ole_drawing(seedfile, new_design_file_name, open: true, wait_time: 500, wait_interval: 0.5) ⇒ Object
- #normalize_name(name) ⇒ Object
- #ole_matrix ⇒ Object
- #ole_obj ⇒ Object
- #ole_point ⇒ Object
-
#ole_point3d?(pt) ⇒ Boolean
<Description>.
- #ole_rotation ⇒ Object
- #ole_to_ruby(ole) ⇒ Object
-
#open_drawing(filename, readonly: false, error_proc: nil, wait_time: 500, wait_interval: 0.5) {|Drawing| ... } ⇒ void
open the drawing.
-
#prepend_seed_path(dir) ⇒ Object
prepend a dir to the MS_SEEDFILES configuration.
-
#quit ⇒ void
quit the app.
-
#register_handler(event, &block) ⇒ <Type>
register an handler.
- #render_template(drawing, output_dir: nil, locals: {}, name: nil) ⇒ Object
- #run_templates_in_dir(dir, options = {}) ⇒ Object
-
#scan_model(criteria = nil, model = nil) ⇒ Object
def find_by_id(id) active_design_file.find_by_id(id) wrap(model) if el end.
-
#seed_paths ⇒ Array
Returns the MS_SEEDFILES as Pathnames Array.
- #show_command(text) ⇒ Object
- #show_message(text) ⇒ Object
- #show_prompt(text) ⇒ Object
- #show_temp_message(text, location: nil) ⇒ void
- #start_primitive(klass) ⇒ Object
- #tags_criteria ⇒ Object
- #text_criteria ⇒ Object
- #to_ole_matrix3d(vec) ⇒ Object
-
#to_ole_point3d(pt) ⇒ WIN32OLE_RECORD
Conversion to WIN32OLE_RECORD of type Point3d.
- #to_point(pt) ⇒ Object
-
#to_point3d(pt) ⇒ Point3d
convert pt to Point3d.
-
#username ⇒ String
The configuration variable USERNAME.
-
#visible? ⇒ Boolean
Whether the app is visible.
- #wait_drawing_opened(secs, interval = 1) ⇒ Object
- #windows_path(path) ⇒ Object
- #with_config ⇒ Object
- #with_drawing(drawing) ⇒ Object
- #with_template(template) {|template| ... } ⇒ Object
- #wrap(item, cell = nil) ⇒ Object
Methods included from Functions
#clear_ui, #get_point, #get_points_by_line, #get_points_by_rectangle
Constructor Details
#initialize(visible: false, event_handler: default_event_handler) ⇒ App
Constructor for app
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/microstation/app.rb', line 145 def initialize(visible: false, event_handler: default_event_handler) @visible = visible @event_handler = event_handler @ole_obj, @app_event = init_ole_and_app_event(visible: @visible, event_handler: @event_handler, tries: 5, sleep_duration: 0.5) @run_loop = true @windows = Windows::FileSystem.new # make_visible(visible) @scanners = {} rescue StandardError => e binding.pry end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
740 741 742 743 744 745 746 747 748 749 |
# File 'lib/microstation/app.rb', line 740 def method_missing(meth, *args, &block) if meth.to_s =~ /^[A-Z]/ require 'pry'; binding.pry result = ole_obj.send(meth, *args, &block) else super(meth, *args, &block) end rescue StandardError => e binding.pry end |
Class Attribute Details
.default_app_options ⇒ Object
Returns the value of attribute default_app_options.
49 50 51 |
# File 'lib/microstation/app.rb', line 49 def @default_app_options end |
Instance Attribute Details
#app_event ⇒ Object (readonly)
Returns the value of attribute app_event.
140 141 142 |
# File 'lib/microstation/app.rb', line 140 def app_event @app_event end |
#project_dir ⇒ Object
Returns the value of attribute project_dir.
140 141 142 |
# File 'lib/microstation/app.rb', line 140 def project_dir @project_dir end |
#scanners ⇒ Object (readonly)
Returns the value of attribute scanners.
140 141 142 |
# File 'lib/microstation/app.rb', line 140 def scanners @scanners end |
#visible ⇒ Object
Returns the value of attribute visible.
140 141 142 |
# File 'lib/microstation/app.rb', line 140 def visible @visible end |
Class Method Details
.open_drawing(drawing, app_options: {}, options: {}) { ... } ⇒ void
This method returns an undefined value.
Calls #run to get an app instance then call open drawing with that app (see #open_drawing)
89 90 91 92 93 |
# File 'lib/microstation/app.rb', line 89 def open_drawing(drawing, app_options: {}, options: {}, &block) run(**) do |app| app.open_drawing(drawing, **, &block) end end |
.run(options = {}) {|App| ... } ⇒ void
This method returns an undefined value.
Initialize an instance of app with the options
- source
App.run do |app|
drawing = app.open_drawing('test.dgn') drawing.scan_all_text do |model,text| puts "#{model} #{text}" end
end
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/microstation/app.rb', line 68 def run( = {}) opts = self..merge() begin the_app = new(**opts) binding.pry if the_app.nil? yield the_app rescue StandardError binding.pry ensure the_app.quit if the_app.respond_to? :quit the_app = nil GC.start nil end end |
.with_drawings(*files, visible: true, readonly: false, error_proc: ::Microstation.default_error_proc) {|Drawing| ... } ⇒ void
This method returns an undefined value.
Runs the app, opening the filenames and yielding each open drawing to the supplied block it automatically closes the drawing and the app when done
- source
-
dir = Pathname(‘C:/templates’) drawings = Pathname.glob(dir + ‘/*/.dgn’) App.with_drawings(drawings) do |drawing|
drawing.save_as_pdf(dir: 'c:/output/')
end
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/microstation/app.rb', line 114 def with_drawings(*files, visible: true, readonly: false, error_proc: ::Microstation.default_error_proc, &block) # drawing_options = default_drawing_options.merge(options) # app_options = default_app_options errors = [] files = files[0] if files[0].is_a? Array begin the_app = new(visible: visible) files_enum = files.each loop do file = files_enum.next puts "opening #{file}.." begin the_app.open_drawing(file, readonly: readonly, error_proc: error_proc, &block) the_app.ole_obj.ole_methods # check if server still open rescue StandardError => e error_proc.call(e, file) the_app = new() end end ensure the_app&.quit the_app = nil end end |
Instance Method Details
#active_design_file ⇒ Drawing Also known as: active_drawing, current_drawing
the active design file
486 487 488 489 490 491 |
# File 'lib/microstation/app.rb', line 486 def active_design_file if active_design_file? ole = ole_obj.ActiveDesignFile drawing_from_ole(ole) end end |
#active_design_file? ⇒ Boolean Also known as: current_design_file?
Returns true if app has an active design file open.
512 513 514 |
# File 'lib/microstation/app.rb', line 512 def active_design_file? ole_obj.HasActiveDesignFile end |
#active_model_reference ⇒ Object
616 617 618 619 620 |
# File 'lib/microstation/app.rb', line 616 def active_model_reference DefaultModel.new(self, ole_obj.ActiveModelReference) rescue StandardError nil end |
#active_workspace ⇒ Object
357 358 359 |
# File 'lib/microstation/app.rb', line 357 def active_workspace ole_obj.ActiveWorkspace end |
#base_dir ⇒ Object
267 268 269 |
# File 'lib/microstation/app.rb', line 267 def base_dir project_dir || Pathname.getwd end |
#cad_input_queue {|CadInputQueue| ... } ⇒ void
This method returns an undefined value.
lets you interact with the cad_input_queue
566 567 568 569 570 571 572 573 574 575 576 577 578 |
# File 'lib/microstation/app.rb', line 566 def cad_input_queue queue = init_cad_input_queue return queue unless block_given? begin yield queue rescue StandardError ensure queue.close queue = nil @cad_input_queue = nil end end |
#can_open?(filename) ⇒ Boolean
611 612 613 614 |
# File 'lib/microstation/app.rb', line 611 def can_open?(filename) ext = File.extname(filename) (ext == '.dwg') || (ext == '.dgn') end |
#capabilities(mode = :all) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/microstation/configuration.rb', line 175 def capabilities(mode = :all) case mode when :all configuration.capabilities_all when :dwg configuration.capabilites_dwg when :v7 configuration.capabilities_v7 else configuration_capabilities_all end end |
#change_drawing(dgn, output_dir: nil, name: nil, options: {}, &block) ⇒ Object
165 166 167 168 |
# File 'lib/microstation/app.rb', line 165 def change_drawing(dgn, output_dir: nil, name: nil, options: {}, &block) changer = Changer.new(dgn, name: name, output_dir: output_dir, app: self) changer.run(&block) end |
#close_active_drawing ⇒ void Also known as: close_current_drawing
This method returns an undefined value.
close the active_design_file
501 502 503 |
# File 'lib/microstation/app.rb', line 501 def close_active_drawing active_design_file.close if active_design_file? end |
#configuration ⇒ Object
362 363 364 |
# File 'lib/microstation/app.rb', line 362 def configuration @config ||= ::Microstation::Configuration.new(self) end |
#configured_seed_paths ⇒ String
Returns the configuration variable MS_SEEDFILES.
437 438 439 |
# File 'lib/microstation/app.rb', line 437 def configured_seed_paths configuration['MS_SEEDFILES'] end |
#create_ole_point(x, y, z = 0) ⇒ WIN32OLE_RECORD
Create an WIN32OLE_RECORD of type Point3d
649 650 651 652 653 654 655 |
# File 'lib/microstation/app.rb', line 649 def create_ole_point(x, y, z = 0) ole = ole_point ole.X = x ole.Y = y ole.Z = z ole end |
#create_ole_scan_criteria ⇒ Object
14 15 16 |
# File 'lib/microstation/scan/criteria.rb', line 14 def create_ole_scan_criteria ole_obj.CreateObjectInMicroStation("MicroStationDGN.ElementScanCriteria") end |
#create_scan_criteria(name = nil, &block) ⇒ Object
541 542 543 |
# File 'lib/microstation/app.rb', line 541 def create_scan_criteria(name = nil, &block) ::Microstation::Scan::Criteria.create_scanner(name, self, &block) end |
#create_scanner(name = nil, &block) ⇒ Object
529 530 531 |
# File 'lib/microstation/app.rb', line 529 def create_scanner(name = nil, &block) ::Microstation::Scan::Criteria.create_scanner(name, self, &block) end |
#create_text_node(origin, rotation, temp = nil) ⇒ Object
696 697 698 699 700 701 702 703 704 |
# File 'lib/microstation/app.rb', line 696 def create_text_node(origin, rotation, temp = nil) ole_origin = to_ole_point3d(origin) ole_rotation = to_ole_matrix3d(rotation) temp ||= WIN32OLE_VARIANT::Nothing ole = ole_obj.CreateTextNodeElement1(temp, ole_origin, ole_rotation) rescue Exception => e puts e. nil end |
#default_event_handler ⇒ EventHandler
the default EventHandler
180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/microstation/app.rb', line 180 def default_event_handler event_handler = EventHandler.new event_handler.add_handler('OnDesignFileOpened') do |*_args| puts 'drawing opened' @drawing_opened = true end event_handler.add_handler('OnDesignFileClosed') do |*_args| @drawing_opened = false puts 'drawing closed' end event_handler end |
#default_model ⇒ Object
622 623 624 625 626 |
# File 'lib/microstation/app.rb', line 622 def default_model DefaultModel.new(self, ole_obj.DefaultModelReference) rescue StandardError nil end |
#determine_seed(seedfile) ⇒ Object
427 428 429 430 431 432 433 434 |
# File 'lib/microstation/app.rb', line 427 def determine_seed(seedfile) return configuration['MS_DESIGNSEED'] unless seedfile seed = find_seed(seedfile) return seed.to_s if seed raise "Seedfile #{seedfile} not found in #{configured_seed_paths}" end |
#drawing_from_ole(ole) ⇒ Object
423 424 425 |
# File 'lib/microstation/app.rb', line 423 def drawing_from_ole(ole) Drawing.new(self, ole) end |
#drawing_opened? ⇒ Boolean
349 350 351 |
# File 'lib/microstation/app.rb', line 349 def drawing_opened? @drawing_opened end |
#eval_cexpression(string) ⇒ Object
465 466 467 |
# File 'lib/microstation/app.rb', line 465 def eval_cexpression(string) ole_obj.GetCExpressionValue(string) end |
#exit_message_looop ⇒ Object
216 217 218 219 |
# File 'lib/microstation/app.rb', line 216 def puts 'Microstation exiting...' @run_loop = false end |
#file_exists?(file) ⇒ Boolean
<Description>
525 526 527 |
# File 'lib/microstation/app.rb', line 525 def file_exists?(file) Pathname(file)..file? end |
#find_seed(seedfile) ⇒ Pathname
find the seedfile
-
If the seed file is absolute and found the return the
seedfile.
-
If the seed file is not found search MS_SEEDFILES
448 449 450 451 452 453 |
# File 'lib/microstation/app.rb', line 448 def find_seed(seedfile) seed = Pathname(seedfile)..sub_ext('.dgn') return seed if seed.file? find_seed_in_seed_dirs(seed.basename) end |
#find_seed_in_seed_dirs(seedfile) ⇒ Object
455 456 457 458 |
# File 'lib/microstation/app.rb', line 455 def find_seed_in_seed_dirs(seedfile) seed_dir = seed_paths.find { |p| (p + seedfile).file? } return (seed_dir + seedfile) if seed_dir end |
#get_handler(event) ⇒ Proc
return a Handler
212 213 214 |
# File 'lib/microstation/app.rb', line 212 def get_handler(event) @event_handler.get_handler(event) end |
#get_ole_element_enumerator(model:, criteria: nil) ⇒ Object
555 556 557 558 559 560 561 |
# File 'lib/microstation/app.rb', line 555 def get_ole_element_enumerator(model:, criteria: nil) criteria ||= create_scan_criteria criteria.resolve model.scan(criteria.ole_obj) rescue Exception # binding.pry end |
#has_current_drawing? ⇒ Boolean
413 414 415 |
# File 'lib/microstation/app.rb', line 413 def has_current_drawing? ole_obj.HasActiveDesignFile end |
#init_ole_and_app_event(visible: @visible, event_handler: @event_handler, tries: 5, sleep_duration: 1) ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/microstation/app.rb', line 230 def init_ole_and_app_event(visible: @visible, event_handler: @event_handler, tries: 5, sleep_duration: 1) ole = WIN32OLE.new('MicrostationDGN.Application') sleep(sleep_duration) ole.Visible = visible ole.IsProcessLocked = true load_constants(ole) app_event = WIN32OLE_EVENT.new(ole) app_event.handler = event_handler [ole, app_event] rescue StandardError => e tries -= 1 sleep_duration += 1.5 puts "Error: #{e}. #{tries} tries left." retry if tries.positive? raise e, 'unable to init ole app' end |
#make_visible(visible) ⇒ Object
281 282 283 284 285 286 287 288 289 |
# File 'lib/microstation/app.rb', line 281 def make_visible(visible) @visible = visible begin ole_obj.Visible = @visible true rescue Exception => e false end end |
#my_place_line ⇒ Object
735 736 737 738 |
# File 'lib/microstation/app.rb', line 735 def my_place_line require_relative 'primitive_command_interface' start_primitive LineCreation end |
#new_drawing(filename, seedfile: nil, open: true, wait_time: 500, wait_interval: 1, &block) ⇒ Drawing
create a new drawing
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/microstation/app.rb', line 381 def new_drawing(filename, seedfile: nil, open: true, wait_time: 500, wait_interval: 1, &block) file_path = Pathname(filename). raise ExistingFile, file_path if file_path.exist? # drawing_name = normalize_name(filename) seedfile = determine_seed(seedfile) binding.pry unless seedfile windows_name = windows_path(filename) ole = new_ole_drawing(seedfile, windows_name, open: open, wait_time: wait_time, wait_interval: wait_interval) drawing = drawing_from_ole(ole) return drawing unless block_given? begin yield drawing rescue StandardError => e 'puts error in new drawing' raise e ensure drawing.close end end |
#new_ole_drawing(seedfile, new_design_file_name, open: true, wait_time: 500, wait_interval: 0.5) ⇒ Object
403 404 405 406 407 408 409 410 411 |
# File 'lib/microstation/app.rb', line 403 def new_ole_drawing(seedfile, new_design_file_name, open: true, wait_time: 500, wait_interval: 0.5) ole = ole_obj.CreateDesignFile(seedfile, new_design_file_name, open) wait_drawing_opened(wait_time, wait_interval) raise "drawing not opened in #{wait_time}" unless drawing_opened? ole rescue StandardError => e raise e end |
#normalize_name(name) ⇒ Object
275 276 277 278 279 |
# File 'lib/microstation/app.rb', line 275 def normalize_name(name) name = Pathname.new(name) unless name.is_a? Pathname name = name.ext('.dgn') unless name.extname.to_s == /\.(dgn|dwg)$/ (base_dir + name). end |
#ole_matrix ⇒ Object
636 637 638 |
# File 'lib/microstation/app.rb', line 636 def ole_matrix ::WIN32OLE_RECORD.new('Matrix', ole_obj) end |
#ole_obj ⇒ Object
291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/microstation/app.rb', line 291 def ole_obj is_ok = true begin @ole_obj.Visible rescue StandardError => e is_ok = false end @ole_obj, @app_event = init_ole_and_app_event(tries: 3) unless is_ok @ole_obj end |
#ole_point ⇒ Object
628 629 630 |
# File 'lib/microstation/app.rb', line 628 def ole_point ::WIN32OLE_RECORD.new('Point3d', ole_obj) end |
#ole_point3d?(pt) ⇒ Boolean
<Description>
692 693 694 |
# File 'lib/microstation/app.rb', line 692 def ole_point3d?(pt) pt.instance_of?(WIN32OLE_RECORD) && pt.typename == 'Point3d' end |
#ole_rotation ⇒ Object
632 633 634 |
# File 'lib/microstation/app.rb', line 632 def ole_rotation ::WIN32OLE_RECORD.new('Rotation', ole_obj) end |
#ole_to_ruby(ole) ⇒ Object
283 284 285 |
# File 'lib/microstation/element.rb', line 283 def ole_to_ruby(ole) Element.convert_item(ole,self) end |
#open_drawing(filename, readonly: false, error_proc: nil, wait_time: 500, wait_interval: 0.5) {|Drawing| ... } ⇒ void
This method returns an undefined value.
open the drawing
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'lib/microstation/app.rb', line 324 def open_drawing(filename, readonly: false, error_proc: nil, wait_time: 500, wait_interval: 0.5) filename = Pathname(filename) raise FileNotFound unless filename.file? begin ole = ole_open_drawing(windows_path(filename), readonly: readonly, wait_time: wait_time, wait_interval: wait_interval) rescue StandardError => e if error_proc error_proc.call(filename) return else raise e end end drawing = drawing_from_ole(ole) return drawing unless block_given? begin yield drawing ensure drawing.close end end |
#prepend_seed_path(dir) ⇒ Object
prepend a dir to the MS_SEEDFILES configuration
419 420 421 |
# File 'lib/microstation/app.rb', line 419 def prepend_seed_path(dir) configuration.prepend('MS_SEEDFILES', windows_path(dir)) end |
#quit ⇒ void
This method returns an undefined value.
quit the app
474 475 476 477 478 479 480 481 482 |
# File 'lib/microstation/app.rb', line 474 def quit close_active_drawing @scanners.each { |_name, sc| sc.close } begin ole_obj.Quit rescue StandardError nil end end |
#register_handler(event, &block) ⇒ <Type>
register an handler
201 202 203 |
# File 'lib/microstation/app.rb', line 201 def register_handler(event, &block) @event_handler.add_handler(event, &block) unless event == 'OnQuit' end |
#render_template(drawing, output_dir: nil, locals: {}, name: nil) ⇒ Object
170 171 172 173 |
# File 'lib/microstation/app.rb', line 170 def render_template(drawing, output_dir: nil, locals: {}, name: nil) temp = Template.new(drawing, output_dir: output_dir, app: self, name: name) temp.render(output_dir: output_dir, locals: locals) end |
#run_templates_in_dir(dir, options = {}) ⇒ Object
158 159 160 161 162 163 |
# File 'lib/microstation/app.rb', line 158 def run_templates_in_dir(dir, = {}) yaml_files = Pathname.glob("#{Pathname(dir).}*.yaml") yaml_files.each do |f| TemplateRunner.new(f).run_with_app(self, ) end end |
#scan_model(criteria = nil, model = nil) ⇒ Object
def find_by_id(id)
active_design_file.find_by_id(id)
wrap(model) if el
end
550 551 552 553 |
# File 'lib/microstation/app.rb', line 550 def scan_model(criteria = nil, model = nil) model ||= active_model_reference model.scan(criteria) end |
#seed_paths ⇒ Array
Returns the MS_SEEDFILES as Pathnames Array
461 462 463 |
# File 'lib/microstation/app.rb', line 461 def seed_paths configured_seed_paths.split(';').map { |d| Pathname(d) } end |
#show_command(text) ⇒ Object
580 581 582 |
# File 'lib/microstation/app.rb', line 580 def show_command(text) ole_obj.ShowCommand(text) end |
#show_message(text) ⇒ Object
588 589 590 |
# File 'lib/microstation/app.rb', line 588 def (text) ole_obj.ShowMessage(text) end |
#show_prompt(text) ⇒ Object
584 585 586 |
# File 'lib/microstation/app.rb', line 584 def show_prompt(text) ole_obj.ShowPrompt(text) end |
#show_temp_message(text, location: nil) ⇒ void
This method returns an undefined value.
599 600 601 602 603 604 605 606 607 608 609 |
# File 'lib/microstation/app.rb', line 599 def (text, location: nil) loc = case location when :left MSD::MsdStatusBarAreaLeft when :middle MSD::MsdStatusBarAreaMiddle else MSD::MsdStatusBarAreaLeft end ole_obj.ShowTempMessage(loc, text) end |
#start_primitive(klass) ⇒ Object
731 732 733 |
# File 'lib/microstation/app.rb', line 731 def start_primitive(klass) ole_obj.CommandState.StartPrimitive klass.new(self) end |
#tags_criteria ⇒ Object
537 538 539 |
# File 'lib/microstation/app.rb', line 537 def sc = scanners[:tags] || create_scanner(:tags) { } end |
#text_criteria ⇒ Object
533 534 535 |
# File 'lib/microstation/app.rb', line 533 def text_criteria scanners[:textual] || create_scanner(:textual) { include_textual } end |
#to_ole_matrix3d(vec) ⇒ Object
657 658 659 660 661 662 663 |
# File 'lib/microstation/app.rb', line 657 def to_ole_matrix3d(vec) if vec.instance_of?(WIN32OLE_RECORD) && vec.typename == 'Matrix3d' vec else binding.pry end end |
#to_ole_point3d(pt) ⇒ WIN32OLE_RECORD
Conversion to WIN32OLE_RECORD of type Point3d
671 672 673 674 675 676 677 678 679 680 681 682 683 |
# File 'lib/microstation/app.rb', line 671 def to_ole_point3d(pt) case pt when ole_point3d?(pt) pt when Point3d create_ole_point(pt.x, pt.y, pt.z) when Array pt1 = pt.map(&:to_f) x, y, z = pt1 z ||= 0.0 create_ole_point(x, y, z) end end |
#to_point(pt) ⇒ Object
727 728 729 |
# File 'lib/microstation/app.rb', line 727 def to_point(pt) to_point3d(pt) end |
#to_point3d(pt) ⇒ Point3d
convert pt to Point3d
713 714 715 716 717 718 719 720 721 722 723 724 725 |
# File 'lib/microstation/app.rb', line 713 def to_point3d(pt) case pt when Array pt_a = pt.map(&:to_f) x, y, z = pt_a z ||= 0.0 Point3d.new(x, y, z) when Point3d pt when WIN32OLE_RECORD Point3d.from_ole(pt) if pt.typename == 'Point3d' end end |
#username ⇒ String
Returns the configuration variable USERNAME.
367 368 369 |
# File 'lib/microstation/app.rb', line 367 def username configuration['USERNAME'] end |
#visible? ⇒ Boolean
Returns whether the app is visible.
248 249 250 |
# File 'lib/microstation/app.rb', line 248 def visible? @visible end |
#wait_drawing_opened(secs, interval = 1) ⇒ Object
221 222 223 224 225 226 227 228 |
# File 'lib/microstation/app.rb', line 221 def wait_drawing_opened(secs, interval = 1) elapsed = 0 while !drawing_opened? && elapsed <= secs elapsed += interval sleep(interval) WIN32OLE_EVENT. end end |
#windows_path(path) ⇒ Object
353 354 355 |
# File 'lib/microstation/app.rb', line 353 def windows_path(path) @windows.windows_path(path) end |
#with_config ⇒ Object
85 86 87 |
# File 'lib/microstation/configuration.rb', line 85 def with_config end |
#with_drawing(drawing) ⇒ Object
304 305 306 307 308 |
# File 'lib/microstation/app.rb', line 304 def with_drawing(drawing) yield drawing ensure drawing.close end |
#with_template(template) {|template| ... } ⇒ Object
310 311 312 313 314 |
# File 'lib/microstation/app.rb', line 310 def with_template(template) template = Template.new(template, self) yield template template = nil end |
#wrap(item, cell = nil) ⇒ Object
271 272 273 |
# File 'lib/microstation/app.rb', line 271 def wrap(item, cell = nil) Element.convert_item(item, self, cell) end |