sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Distinct between entities in instances

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 384 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M Offline
      maricanis
      last edited by

      Hi,

      I've came to a problem, I don't have idea how to solve.
      Is it possible to treat entities inside instances separately or each change in one instance necessary leads to changes in all other instances?

      In a plugin I'm working on, I should make distinction between surfaces which are part of various component's instances. My goal is to attach unique id value to each face (as an attribute), but whenever I try that, corresponding faces in all instances are updated to.

      Example code
      User selects some face in one instance (it is also selected in other instances).
      Run next code in Ruby console:

      [pre:1gler01f] index=0 selection = Sketchup.active_model.selection face = selection[0] #selected face parent = face.parent if parent.class == Sketchup::ComponentDefinition and parent.count_instances>1 #go through all instances and find selected faces parent.instances.each{ |inst| inst.definition.entities.each{ |ent| if selection.contains?(ent) #attach id to face ent.set_attribute("faceData", "id",index) puts index index = index + 1 end } } end[/pre:1gler01f]

      when I have 3 instances of the component output is :
      0 1 2
      Based on this it seems like in each instance, selected face should have unique attribute value, but it is not the case in fact.

      After this code when I select face in any instance and type in console
      Sketchup.active_model.selection[0].get_attribute("faceData", "id")
      Result is always 2 - which means that each time I set attribute it was in fact set in all instances, and only the last value from look is the one saved.

      Note, I don't want to make instances unique, because it would effect on model geometry (and plugin users don't want that).

      Thanks in advance,
      Marija

      1 Reply Last reply Reply Quote 0
      • S Offline
        slbaumgartner
        last edited by

        ComponentInstances don't own separate copies of the primitive geometry, all the geometry is owned by the ComponentDefinition. So, if you alter anything about a primitive (Edge, Face,...) in the ComponentDefinition it immediately affects all of the ComponentInstances. You can only set per-instance values for things that are not shared by all the instances, such as transformation, name,...

        1 Reply Last reply Reply Quote 0
        • M Offline
          maricanis
          last edited by

          Thanks,

          I came to the same conclusion after various forum's posts reading and my experiments with code. Just wanted to be sure if I understood it well.

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            To recap.

            Component definitions can have attributes.
            These apply to the definition and are therefore accessible via definition.get_attribute(...)

            Component definitions can have entities,
            These entities can have attributes.
            These apply to the entities with the definition, and are therefore accessible via some_entity.get_attribute(...)

            Component instances can have attributes.
            These apply to the instance and are therefore accessible via instance.get_attribute(...)

            If you have an attribute set for any entity that is within a definition.entities context, then that attribute is accessible all instance.definition.entities - i.e. it is the same attribute, and therefore if you ' .set_...' it, it affects every instance sharing that definition - just as if you had painted a face 'red' inside the definition you should expect every instance to show that subsequently.

            TIG

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement