ModraUp Ruby API Documentation Ruby API Reference

Class: ModraUp::HatchPattern

Inherits:
ModraUp::Entity show all

Overview

A hatch pattern in a model (an item of ModraUp::Model#hatch_patterns): overlay .PAT line families or tiled images on the fill color, with scaling and rotation. Groups, components, materials, and section planes reference it via hatch_pattern=. Cannot be instantiated directly with new, instead use ModraUp::HatchPatterns#add.

The order in which hatch patterns are applied to a section area: first, the pattern of the containing group or component (including nested content), then the material's pattern, then the section plane's pattern, and finally, if none are specified, ModraUp::RenderingOptions#hatch_pattern.

Examples:

hp = ModraUp.active_model.hatch_patterns.first
puts hp.name if hp

Instance Method Summary # collapse

Inherited from ModraUp::Entity

Instance Method Details

#clear_fill_pattern ⇒ ModraUp::HatchPattern, ModraUp::HatchPatternData

Clear the .PAT line pattern definition (the #fill_pattern_file_name will be empty), while preserving the fill color and texture.

Returns:

  • (ModraUp::HatchPattern, ModraUp::HatchPatternData) The receiver

Examples:

hp = ModraUp.active_model.hatch_patterns.first
hp.clear_fill_pattern if hp

#clear_fill_texture ⇒ ModraUp::HatchPattern, ModraUp::HatchPatternData

Clear the fill texture, retaining the fill color and .PAT line family.

Returns:

  • (ModraUp::HatchPattern, ModraUp::HatchPatternData) The receiver

Examples:

hp = ModraUp.active_model.hatch_patterns.first
hp.clear_fill_texture if hp

#fill_color ⇒ ModraUp::Color

Retrieve the fill color (the background color beneath lines and patterns).

Returns:

  • (ModraUp::Color)

Examples:

ModraUp::HatchPatternData.new.fill_color

#fill_color=(color) ⇒ ModraUp::Color

Sets the fill color.

Parameters:

  • color (ModraUp::Color) Color (also accepts color name or array).

Returns:

  • (ModraUp::Color)

Raises:

  • [TypeError] It is not a color.

Examples:

data = ModraUp::HatchPatternData.new
data.fill_color = ModraUp::Color.new(255, 0, 0)

#fill_pattern_file_name ⇒ String

The path to the line pattern file (.PAT / .skh / .oskh); an empty string if no line pattern is defined.

Returns:

  • (String)

Examples:

ModraUp::HatchPatternData.new.fill_pattern_file_name  #=> ""

#fill_texture_file_name ⇒ String

The path to the texture source file; an empty string if no texture is used.

Returns:

  • (String)

Examples:

ModraUp::HatchPatternData.new.fill_texture_file_name  #=> ""

#fill_texture_image ⇒ ModraUp::ImageRep, nil

Returns the image used for texture filling; returns nil if no texture is applied.

Returns:

  • (ModraUp::ImageRep, nil)

Examples:

ModraUp::HatchPatternData.new.fill_texture_image  #=> nil

#rotation_angle ⇒ Float

Reads the rotation angle (degrees, counterclockwise).

Returns:

  • (Float)

Examples:

ModraUp::HatchPatternData.new.rotation_angle  #=> 0.0

#rotation_angle=(angle) ⇒ Float

Sets the rotation angle (degrees).

Parameters:

  • angle (Float) The angle.

Returns:

  • (Float)

Raises:

  • [ArgumentError] The rotation angle is not a finite number.

Examples:

data = ModraUp::HatchPatternData.new
data.rotation_angle = 45.0

#save_fill_pattern_to_file(file_name) ⇒ ModraUp::HatchPattern, ModraUp::HatchPatternData

Write the .PAT hatch pattern as an AutoCAD .PAT text file (excluding fill color, scale, and texture; use ModraUp::HatchPattern#write for the entire pattern).

Parameters:

  • file_name (String) Target path.

Returns:

  • (ModraUp::HatchPattern, ModraUp::HatchPatternData) The receiver

Raises:

  • [ArgumentError] No line family or write failed.

Examples:

hp = ModraUp.active_model.hatch_patterns.first
hp.save_fill_pattern_to_file(File.join(Dir.tmpdir, "pattern.pat")) if hp && !hp.fill_pattern_file_name.empty?

#set_fill_pattern_from_file(file_name) ⇒ ModraUp::HatchPattern, ModraUp::HatchPatternData

Read hatch patterns from a file. Only the first pattern in the file is used; also accepts line patterns from .skh / .oskh files.

Parameters:

  • file_name (String) Paths for .PAT / .skh / .oskh files.

Returns:

  • (ModraUp::HatchPattern, ModraUp::HatchPatternData) The receiver

Raises:

  • [ArgumentError] Unable to read edge group.

Examples:

path = File.join(Dir.tmpdir, "line.pat")
File.write(path, "*LINE\n0, 0,0, 0,.125\n")
data = ModraUp::HatchPatternData.new
data.set_fill_pattern_from_file(path)

#set_fill_texture_image_and_file_name(image, file_name) ⇒ ModraUp::HatchPattern, ModraUp::HatchPatternData

Set fill texture: The image and its source path are saved. The new texture initially tiles 12 inches wide, then scaled by #uv_scale.

Parameters:

  • image (ModraUp::ImageRep) Image.
  • file_name (String) Source path (record only).

Returns:

  • (ModraUp::HatchPattern, ModraUp::HatchPatternData) The receiver

Raises:

  • [ArgumentError] Invalid image data; HatchPattern raises this error when image is not an ImageRep.
  • [TypeError] The image for HatchPatternData is not an ImageRep.

Examples:

rep = ModraUp::ImageRep.new
rep.set_data(2, 2, 24, 0, "\xFF\x00\x00" * 4)
data = ModraUp::HatchPatternData.new
data.set_fill_texture_image_and_file_name(rep, "red.png")

#set_uv_scale(u_scale, v_scale) ⇒ ModraUp::HatchPattern, ModraUp::HatchPatternData

Sets the repeat scale in the U/V directions (pattern units × scale = model inches).

Parameters:

  • u_scale (Float) greater than 0.
  • v_scale (Float) greater than 0.

Returns:

  • (ModraUp::HatchPattern, ModraUp::HatchPatternData) The receiver

Raises:

  • [ArgumentError] The argument is not greater than 0.

Examples:

data = ModraUp::HatchPatternData.new
data.set_uv_scale(10.0, 10.0)

#uv_scale ⇒ Array(Float, Float)

Retrieve the U/V repetition scale.

Returns:

  • (Array(Float, Float))

Examples:

ModraUp::HatchPatternData.new.uv_scale  #=> [1.0, 1.0]

#name ⇒ String

Read name (unique within the model).

Returns:

  • (String)

Examples:

hp = ModraUp.active_model.hatch_patterns.first
hp.name if hp

#name=(name) ⇒ String

Rename. The name cannot be empty and must be unique and not conflict with other hatch patterns in the model.

Parameters:

  • name (String) New name.

Returns:

  • (String)

Raises:

  • [ArgumentError] The name is empty or already in use by another pattern.

Examples:

hp = ModraUp.active_model.hatch_patterns.first
hp.name = "Concrete #{rand(1000)}" if hp

#thumbnail_image ⇒ ModraUp::ImageRep, nil

Returns the thumbnail preview image (128×128) displayed in the thumbnail tray.

Returns:

  • (ModraUp::ImageRep, nil) The host returns nil when it cannot draw.

Examples:

hp = ModraUp.active_model.hatch_patterns.first
hp.thumbnail_image if hp

#write(path) ⇒ Boolean

Write the entire hatch pattern (name, source, fill color, line family or texture, scale, rotation) to a file.

ModraUp can read it back, but SketchUp cannot.

Parameters:

  • path (String) Target path.

Returns:

  • (Boolean) Returns true on success.
Note: ModraUp extension. The write output is in the .oskh format (zip + document.xml), not SketchUp's .skh.

Examples:

hp = ModraUp.active_model.hatch_patterns.first
hp.write(File.join(Dir.tmpdir, "pattern.oskh")) if hp