speckle_connector/converter/to_native.rb
def component_instance_to_native(block, entities)
    # is_group = block.key?("is_sketchup_group") && block["is_sketchup_group"]
    # something about this conversion is freaking out if nested block geo is a group
    # so this is set to false always until I can figure this out
    is_group = false

    definition = component_definition_to_native(
      block["blockDefinition"]["geometry"],
      block["blockDefinition"]["name"],
      block["blockDefinition"]["applicationId"]
    )
    name = block["name"].nil? || block["name"].empty? ? block["id"] : block["name"]
    transform = transform_to_native(
      block["transform"].is_a?(Hash) ? block["transform"]["value"] : block["transform"],
      block["units"]
    )
    instance =
      if is_group
        entities.add_group(definition.entities.to_a)
      else
        entities.add_instance(definition, transform)
      end
    # erase existing instances after creation and before rename because you can't have definitions without instances
    find_and_erase_existing_instance(definition, name, block["applicationId"])
    puts("Failed to create instance for speckle block instance #{block["id"]}") if instance.nil?
    instance.transformation = transform if is_group
    instance.material = material_to_native(block["renderMaterial"])
    instance.name = name
    instance
  end
# creates a component instance from a block
creates a component instance from a block
creates a component instance from a block
def component_instance_to_native(block, entities)
    is_group = false
    definition = component_definition_to_native(
      block["blockDefinition"]["geometry"],
      block["blockDefinition"]["name"],
      block["blockDefinition"]["applicationId"]
    )
    name = block["name"].nil? || block["name"].empty? ? block["id"] : block["name"]
    transform = transform_to_native(
      block["transform"].is_a?(Hash) ? block["transform"]["value"] : block["transform"],
      block["units"]
    )
    instance =
      if is_group
        entities.add_group(definition.entities.to_a)
      else
        entities.add_instance(definition, transform)
      end
    find_and_erase_existing_instance(definition, name, block["applicationId"])
    puts("Failed to create instance for speckle block instance #{block["id"]}") if instance.nil?
    instance.transformation = transform if is_group
    instance.material = material_to_native(block["renderMaterial"])
    instance.name = name
    instance
  end
def component_instance_to_native ( block , entities ) is_group = false definition = component_definition_to_native ( block [ "blockDefinition" ] [ "geometry" ] , block [ "blockDefinition" ] [ "name" ] , block [ "blockDefinition" ] [ "applicationId" ] ) name = block [ "name" ] . nil? || block [ "name" ] . empty? ? block [ "id" ] : block [ "name" ] transform = transform_to_native ( block [ "transform" ] . is_a? ( Hash ) ? block [ "transform" ] [ "value" ] : block [ "transform" ] , block [ "units" ] ) instance = if is_group entities . add_group ( definition . entities . to_a ) else entities . add_instance ( definition , transform ) end find_and_erase_existing_instance ( definition , name , block [ "applicationId" ] ) puts ( "Failed to create instance for speckle block instance #{block["id"]}" ) if instance . nil? instance . transformation = transform if is_group instance . material = material_to_native ( block [ "renderMaterial" ] ) instance . name = name instance end
creates a component instance from a block
creates a component instance from a block
# is_group = block.key?("is_sketchup_group") && block["is_sketchup_group"] # something about this conversion is freaking out if nested block geo is a group # so this is set to false always until I can figure this out # erase existing instances after creation and before rename because you can't have definitions without instances
block
entities