ModraUp Ruby API Documentation Ruby API Reference

Class: ModraUp::HatchPatternData

Inherits:
Object
  • Object
show all

Overview

Values for hatch patterns that do not belong to a model collection and have no name, used for ModraUp::RenderingOptions#hatch_pattern (the default hatch pattern for styles). The object obtained from the rendering options is frozen: first dup, modify it, and then assign it back.

Examples:

ro = ModraUp.active_model.rendering_options
data = ro.hatch_pattern.dup
data.rotation_angle = 45.0
ro.hatch_pattern = data

Class Method Summary # collapse

Instance Method Summary # collapse

Class Method Details

.new ⇒ ModraUp::HatchPatternData

Create an empty hatch pattern settings: white fill, no line family and texture, scale 1, rotation 0.

Returns:

  • (ModraUp::HatchPatternData)

Examples:

data = ModraUp::HatchPatternData.new

Instance Method Details

#initialize_copy(other) ⇒ ModraUp::HatchPatternData

Copy all settings (use dup / clone).

Parameters:

  • other (ModraUp::HatchPatternData) Source.

Returns:

  • (ModraUp::HatchPatternData)

Examples:

copy = ModraUp::HatchPatternData.new.dup

#==(other) ⇒ Boolean

Returns true if all settings are the same.

Parameters:

  • other (Object) Compare the objects.

Returns:

  • (Boolean)

Examples:

ModraUp::HatchPatternData.new == ModraUp::HatchPatternData.new  #=> true

#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]