Applying add_text and #leader_type= multiple times yields different parameter values

test.rb (354 Bytes)

if you create a component and select it, then run the ruby code multiple times (5-10 times at least to be sure) the result of the text.leader_type parameter will be 1 or 2 , although the code sets that parameter to 1

I do not see this happening on Win10. Perhaps this is only a Mac M1 issue ?

It might be a issue with Console IO [ ie, the puts() call ] with Ruby running on M1.

First posted test method ...
module Testing

  def self.go
    model = Sketchup.active_model
    inst  = model.selection.first
    outer_entities = inst.definition.entities
    types = []
    model.start_operation("Text Test",true)
    #
    10.times do
      group = outer_entities.add_group
      group.locked = true
      inner_entities = group.entities
      cpt  = inner_entities.add_cpoint(ORIGIN)
      text = inner_entities.add_text(
        "TestName",
        Geom::Point3d.new(30, 30, 30),
        Geom::Vector3d.new(0, 0, 35)
      )
      text.leader_type = 1
      text.arrow_type  = 2
      text.display_leader = true
      puts text.leader_type # slow IO
      types << text.leader_type
      cpt.erase!
    end
    #
    model.commit_operation
    puts "True leader types: #{types.inspect}"
  end # go()

end # module

Improved test method ... (Allows passing number for loop) ...
module Issue792

  def self.go(num = 10)
    model = Sketchup.active_model
    inst  = model.selection.first
    outer_entities = inst.definition.entities
    objects = []
    model.start_operation("Text Test",true)
    #
    num.times do
      group = outer_entities.add_group
      group.locked = true
      inner_entities = group.entities
      cpt  = inner_entities.add_cpoint(ORIGIN)
      text = inner_entities.add_text(
        "TestName",
        Geom::Point3d.new(30, 30, 30),
        Geom::Vector3d.new(0, 0, 35)
      )
      text.leader_type = 1
      text.arrow_type  = 2
      text.display_leader = true
      puts text.leader_type # slow IO
      objects << text
      cpt.erase!
    end
    #
    model.commit_operation
    types = objects.map(&:leader_type)
    puts "True leader types: #{types.inspect}"
  end # go()

end # module

If you still see the issue, please log a report in the API Issue Tracker:

1 Like