Click or drag to resize

GenericExportHandlerT, E, I Class

A generic abstract "ERP Export Handler" event extension. Supports component itemization including multiconfiguration export, cut-list items, and consistency validation, item attachment rows, value writebacks to items supporting models, drawings and cutlist items, export document collection, and both 2-phased export and silent export for PDM. Itemizes rows using I (RowItemizer) into T (ExportItem). It is also possible to override both the itemizer and the item types with custom inheriants at CreateObjectT for the given type.
Inheritance Hierarchy
SystemObject
  CTExtensions.ExportCore.EXTsEventExtension
    CTExtensions.ExportCore.EXTsEventExtensionT
      CTExtensions.ExportCore.ExportHandlerGenericExportHandlerT, E, I

Namespace: CTExtensions.ExportCore.ExportHandler
Assembly: CTInterface (in CTInterface.dll) Version: 25.0
Syntax
public abstract class GenericExportHandler<T, E, I> : EventExtension<T>, 
	IGenericExportHandler
where T : CTExtension
where E : new(), ExportItem
where I : new(), RowItemizer

Type Parameters

T
Type of the parent CTExtension
E
An object that corresponds to an item at ERP
I
Itemizer that decides if an Export row is an ERP Item or not.

The GenericExportHandlerT, E, I type exposes the following members.

Constructors
 NameDescription
Public methodGenericExportHandlerT, E, I Constuctor.
Top
Properties
 NameDescription
Public propertyContextMenuBOMModifiers 
Public propertyConversionCheckboxes 
Protected propertyCurrentExportCase This this generic handles supports normal export, export in PDM and silent export, it's often important to know which case is the current one.
Protected propertyExportSucceeded True if user implementation of Export(ListE) retuned true, or if implementation of SecondPhaseExport(ListE) returns true.
Public propertyExtendedSettings The base extension class, in case it supports extended settings.
Public propertyGeneralSetting_AttachMergedPDFsToRootItems True to collect merge PDFs as documents of the root item. Default is false to avoid regression.
Protected propertyHandleExport A flag that is set to true when user loads an Export Profile bound to this handler. False otherwise and when user has exited the Export. Used to define whether specific events should be handled or not.
Public propertyItemizer RowItemizer that defines which export rows are unique items and which ones are attachments of those unique items.
Protected propertySilentMode True when the export core requests Silent Export. When this is true, export handling is expected to be fully automatic and must not have any user interaction.
Public propertyWriteBackHandler The class that handles writing back values from Export to files.
Top
Methods
 NameDescription
Public methodAllowInplaceWriteBack Returns whether or not inplace editing is allowed for an item. This considers different launch cases for Export:
- From SOLIDWORKS -> Must have write access
- From PDM -> All must be checked in (writeback handled at Task Host)
OR The one being edited must be checked out (writeback handled locally).
- Silent Export -> Never allowed as user interaction doesn't make sense in that case


Note that this PDM-logic can conflict with what ERP integrations do: Either ALL files must be checked-in or NONE of them (than need writeback) must be checked-in.
Protected methodCancelConversionsFromUnaffectedItems Checks if items are affected by currently set conversion rules, and if not, set cancelled flag.
Protected methodCheckBOMModifierValueMatch Returns whether or not given field (or parent field) value matches given pattern.

This supports exact value (case-insensitive), starts with, ends with, contains and NOT versions for all of those. For starts-with, use asterisk (*) as wildcard at the end of the value, for ends-with at the beginning and for contains at both. For NOT, start the value with exclamation (!).

To base the rule on PARENT's value, start with accent (^).

Furhermore, you can do OR -rules using pipe (|) in between.

Wildcard alone (*) is "must have non-empty value". Null or whitespace only is ignored. To achieve "must have empty value", use negation of "must have non-empty value" i.e. '!*'.

Value comparison is case-insensitive.
Protected methodCheckWritebackAccessInPrefill 
Protected methodDeserializeSecondPhase Deserialize this object and its items.
Protected methodDiscardExcludedFromBOMItems This function discards all excluded from BOM components from items. It's called after UpdateItemsPreFilling(ListE) but before UpdateItemsPostFilling(ListE). It's safe to call also during overridden implementation of UpdateItemsPreFilling(ListE) in case excluded from BOM components can be completely discarded by the implementation.
Protected methodExport User has clicked the Export button, and the items are prepared for the export. Remember to check the export case using CurrentExportCase and if SilentMode is set.
Protected methodFinalizeSecondPhase 
Protected methodGetAdditionalColumnsSetup Allows injecting new columns to export and hiding existing ones.
Protected methodGetAdditionalColumnsSetup2 Allows defining Editable columns in List view.
Public methodGetExportProfile Getter for current export profile.
Public methodGetItemizer Getter for loosly typed Itemizer, mostly for internal puposes.
Public methodGetParent Getter for Parent Extension, mostly for internal puposes.
Public methodGetRoots Get all non-excluded root items from the last itemized structure.
Public methodHook Event subscribtions, called by the framework if T is inheritant of ExportBaseFIELDSETTINGSTYPE, EXPORTSETTINGSTYPE, PROFILESETTINGSTYPE, USERSETTINGSTYPE and this extension is provided with GetEventExtensions. If this event extension is used directly, then also Hook(CTInterface) must be called manually at T's implementation of Hook(CTInterface).
(Overrides EventExtensionHook(CTInterface))
Public methodInit Initialization, called by the framework if T is inheritant of ExportBaseFIELDSETTINGSTYPE, EXPORTSETTINGSTYPE, PROFILESETTINGSTYPE, USERSETTINGSTYPE and this extension is provided with GetEventExtensions. If this event extension is used directly, then also Init(T) must be called immediately after this class is instantiated.
(Overrides EventExtensionEXTTYPEInit(EXTTYPE))
Protected methodInitExport Initialization of this class for Export procedure, or to disable or handling; depending if the typename of the given export profile matches the indentifying name of the parent extension.
Public methodLog Log everything that happends.
Protected methodManipulateExportDataBeforeItemization Override this function to do anything you like for the data before it's being itemized. Note that this is invoked for all exported configurations separately.
Protected methodNeedsSecondsPhase Indicates is second phase is required or not. By default it IS needed if we are outside SW context, the first phase succeeded and any of the items has cached writebacks or has not cancelled its conversions.
Protected methodOnCloseCustomStructureDlg Resets this class by calling InitExport(ICTExportProfile, Boolean, Boolean, Int64, Int32) with nulls and defaults.
Protected methodOnPostFileConversion 
Protected methodOnQueryCancelExportConversions 
Protected methodPerformWritebacksWithCheckoutAndCheckin Collects all cached writeback requests from the items, requests write access to each individual file (causes check-out in PDM), applies the writebacks, and then releases the obtained write accesses (causes check-in to PDM) and clears cached writebacks.
Protected methodPreExport This function is called immediately before Export(ListE) to give arguments provided by the framework and Export Profile settings.
Protected methodQueryExportSuccess 
Public methodRefreshItems 
Protected methodRefreshItems(ListE) 
Protected methodSecondPhaseExport This function is called during the second phase Export. At this point all conversions are done and collected, and writebacks are already done to files. This is mostly desined for sending converted documents to the target system, however, it is also possible to handle the whole Export Process silently within this function. To write addtitional writebacks to files, call PerformWritebacksWithCheckoutAndCheckin(ListE) after caching the writebacks to items. Note that PerformWritebacksWithCheckoutAndCheckin(ListE) is already called once during SecondPhaseInitialized(ListE) so if there were writebacks added at the first export phase, some items might get multiple versions checked-in. You can override SecondPhaseInitialized(ListE) to not call.
Protected methodSecondPhaseInitialized Called after deserialization is done and this class and all items have all data available. Calls PerformWritebacksWithCheckoutAndCheckin(ListE) to write pending value writebacks as the conversions are performed after this and it might be important to have updated values visible in converted documents.
Protected methodSerializeForSecondPhase Serialize this object and its Items.
Protected methodShowExportDoneMessage 
Protected methodShowProcessContinuesToSecondPhaseMessage 
Public methodUnHook Event unsubscribtions, called by the framework if T is inheritant of ExportBaseFIELDSETTINGSTYPE, EXPORTSETTINGSTYPE, PROFILESETTINGSTYPE, USERSETTINGSTYPE and this extension is provided with GetEventExtensions. If this event extension is used directly, then also UnHook(CTInterface) must be called manually at T's implementation of UnHook(CTInterface).
(Overrides EventExtensionUnHook(CTInterface))
Protected methodUpdateItemsPostFilling All the same operations should be doable in UpdateItemsPreFilling(ListE), which recommended over this function. If there for some reason is a need to directly manipulate ListView rows, it can be done here.
Protected methodUpdateItemsPreFilling Do possible queries to target systems to map the items etc. Supports setting field and bom field values, colors and everything even before the actual list view items are added to the list.
Protected methodVerifyFieldHandler 
Top
Fields
 NameDescription
Protected fieldmbCollectConvertedDocs Flag to collect converted documents for items during export.
Protected fieldmlExporWindowHandle Window handle for the Export Dialog
Protected fieldmoExportListViews Dictinary from source configration to List View in different export tabs.
Protected fieldmoExportProfile Export profile that is being processed.
Protected fieldmoExportProfileDatas Dictionary from source configuration to Export Profile data in different export tabs.
Protected fieldmoParent Parent Extensions that intantiates this Export Handler
Protected fieldmoRightClickItems Right click menu for items. The row must be detected as an item (rather than an attachment) to have right click menu. Dictionary key is the ID, followed by a list of tuples, where Item1 is the menuitem text than the Item2 is the action to invoke.
Top
Example
This example shows how to create Export Add-ins that use the very powerful GenericExportHandlerT, E, I for itemization, supporting all CUSTOMTOOLS Export features including multiconfiguration export and configuration grouping, converted document collecting, execution within PDM, possiblity to writeback values, 2-phased and silent PDM exports, and many other. For even more complete example look for "MyCustomErpIntegration".

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

using ATR.CT.CTInterface;
using CTEngineLib;
using CTExtensions.ExportCore.Config;           /* ExportSettingsBase, Dummy */
using CTExtensions.ExportCore.EXTs;             /* EventExtension */
using CTExtensions.ExportCore.ExportBaseTypes;  /* ERPExportBase */
using System.Collections.Generic;               /* List */
using CTExtensions.ExportCore.ExportHandler;    /* GenericExportHandler */
using System.Linq;

/*
 * NOTE: This add-in requires CUSTOMTOOLS 2024 SP1 or newer to work properly.
 */

namespace MyCustomItemExportAddinDemo
{

  // THIS is the main class of the extension
  public class MyCustomItemExportAddin : ERPExportBase
  {
    public override string FriendlyName()
    {
      return "My Export Add-in"; // This is shown in the UI.
    }

    public override string IdentifyingName()
    {
      return "MY-EXPORT-ADDIN-12345"; // Just something that is unique and constant.
    }

    public override List<EventExtension> GetEventExtensions()
    {
      return new List<EventExtension>() { new MyExportHandler() };
    }

    // Override to add PDM context support.
    protected override ExportTypeExt<ExportSettingsBase<Dummy>, Dummy> CreateExportType()
    {
      return new ExportWithFullPDMSupport();
    }

    // This class adds full PDM support, both 2-phased export (= export on client; conversions and writebacks on task host machine),
    // and silent execution (= completely on task host machine with no user interaction).
    // MyExportHandler should investigate MyExportHandler.CurrentExportCase variable to know the context.
    public class ExportWithFullPDMSupport : ExportTypeExt<ExportSettingsBase<Dummy>, Dummy>
    {
      public override bool AllowUseInSWPDM()
      {
        return true;
      }

      public override bool SupportsSilentExecution()
      {
        return true;
      }
    }
  }


  // This is the class that does all the magic in Export.
  public class MyExportHandler : GenericExportHandler<MyCustomItemExportAddin, ExportItem, RowItemizer>
  {


    // This is called for items before they are filled to list(s).
    protected override void UpdateItemsPreFilling(List<ExportItem> items)
    {

      // It's important to know in which context you are and what you can do.
      // If you are outside SOLIDWORKS, then you cannot use SOLIDWORKS API. 
      if (CurrentExportCase == ExportCase.SOLIDWORKS)
      {
        // This Export is being called from SOLIDWORKS
        Log("This goes to %TEMP%\\MY-EXPORT-ADDIN-12345.log"); // Log file name is IdentifyingName
      }
      else if (CurrentExportCase == ExportCase.PDM)
      {
        // This Export is being called (usually) from PDM

        Log("This goes to Task Details"); // Or to some other system that can do task-like executions in the future.
      }
      else if (CurrentExportCase == ExportCase.SOLIDWORKS_Silent)
      {
        // This Export started outside SOLIDWORKS (usually from PDM) but is now being performed inside SOLIDWORKS
        // SILENTLY, which means user add-ins like this SHOULD NOT HAVE ANY USER INTERACTION!

        // It's not guaranteed that the files are open in SOLIDWORKS as that depends on the task settings.

        Log("This goes to Task Details and the operation is silent."); // Or to some other system that can do task-like executions in the future.
      }

    }

    // This is the actual export that happens after clicking that Export button in Export dialog.
    protected override bool Export(List<ExportItem> items)
    {


      // Do the actual export.


      return true; // Success
    }


    /// This function is called during the second phase Export. At this point
    /// all conversions are done and collected, and writebacks are already done to files. This is mostly desined for
    /// sending converted documents to the target system, however, it is also possible to handle the whole Export Process
    /// silently within this function. 
    /// To write addtitional writebacks to files, call "PerformWritebacksWithCheckoutAndCheckin(...)" after
    /// caching the writebacks to items. Note that "PerformWritebacksWithCheckoutAndCheckin(...)" is already
    /// called once during "SecondPhaseInitialized(...)" so if there were writebacks added at the first
    /// export phase, some items might get multiple versions checked-in. You can override "SecondPhaseInitialized(...)"
    /// to not call.
    protected override bool SecondPhaseExport(List<ExportItem> items)
    {


      return true; // Report success
    }

  }




}
Revision History
DateVersionDescription
-2024 SP0First Release
-2025 SP0 - Extended with GetAdditionalColumnsSetup2(IListViewEx, String, DictionaryString, Boolean, ListString, ListString) thus adding support for in-place editing of columns, with writeback option. See AllowInplaceEdits and WritebackInplaceEdits. - Added support for in-place editing of columns, with writeback option. - Extended with PreExport(PreExportArgs).
-2025 SP1 - Added support for in-place editing of columns, with writeback option. -
See Also