 | CTInterfaceOnPostFileConversion Event |
Invoked after CUSTOMTOOLS has performed file conversion.
Namespace: ATR.CT.CTInterfaceAssembly: CTInterface (in CTInterface.dll) Version: 25.0
Syntax
Example
This sample shows how you can create an event hook and handle the OnPostFileConversion event.
public class CDocumentValues
{
public ModelDoc2 poDoc = null;
public string psRevision { get; set; }
public string psQty { get; set; }
public string psMaterial { get; set; }
public string psConfigurationName { get; set; }
public string psFilename { get; set; }
public string psOutputFileExt { get; set; }
public string psConfDrawingName { get; set; }
public List<string> pslSelectedOpts = new List<string>();
}
public CTFileConversion(ATR.CT.CTInterface.CTInterface ctInterface)
{
_ctInterface = ctInterface;
_ctInterface.OnPostFileConversion += new EventHandler<ATR.CT.CTInterface.CTInterface.PostFileConversionArgs>(_ctInterface_OnPostFileConversion);
}
#region PostFileConversion
void _ctInterface_OnPostFileConversion(object sender, ATR.CT.CTInterface.CTInterface.PostFileConversionArgs e)
{
if (!e.BatchConversionRule.Name.StartsWith(@"[Scripted]", StringComparison.OrdinalIgnoreCase))
{
return;
}
ModelDoc2 oSrcDoc = (ModelDoc2)e.SourceModelDoc;
CDocumentValues cCurrent = lConvCopys.Find(x => x.poDoc == oSrcDoc);
if (cCurrent != null)
lConvCopys.Remove(cCurrent);
int iConvertedFilesCount = 0;
if (cCurrent.pslSelectedOpts.Count > 0)
{
foreach (string sOption in cCurrent.pslSelectedOpts)
{
if (sOption.Equals("CopyToERP", StringComparison.OrdinalIgnoreCase))
{
string sTargetPath = @"C:\Workspace\ERPFolder\";
CreateMissingFolder(sTargetPath);
string sOutputFilename = "";
if (cCurrent.psOutputFileExt.Equals(@".pdf", StringComparison.OrdinalIgnoreCase))
sOutputFilename = string.Format(@"{0}{1}{2}", sTargetPath, cCurrent.psFilename, cCurrent.psOutputFileExt);
else if(cCurrent.psRevision == "")
sOutputFilename = string.Format(@"{0}{1}{2}", sTargetPath, cCurrent.psConfDrawingName, cCurrent.psOutputFileExt);
else
sOutputFilename = string.Format(@"{0}{1} {2}{3}", sTargetPath, cCurrent.psConfDrawingName, cCurrent.psRevision, cCurrent.psOutputFileExt);
if (CopyFile(e.TargetFileName, sOutputFilename))
iConvertedFilesCount++;
}
}
}
else
{
if (cCurrent.psOutputFileExt.Equals(@".pdf", StringComparison.OrdinalIgnoreCase))
{
string sTargetPath = @"C:\Workspace\CT Conversion\";
CreateMissingFolder(sTargetPath);
string sOutputFilename = string.Format(@"{0}{1}{2}", sTargetPath, cCurrent.psFilename, cCurrent.psOutputFileExt);
if (CopyFile(e.TargetFileName, sOutputFilename))
iConvertedFilesCount++;
}
}
if(iConvertedFilesCount == cCurrent.pslSelectedOpts.Count)
DeleteFile(e.TargetFileName);
}
#endregion
#region WinAPI - File and Folder Handling
private void CreateMissingFolder(string sPath)
{
if (!Directory.Exists(sPath))
{
Directory.CreateDirectory(sPath);
}
}
private bool CopyFile(string sSrcFile, string sTgtFile)
{
try
{
File.Copy(sSrcFile, sTgtFile, true);
}
catch (Exception)
{
return false;
}
return true;
}
private void DeleteFile(string sFile)
{
File.Delete(sFile);
}
#endregion
Revision HistoryDate | Version | Description |
---|
- | 2016 SP1 | First Release |
See Also