SketchUp / api-issue-tracker

Public issue tracker for the SketchUp and LayOut's APIs
https://developer.sketchup.com/
38 stars 10 forks source link

Sketchup::Model#drawing_element_visible? will not accept leaf of type Group #764

Open SnowyEgret opened 2 years ago

SnowyEgret commented 2 years ago

Sketchup::Model#drawing_element_visible? throws an error when the leaf of an array representing an instance path is a Sketchup::Group

mod = Sketchup.active_model
group = mod.entities.add_group
mod.drawing_element_visible?([group])

throws

Leaf must be a type of Sketchup::Drawingelement

Please reference Developer's RubyAPI forum topic ​ Drawingelement#visible? seems to return inconsistent results

SketchUp Pro 2022 Windows 10

DanRathbun commented 2 years ago

RELATED: Attempts to create a new InstancePath object with it's class constructor also fail to create a valid instance path when a group is the leaf.

I also see this on SU2021.

We can only get a valid path if the leaf is a primitive.

sketchupbot commented 2 years ago

Logged as: SKEXT-3342

DanRathbun commented 2 years ago

Issue 764 Workaround

Avoid calling the Sketchup::Model#drawing_element_visible? method upon groups and instances by using a conditional expression (whilst this issue remains unfixed) ...

def self.is_any_object_or_geometry_hidden?(entities, path = [])
  #
  entities.any? { |entity|
    entity_path = path + [entity]
    if entity.respond_to?(:definition)
      break true if is_any_object_or_geometry_hidden?(
        entity.definition.entities, entity_path
      )
    else
      break true if !entity.model.drawing_element_visible?(entity_path)
    end
    #
    false # default return for the block
  }
  #
end
DanRathbun commented 2 years ago

Unfortunately, there appears to not be an easy workaround when the entity is an Sketchup::Image object.

tomboul26 commented 2 months ago

it will not also accept leaf of type ComponentInstance