ModraUp Ruby API Documentation Ruby API Reference

Class: ModraUp::HatchPatterns

Inherits:
ModraUp::Entity show all
Includes:
Enumerable

Overview

A collection of all hatch patterns in the model, obtained from ModraUp::Model#hatch_patterns.

Examples:

ModraUp.active_model.hatch_patterns.each { |hp| puts hp.name }

Instance Method Summary # collapse

Inherited from ModraUp::Entity

Instance Method Details

hatch_patterns[index] ⇒ hatch_pattern or nilhatch_patterns[name] ⇒ hatch_pattern or nil

Retrieve hatch patterns by index or name; return nil if not found.

Parameters:

  • index_or_name (Integer, String) Index (can be negative) or name.

Returns:

  • (ModraUp::HatchPattern, nil)

Examples:

hps = ModraUp.active_model.hatch_patterns
hps[0]
hps["Pattern"]

#add(name, path) ⇒ ModraUp::HatchPattern

Read a new hatch pattern from a file and add it to the model.

Parameters:

  • name (String) The unique, non-empty name within the model.
  • path (String) Path to the hatch pattern file (.skh / .oskh / .PAT) or a tileable image.

Returns:

  • (ModraUp::HatchPattern)

Raises:

  • [ArgumentError] The name is empty or already in use, or the file cannot read the pattern.

Examples:

path = File.join(Dir.tmpdir, "ansi31.pat")
File.write(path, "*ANSI31\n45, 0,0, 0,.125\n")
hp = ModraUp.active_model.hatch_patterns.add("ANSI31 #{rand(1000)}", path)

#each ⇒ ModraUp::HatchPatterns

Iterate through each hatch pattern.

Returns:

  • (ModraUp::HatchPatterns)

Yields:

  • @yield [hatch_pattern]
  • @yieldparam [ModraUp::HatchPattern] hatch_pattern

Examples:

ModraUp.active_model.hatch_patterns.each { |hp| puts hp.name }

#purge_unused ⇒ ModraUp::HatchPatterns

Delete hatch patterns that are not used by any group, component, material, or section plane.

Returns:

  • (ModraUp::HatchPatterns)

Examples:

ModraUp.active_model.hatch_patterns.purge_unused

#remove(hatch_pattern) ⇒ Boolean

Remove hatching patterns from the model; any groups, components, materials, or section planes referencing it will no longer display it (undo can restore).

Parameters:

  • hatch_pattern (ModraUp::HatchPattern) The hatch pattern to be removed.

Returns:

  • (Boolean) Returns true if removed, false if not in the collection.

Examples:

hps = ModraUp.active_model.hatch_patterns
hps.remove(hps.first) if hps.first

#selected_hatch_pattern ⇒ ModraUp::HatchPattern, nil

The currently selected hatch pattern (the current item in the HatchPatterns palette).

Returns:

  • (ModraUp::HatchPattern, nil)

Examples:

ModraUp.active_model.hatch_patterns.selected_hatch_pattern

#selected_hatch_pattern=(hatch_pattern) ⇒ ModraUp::HatchPattern, nil

Sets the current selected hatch pattern; nil unselects the pattern.

Parameters:

  • hatch_pattern (ModraUp::HatchPattern, nil) The hatch patterns in this collection.

Returns:

  • (ModraUp::HatchPattern, nil)

Raises:

  • [ArgumentError] The hatch pattern belongs to another model.

Examples:

hps = ModraUp.active_model.hatch_patterns
hps.selected_hatch_pattern = hps.first

#size ⇒ Integer

Number of patterns.

Returns:

  • (Integer)

Examples:

ModraUp.active_model.hatch_patterns.size

#length ⇒ Integer

Alias for #size.

Returns:

  • (Integer)

Examples:

ModraUp.active_model.hatch_patterns.length