Question
Export 2D Drawing to DXF and DWG using VB API
Hello everyone,
We use Creo10.0.
I am able to export a DWG but certain parts of the drawing are missing. e.g. the title block.
Does someone know a solution. maybe it is relate to me using CCpfcDWG3DExportInstructions but no other instrutions i tested deliver a openable DWG.
public static string ExportToDwg(string inputFilePath)
{
if (string.IsNullOrWhiteSpace(inputFilePath))
throw new ArgumentNullException(nameof(inputFilePath), "No input file path provided.");
if (!System.IO.File.Exists(inputFilePath))
throw new ArgumentException($"File path does not exist: {inputFilePath}");
Interop interop = new Interop();
IpfcAsyncConnection connection = interop.Connection;
if (connection == null)
throw new Exception("Invalid Creo connection.");
FileInformation fileInfo = new FileInformation(inputFilePath);
IpfcBaseSession session = interop.Session;
Interop.ClearSessionCache(session);
session.ChangeDirectory(fileInfo.directory);
// Apply DWG Settings
Interop.ApplySettigns(session, "dwgSettings");
try
{
IpfcModel model = interop.GetModel(inputFilePath);
if (model == null)
throw new Exception("Model could not be retrieved.");
if (model.Type != (int)EpfcModelType.EpfcMDL_DRAWING)
throw new ArgumentException("Given model is not of type Drawing");
// Using Creo API for DWG Export
IpfcDWG3DExportInstructions dwgExportInstructions = new CCpfcDWG3DExportInstructions().Create();
if (File.Exists(fileInfo.exportedDWGFilePath))
{
File.SetAttributes(fileInfo.exportedDWGFilePath, FileAttributes.Normal);
System.IO.File.Delete(fileInfo.exportedDWGFilePath);
}
// Export DWG
Logger.Info("Trying to export DWG.");
model.Export(fileInfo.exportedDWGFilePath, (IpfcExportInstructions)dwgExportInstructions);
if (File.Exists(fileInfo.exportedDWGFilePath))
{
Logger.Info("DWG Export successfully.");
}
if (File.Exists(fileInfo.dwgPathForVault))
{
File.SetAttributes(fileInfo.dwgPathForVault, FileAttributes.Normal);
File.Delete(fileInfo.dwgPathForVault);
}
System.IO.File.Move(fileInfo.exportedDWGFilePath, fileInfo.dwgPathForVault);
// Ensure DWG file is created
if (!System.IO.File.Exists(fileInfo.dwgPathForVault))
throw new Exception("DWG file was not created. Check Creo log for errors.");
Logger.Info("DWG Export completed successfully.");
connection.Disconnect(5);
return fileInfo.dwgPathForVault;
}
catch (Exception ex)
{
try { Interop.ClearSessionCache(session); } catch { }
throw;
}
}I apply settings to creo like this:
public static void ApplySettigns(IpfcBaseSession session, string settingName)
{
ConfigReader configReader = new ConfigReader();
Dictionary<string, string> settings = new Dictionary<string, string>();
try
{
settings = configReader.GetSettings(settingName);
}
catch (ArgumentException ex)
{
Logger.Error(ex.Message);
}
if (settings.Count > 0)
{
foreach (KeyValuePair<string, string> setting in settings)
{
try
{
// configOptionName and configOptionValue
session.SetConfigOption(setting.Key, setting.Value);
}
catch (Exception ex)
{
Logger.Error($"Could not set {setting.Key} because of: {ex.Message}");
}
}
}
}These are my settings but in the export log they seem not to be applied:
<drawingSettings>
<add key="enable_popup_help" value="no" />
<add key="display_axes" value="no" />
<add key="display_coord_sys" value="no" />
<add key="display_planes" value="no" />
<add key="display_points" value="no" />
<add key="allow_mfg_in_assem_mode" value="yes" />
</drawingSettings>
<dwgSettings>
<!--https://support.ptc.com/help/creo/creo_pma/r8.0/usascii/#page/data_exchange/interface/Controlling_DXF_and_DWG_Export.html-->
<add key="DWG_EXPORT_FORMAT" value="2018" />
<add key="INTF2D_OUT_DXF_MAPPING_FILE" value="C:\PTC\cadpool\Kelvion_NOB\parametric\data\Kelvion_NOB\config\profile_dir\sut_dxf_export.pro" />
<add key="DXF_OUT_DRAWING_SCALE" value="NO" />
<add key="DXF_OUT_SCALE_VIEWS" value="NO" />
<add key="DXF_OUT_SEP_DIM_W_BREAKS" value="NO" />
<add key="INTF2D_OUT_STROKE_TEXT" value="All" />
<add key="INTF2D_OUT_ACAD_SPLINES" value="AS_SPLINE" />
<add key="INTF2D_OUT_ACAD_HATCHES" value="AS_HATCH" />
<add key="INTF_OUT_LAYER" value="NONE" />
<add key="INTF2D_OUT_ACAD_MTEXT" value="YES" />
<add key="INTF2D_OUT_ACAD_UNICODE" value="NO" />
<add key="INTF2D_OUT_ACAD_TEXT_ALIGN" value="AS_IS" />
<add key="INTF2D_OUT_PNT_ENT" value="NO" />
<add key="INTF2D_OUT_OPEN_LOG_WINDOW" value="NO" />
</dwgSettings>I much appreciate your help!

