Class: Microstation::App

Inherits:
Object
  • Object
show all
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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

Parameters:

  • visible (Boolean) (defaults to: false)
  • event_handler (EventHandler) (defaults to: default_event_handler)


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_optionsObject

Returns the value of attribute default_app_options.



49
50
51
# File 'lib/microstation/app.rb', line 49

def default_app_options
  @default_app_options
end

Instance Attribute Details

#app_eventObject (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_dirObject

Returns the value of attribute project_dir.



140
141
142
# File 'lib/microstation/app.rb', line 140

def project_dir
  @project_dir
end

#scannersObject (readonly)

Returns the value of attribute scanners.



140
141
142
# File 'lib/microstation/app.rb', line 140

def scanners
  @scanners
end

#visibleObject

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)

Yields:

  • Drawing



89
90
91
92
93
# File 'lib/microstation/app.rb', line 89

def open_drawing(drawing, app_options: {}, options:  {}, &block)
  run(**app_options) do |app|
    app.open_drawing(drawing, **options, &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

Parameters:

  • options (Hash) (defaults to: {})

    the options to create the app with

Options Hash (options):

  • :visible (Boolean)

    Is the app visible

Yields:

  • (App)

    the_app yields the instanciated app



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/microstation/app.rb', line 68

def run(options = {})
  opts = self.default_app_options.merge(options)
  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

Parameters:

  • files (Array<String,Pathname>)
  • visible (Boolean) (defaults to: true)
  • readonly (Boolean) (defaults to: false)
  • error_proc (Proc) (defaults to: ::Microstation.default_error_proc)

Yields:



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(app_options)
      end
    end
  ensure
    the_app&.quit
    the_app = nil
  end
end

Instance Method Details

#active_design_fileDrawing Also known as: active_drawing, current_drawing

the active design file

Returns:



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.

Returns:

  • (Boolean)

    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_referenceObject



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_workspaceObject



357
358
359
# File 'lib/microstation/app.rb', line 357

def active_workspace
  ole_obj.ActiveWorkspace
end

#base_dirObject



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

Yields:



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

Returns:

  • (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_drawingvoid 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

#configurationObject



362
363
364
# File 'lib/microstation/app.rb', line 362

def configuration
  @config ||= ::Microstation::Configuration.new(self)
end

#configured_seed_pathsString

Returns the configuration variable MS_SEEDFILES.

Returns:

  • (String)

    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

Parameters:

  • x (Numeric)

    coordinate in x axis

  • y (Numeric)

    coordinate in y axis

  • z (Numeric) (defaults to: 0)

    coordinate in z direction (0.0)

Returns:

  • (WIN32OLE_RECORD)

    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_criteriaObject



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.message
  nil
end

#default_event_handlerEventHandler

the default EventHandler

Returns:



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_modelObject



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

Returns:

  • (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_looopObject



216
217
218
219
# File 'lib/microstation/app.rb', line 216

def exit_message_looop
  puts 'Microstation exiting...'
  @run_loop = false
end

#file_exists?(file) ⇒ Boolean

<Description>

Parameters:

  • file (String, Pathname)

    name of file to search for

Returns:

  • (Boolean)

    true if file exists



525
526
527
# File 'lib/microstation/app.rb', line 525

def file_exists?(file)
  Pathname(file).expand_path.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

Parameters:

Returns:

  • (Pathname)

    seedfile the found seedfile



448
449
450
451
452
453
# File 'lib/microstation/app.rb', line 448

def find_seed(seedfile)
  seed = Pathname(seedfile).expand_path.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

Parameters:

  • event (String, Symbol)

    the event key

Returns:

  • (Proc)

    returns the Proc given by event name



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

Returns:

  • (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_lineObject



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

Parameters:

  • filename (String, Pathname)

    the name of the file

  • seedfile (String) (defaults to: nil)

    The name of the seed file. should not include a path. The default extension is “.dgn”. Typical values are “seed2d” or “seed3d”.

  • open (Boolean) (defaults to: true)

    .If the open argument is True, CreateDesignFile returns the newly-opened DesignFile object; this is the same value as ActiveDesignFile. If the Open argument is False, CreateDesignFile returns Nothing.

Returns:

Raises:



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).expand_path
  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).expand_path
end

#ole_matrixObject



636
637
638
# File 'lib/microstation/app.rb', line 636

def ole_matrix
  ::WIN32OLE_RECORD.new('Matrix', ole_obj)
end

#ole_objObject



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_pointObject



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>

Parameters:

  • pt (Object)

    pt object to test if it is a WIN32OLE_RECORD of ‘Point3d’

Returns:

  • (Boolean)

    true if pt is WIN32OLE_RECORD of ‘Point3d’



692
693
694
# File 'lib/microstation/app.rb', line 692

def ole_point3d?(pt)
  pt.instance_of?(WIN32OLE_RECORD) && pt.typename == 'Point3d'
end

#ole_rotationObject



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

Parameters:

  • filename (String)

    the name of the file to open

  • :readonly (Boolean)

    (false)

  • :error_proc (Proc)

    (raise) a proc to run

  • wait_time (Integer) (defaults to: 500)

    the total amount of time to wait to open file (500)

  • wait_interval (Float) (defaults to: 0.5)

    the amount of time in seconds to wait before retry (0.5)

Yields:

Raises:



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

Parameters:



419
420
421
# File 'lib/microstation/app.rb', line 419

def prepend_seed_path(dir)
  configuration.prepend('MS_SEEDFILES', windows_path(dir))
end

#quitvoid

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

Parameters:

  • event (String)

    key for handler

  • &block (<Type>)

    <description>

Returns:

  • (<Type>)

    <description>



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, options = {})
  yaml_files = Pathname.glob("#{Pathname(dir).expand_path}*.yaml")
  yaml_files.each do |f|
    TemplateRunner.new(f).run_with_app(self, options)
  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_pathsArray

Returns the MS_SEEDFILES as Pathnames Array

Returns:

  • (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 show_message(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.

Parameters:

  • text (String)

    text to show

  • location (Symbol) (defaults to: nil)

    (one of :left, :middle)



599
600
601
602
603
604
605
606
607
608
609
# File 'lib/microstation/app.rb', line 599

def show_temp_message(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_criteriaObject



537
538
539
# File 'lib/microstation/app.rb', line 537

def tags_criteria
  sc = scanners[:tags] || create_scanner(:tags) { include_tags }
end

#text_criteriaObject



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

Parameters:

  • pt (WIN32OLE_RECORD, Point3d, Array<Numeric>)

    Point to normalize to ole point

Returns:

  • (WIN32OLE_RECORD)

    ‘Point3d’ WIN32OLE_RECORD



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

Parameters:

  • pt (Array<Numeric,Numeric,Numeric>, Point3d, WIN32OLE_RECORD)

    Point to convert

Returns:



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

#usernameString

Returns the configuration variable USERNAME.

Returns:

  • (String)

    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.

Returns:

  • (Boolean)

    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.message_loop
  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_configObject



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

Yields:

  • (template)


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