- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
in my plugin I want to mimic the 'import dwg file' command from the sketch menu. There you can tick a checkmark "Create Sketch Blocks" and the Translator Addin will convert all AutoCAD Blocks into Inventor SketchBlockDefinitions.
I have tried different TranslationContext.OpenIntoExisting types (Sketch or PartDucument), different TranslationContext.Type's and different NameValueMap / Ini file settings.
The Translator Plugin will create SketchBlocks only if I set TranslationContext.OpenIntoExisting to the current PartDocument, but even if I give it the same ini values which I have save while manually importing, the Translotor options dialog will pop up and unfortunatly, the SketchBlocks will be imported into a new document, not the current one.
But when I set TranslationContext.OpenIntoExisting to a PlanarSketch, Inventor ignores the "Create Sketch Blocks" switch and therefor will not create the needed SketchBlockDefinitions.
So, what's the right way to import AutoCAD Blocks from an DWG into SketchBlockDefinitions of the current PartDocument ?
Here's the sample of my code:
...
TranslatorAddIn dwgTranslator = (TranslatorAddIn)m_inventorApplication.ApplicationAddIns.get_ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}");
if (dwgTranslator == null)
{
MessageBox.Show("Could not find DwgTranslator AddIn ");
return false;
}
dwgTranslator.Activate();
// create a new Planar Sketch, as context for the import operation
PlanarSketch sketch = skeltonDoc.ComponentDefinition.Sketches.Add(skeltonDoc.ComponentDefinition.WorkPlanes[1]);
TranslationContext translationContext = m_inventorApplication.TransientObjects.CreateTranslationContext();
/*
kUnspecifiedIOMechanism
kDataDropIOMechanism
kFileBrowseIOMechanism
kPasteSpecialIOMechanism
*/
translationContext.Type = IOMechanismEnum.kDataDropIOMechanism;
//translationContext.OpenIntoExisting = skeltonDoc.ComponentDefinition.SketchBlockDefinitions;
//translationContext.OpenIntoExisting = sketch;
translationContext.OpenIntoExisting = skeltonDoc;
NameValueMap options = m_inventorApplication.TransientObjects.CreateNameValueMap();
DataMedium sourceData = m_inventorApplication.TransientObjects.CreateDataMedium();
// FullFileName of the DWG file that has the AutoCAD Block
sourceData.FileName = strBlockDwgFileName;
string strIniFile = @"C:\\Temp\dwgoacadxxx";
options.set_Value("Import_Acad_IniFile", strIniFile);
//dwgTranslator.ShowOpenOptions(sourceData, translationContext, options);
Object sourceObj;
dwgTranslator.Open(sourceData, translationContext, options, out sourceObj);
Solved! Go to Solution.