Hi everyone,
I’m trying to attach a .dgn file to the active DraftSight document using the following function.
However, the InsertDgn() method always returns null, and I’m not sure what I’m missing.
Here’s my code:
public static void Attach_dgn(Document dsDoc, string dngFileName)
{
if (dsDoc == null)
{
MessageBox.Show("There are no open documents in DraftSight.");
return;
}
if (!File.Exists(dngFileName))
{
MessageBox.Show("File not found: " + dngFileName);
return;
}
try
{
Model dsModel = dsDoc.GetModel();
SketchManager dsSketchManager = dsModel.GetSketchManager();
dsModel.Activate();
DgnReference dsReference = dsSketchManager.InsertDgn(dngFileName, "Model", dsDgnConversionUnitType_e.dsDgnConversionUnitType_MasterUnit, 0, 0, 0, 10, 0);
if (dsReference == null)
{
MessageBox.Show("Failed to insert DGN. Check model name or file format.");
}
else
{
MessageBox.Show("DGN reference inserted successfully!");
}
}
catch (COMException comEx)
{
MessageBox.Show("COM error: " + comEx.Message);
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
I’ve verified that:
- The
.dgnfile exists and opens fine in DraftSight. - The file path is correct and absolute.
- I’m running this on a valid
DocumentandSketchManager.
Still, InsertDgn() returns null every time.
Has anyone successfully used InsertDgn() through the DraftSight API?
Any guidance or working example would be greatly appreciated!
