Error: #<NameError: undefined local variable or method

Hello, can anyone explain to me why I get error msg.: Error:
#<NameError: undefined local variable or method `field_build' for
Visual::Plugin_A:Module> on this code:

require("visual_visual_mod.rb")
require("sketchup.rb")

module Visual::Plugin_A

# module methods, module vars, etc.

  unless file_loaded?(File.basename(__FILE__))

  Visual::SUBMENU_VisDose.add_item ("VisDose 3D") {

field_build

}

def field_build

model=Sketchup.active_model
entities=model.active_entities
mod = Sketchup.active_model # Open model
entities = mod.entities # All entities in model
status = entities.clear! #clear current model

path = UI.openpanel "Open Data File", "d:\\", "*.txt"

prompts = ["Alpha: "]
defaults = ["0.5"]
alpha = UI.inputbox prompts, defaults, "Please set transparency."

File.open(path).each_line {|line|

values=line.split(' ')

  x1=values[0].to_f
  y1=values[1].to_f
  z1=values[2].to_f
  color=values[3].to_f
  size=1

  x2=(x1+1)
  y2=(y1+1)

    pt1 = [x1, y1, z1]
    pt2 = [x2, y1, z1]
    pt3 = [x2, y2, z1]
    pt4 = [x1, y2, z1]

case color

  when 8..1000 then
    face1=entities.add_face pt1, pt2, pt3, pt4
    face1.material=[255,0,0]
    face1.material.alpha=alpha[0].to_f
    face1.back_material=[255,0,0]
    face1.back_material.alpha=alpha[0].to_f
    face1.pushpull size, true

  when 7..7.99 then
    face2=entities.add_face pt1, pt2, pt3, pt4
    face2.material=[255,86,25]
    face2.material.alpha=alpha[0].to_f
    face2.back_material=[255,86,25]
    face2.back_material.alpha=alpha[0].to_f
    face2.pushpull size, true

  when 6..6.99 then
    face3=entities.add_face pt1, pt2, pt3, pt4
    face3.material=[255,220,25]
    face3.material.alpha=alpha[0].to_f
    face3.back_material=[255,220,25]
    face3.back_material.alpha=alpha[0].to_f
    face3.pushpull size, true

  when 5..5.99 then
    face4=entities.add_face pt1, pt2, pt3, pt4
    face4.material=[254,254,76]
    face4.material.alpha=alpha[0].to_f
    face4.back_material=[254,254,76]
    face4.back_material.alpha=alpha[0].to_f
    face4.pushpull size, true

  when 4..4.99 then
    face5=entities.add_face pt1, pt2, pt3, pt4
    face5.material=[128,255,0]
    face5.material.alpha=alpha[0].to_f
    face5.back_material=[128,255,0]
    face5.back_material.alpha=alpha[0].to_f
    face5.pushpull size, true

  when 3..3.99 then
    face6=entities.add_face pt1, pt2, pt3, pt4
    face6.material=[0,255,0]
    face6.material.alpha=alpha[0].to_f
    face6.back_material=[0,255,0]
    face6.back_material.alpha=alpha[0].to_f
    face6.pushpull size, true

  when 2.5..2.99 then
    face7=entities.add_face pt1, pt2, pt3, pt4
    face7.material=[0,160,177]
    face7.material.alpha=alpha[0].to_f
    face7.back_material=[0,160,177]
    face7.back_material.alpha=alpha[0].to_f
    face7.pushpull size, true

  when 2..2.49 then
    face8=entities.add_face pt1, pt2, pt3, pt4
    face8.material=[0,86,255]
    face8.material.alpha=alpha[0].to_f
    face8.back_material=[0,86,255]
    face8.back_material.alpha=alpha[0].to_f
    face8.pushpull size, true

  when 0..2 then
    face9=entities.add_face pt1, pt2, pt3, pt4
    face9.material=[0,86,255]
    face9.material.alpha=alpha[0].to_f
    face9.back_material=[0,86,255]
    face9.back_material.alpha=alpha[0].to_f
    face9.pushpull size, true
  else

    face10=entities.add_face pt1, pt2, pt3, pt4
    face10.material=[0,0,255]
    face10.material.alpha=alpha[0].to_f
    face10.back_material=[0,0,255]
    face10.back_material.alpha=alpha[0].to_f
    face10.pushpull size, true

end

}
styles = Sketchup.active_model.styles
status = styles.add_style "D:\\xray.style", true

end

    file_loaded(File.basename(__FILE__))

end
end

Thank's

···

--
Posted via http://www.ruby-forum.com/.

You are calling the field_build method directly from within the
module definition, before the method is defined.

···

On Mon, Dec 2, 2013, at 21:00, Martins Piksis wrote:

Hello, can anyone explain to me why I get error msg.: Error:
#<NameError: undefined local variable or method `field_build' for
Visual::Plugin_A:Module> on this code:

require("visual_visual_mod.rb")
require("sketchup.rb")

module Visual::Plugin_A

# module methods, module vars, etc.

  unless file_loaded?(File.basename(__FILE__))

  Visual::SUBMENU_VisDose.add_item ("VisDose 3D") {

field_build

}

def field_build

--
Lars Haugseth

Thank you, Lars, problem is solved!

···

--
Posted via http://www.ruby-forum.com/.