Exemple de plan d'exécution d'API Precast

Afficher une implémentation d'API simple de la commande de plan d'exécution.

Création d'un plan d'exécution

IShopDrawingOptions options = new ShopDrawingSampleOptions();
IShopDrawingCreator creator = ShopDrawingCreatorFactory.Get(assemblyInstance);

// use the creator to create a shop drawing.
// the creator is bound to the assembly used to get it.
ElementId createdSheetId;
creator.Create(options, out createdSheetId);

Mise en œuvre d'IShopDrawingOptions par l'utilisateur de l'API

class ShopDrawingSampleOptions : ShopDrawingDefaultOptions
   {
      public override bool GetOutlineName(out string outlineName)
      {
         outlineName = "Sample Outline";
         return true;
      }

      public override bool GetExtentsName(out string extentsName)
      {
         extentsName = "Sample Extents";
         return true;
      }
   }

Enregistrement des événements de création de plan d'exécution

ShopDrawingEvents.TaggingView += OnTaggingView; // called before a view is tagged
ShopDrawingEvents.DetailedViews += OnDetailedViews; // called when the detailing for all views is finished

void OnTaggingView(object sender, ITaggingViewEventArgs eventArgs)
{
   // As an example, prevent all Precast tagging from happening
   eventArgs.Cancel = true;
}

void OnDetailedViews(object sender, IDetailedViewsEventArgs eventArgs)
{
   // After the detailing is done, create sample tagging,
   // by adding a tag to the AssemblyInstance, but only in some views
   IEnumerable<IViewportData> viewPorts = eventArgs.Viewports.Where(IsFrontOrBackView);
   foreach (IViewportData viewport in viewPorts)
   {
      // when this event handler is called, a transaction is already opened,
      // so no need to start one
      CreateExampleTagInView(eventArgs.Document, viewport);
   }
}