Click or drag to resize

DrawingCreatorExtension Class

Base implementation of interface type ctExtensionInterfaceDrawingCreator. Must implement at least GetParent. Override GetInterface2(ctExtensionInterface) in your extension and return your implementation of this interface when requested type is ctExtensionInterfaceDrawingCreator. This enables your extension to be attached to drawing creation rules.
Inheritance Hierarchy
SystemObject
  CTExtensions.InterfacesDrawingCreatorExtension

Namespace:  CTExtensions.Interfaces
Assembly:  CTInterface (in CTInterface.dll)
Syntax
public abstract class DrawingCreatorExtension : IExtensionInterface

The DrawingCreatorExtension type exposes the following members.

Constructors
  NameDescription
Protected methodDrawingCreatorExtension
Initializes a new instance of the DrawingCreatorExtension class
Top
Methods
  NameDescription
Public methodAddViews
Called after PreAddViews. If you return true, you are responsible of creating all the views using SW API. Dimensions are imported for all views after this if defined in Drawing Creation Rule settings.
Public methodGetParent
Must implement. Return parent CTExtension of this Drawing Creator Extension.
Public methodOverrideCustomSheetName
If the automation rule uses Custom Sheet name, you can override it here. Called when the drawing rule is selected for a component, after OverrideDrawingFilename.
Public methodOverrideDrawingFilename
Called when the drawing rule is selected for a component at Batch Operations. You can override drawing name (full path). If overriden to empty, then drawing creation is ignored. If you need licensed Document Manager to inspect the source model, you can obtain it with static call CTInterface.GetSWDocManager(). SldWorks instance can be obtained and cached at MyExtension.Hook.
Public methodPostAddViews
Post Process the sheet. E.g. add BOM for assembly drawings.
Public methodPreAddViews
Called when rules are executing. When this is called, the drawing is created but not saved, source model is open and has the configuration to be used as reference activated. Allows doing custom preparations for the sheet before views are added.
Top
Examples
This example shows how to create a Script Extension for a Drawing Creation Rule.

Language: C#
Class name: MyExtension
C#
// @AUTO-REFERENCE { [CT_INSTALL_PATH]\CTInterface.dll }
// @AUTO-REFERENCE { [CT_INSTALL_PATH]\Interop.CTEngineLib.dll }
// @AUTO-REFERENCE { [CT_INSTALL_PATH]\SolidWorks.Interop.sldworks.dll }

using ATR.CT.CTInterface;
using CTExtensions;
using CTExtensions.Interfaces;
using CTEngineLib;
using SolidWorks.Interop.sldworks;
using System.Runtime.InteropServices;

namespace Example
{

  /// <summary>
  /// Example extension that provides basic frame for custom drawing automation routines.
  /// This class is the main extension that provides 'DrawingCreatorExtension' capability for CT Core.
  /// </summary>
  public class MyExtension : CTExtension
  {

    private DrawingCreatorExtension moMyDrawingCreator = null;

    /// <summary>
    /// By defaut, Friendly name is is extension's class name i.e. MyExtension.
    /// Use sees this at "Script Extension" -selection at Drawing Creation Rule settings.
    /// </summary>
    /// <returns></returns>
    public override string FriendlyName()
    {
      return "Single View Creator";
    }

    /// <summary>
    /// Hook and UnHook are empty, since we are not interested
    /// in CTInterface events. However, if you need SldWorks object,
    /// it can be obtained here from oCTInterface.SldWorksInstance and
    /// cached for later use.
    /// </summary>
    public override bool Hook(CTInterface oCTInterface)
    {

      return false;
    }
    public override void UnHook(CTInterface oCTInterface)
    {
    }

    /// <summary>
    /// GetInterface2 returns capabilities of this extension.
    /// While the interface supports returning array, there should be
    /// only one DrawingCreatorExtensions per main Extension.
    /// </summary>
    public override IExtensionInterface[] GetInterface2(ctExtensionInterface eInterface)
    {
      if (eInterface == ctExtensionInterface.ctExtensionInterfaceDrawingCreator)
      {
        if (moMyDrawingCreator == null)
          moMyDrawingCreator = new MyDrawingCreator(this);
        return new[] { moMyDrawingCreator };
      }
      return null;
    }
  }

  /// <summary>
  /// This is the actual view creator i.e. the magic class.
  /// 
  /// NOTE: You should avoid creating additional sheets especially for other configurations.
  /// Supplementing drawings with configuration specific sheet is planned to be 
  /// introduced later as generic feature that would support also existing DrawingCreatorExtensions.
  /// </summary>
  public class MyDrawingCreator : DrawingCreatorExtension
  {

    MyExtension moParent;

    public MyDrawingCreator(MyExtension parent)
    {
      moParent = parent;
    }

    /// <summary>
    /// Must implement.
    /// </summary>
    public override ICTExtension GetParent()
    {
      return moParent;
    }

    /// <summary>
    /// Called when the drawing rule is selected for a component. 
    /// 
    /// You can override drawing name (full path). If overriden to empty, then drawing creation is ignored.
    /// If you need licensed Document Manager to inspect the source model, you can obtain it with static call CTInterface.GetSWDocManager().
    /// SldWorks instance can be obtained and cached at MyExtension.Hook.
    /// </summary>
    /// <returns>true if you overrode the path</returns>
    public override bool OverrideDrawingFilename(CTDrawingAutomation oAutomation, string bsModelFilename, string bsModelConfiguration, string bsDrwFilename, out string bsDrwFilenameOverride)
    {
      bsDrwFilenameOverride = "";
      return false;
    }

    /// <summary>
    /// If the automation rule uses Custom Sheet name, you can override it here. 
    /// 
    /// Called when the drawing rule is selected for a component, after OverrideDrawingFilename.
    /// </summary>
    /// <returns>true if you overrode the custom name</returns>
    public override bool OverrideCustomSheetName(CTDrawingAutomation oAutomation, string bsModelFilename, string bsModelConfiguration, string bsSheetName, out string bsSheetNameOverride)
    {
      bsSheetNameOverride = "";
      return false;
    }

    /// <summary>
    /// Called when rules are executing. When this is called, the drawing is created but not saved, 
    /// source model is open and has the configuration to be used as reference activated.
    /// 
    /// Allows doing custom preparations for the sheet before views are added.
    /// 
    /// 
    /// </summary>
    public override void PreAddViews(object oDrwDoc, object oSheet, object oSourceModel, string oSourceConfiguration)
    {

      IDrawingDoc oDrw = (IDrawingDoc)oDrwDoc;
      IModelDoc2 oModel = (IModelDoc2)oSourceModel;
      ISheet oDrwSheet = (ISheet)oSheet;

      // Do whatever preparations you want.


    }

    /// <summary>
    /// Called after PreAddViews. If you return true, you are responsible of creating all the views using
    /// SW API. Dimensions are imported for all views after this if defined in Drawing Creation Rule settings.
    /// 
    /// NOTE: You should avoid creating additional sheets especially for other configurations.
    /// Supplementing drawings with configuration specific sheet is planned to be 
    /// introduced later as generic feature that would support also existing DrawingCreatorExtensions.
    /// </summary>
    /// <returns>true if core should cancel its view creations and trust that you handle it.</returns>
    public override bool AddViews(object oDrwDoc, object oSheet, object oSourceModel, string oSourceConfiguration)
    {

      IDrawingDoc oDrw = (IDrawingDoc)oDrwDoc;
      IModelDoc2 oModel = (IModelDoc2)oSourceModel;
      ISheet oDrwSheet = (ISheet)oSheet;

      // Your code
      double dWidth = 0, dHeight = 0;
      oDrwSheet.GetSize(ref dWidth, ref dHeight);
      oDrw.CreateDrawViewFromModelView3(oModel.GetPathName(), "*Top", dWidth / 2, dHeight / 2, 0);

      return true;
    }

    /// <summary>
    /// Post Process the sheet. E.g. add BOM for assembly drawings.
    /// 
    /// NOTE: You should avoid creating additional sheets especially for other configurations.
    /// Supplementing drawings with configuration specific sheet is planned to be 
    /// introduced later as generic feature that would support also existing DrawingCreatorExtensions.
    /// </summary>
    public override void PostAddViews(object oDrwDoc, object oSheet, object oSourceModel, string oSourceConfiguration)
    {
      IDrawingDoc oDrw = (IDrawingDoc)oDrwDoc;
      IModelDoc2 oModel = (IModelDoc2)oSourceModel;
      ISheet oDrwSheet = (ISheet)oSheet;

      // TODO: If Assembly -> Add BOM...

    }

  }
}
Availability

CUSTOMTOOLS 2023 SP0


See Also