Hide entity in given paper space viewports using overrule

By Adam Nagy

I would like to hide some entities in specific viewports. I thought about using overrule but not sure how to get started.

Solution

If you only need to hide given entities in certain paper space viewports, i.e. you do not need this functionality for model space viewports, then you can use layers which are designed to solve per viewport visibility.

These are the things your AddIn needs to do:

  1. Create a clone of the layer that the entity you want to hide in a specific viewport is using. This is needed so that when the entity is drawing itself in the viewports where it is still visible, it will use the same color, line width, etc, that it would originally use 
  2. For the same reason, you would also need to keep the clone layer properties in sync with the original layer 
  3. Freeze the clone layer in the appropriate viewports 
  4. Use overrule to make the entity use the previously created clone layer 

When the layer is cloned, the program adds an extension dictionary entry to it with the ObjectId of the original layer. It also monitors the layers for changes in order to update the cloned layers.

It also adds an extension dictionary entry to the overruled entity with the ObjectId of the clone layer it should use – also the Overrule is filtered to entities that have this specific extension dictionary entry.

And this is the Overrule's implementation:

public class MyOverrule : DrawableOverrule

{

  public override int SetAttributes(

    Drawable drawable, DrawableTraits traits)

  {

    int ret = base.SetAttributes(drawable, traits);

 

    ObjectId id = HideControl.GetEntityLayerId(drawable);

    if (!id.IsNull)

      traits.Layer = id;

 

    return ret;

  }

}

The attached project is just to show the concept, and is not fully implemented or tested.

Download _hideobjectpervp_2011-02-15


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading