Hello All
Does anyone know if the functionallity used in the Command DGNImport is customisable via the API?
I've had a look but I can't seem to find it, but I know there are people out there with much more familiarity with it than me.
Thanks
Jason.
Solved! Go to Solution.
Solved by michael_vanhoose. Go to Solution.
Hi there,
I think your problem will besolved with net next block of code.
[CommandMethod("DgnAttach")] static public void DgnAttach() { Database db = Application.DocumentManager.MdiActiveDocument.Database; using (Transaction trans = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction()) { DBDictionary nod = (DBDictionary)trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite); string defDictKey = UnderlayDefinition.GetDictionaryKey(typeof(DgnDefinition)); if (!nod.Contains(defDictKey)) { using (DBDictionary dict = new DBDictionary()) { nod.SetAt(defDictKey, dict); trans.AddNewlyCreatedDBObject(dict, true); } } ObjectId idDgnDef; DBDictionary dgnDict = (DBDictionary)trans.GetObject(nod.GetAt(defDictKey), OpenMode.ForWrite); using (DgnDefinition dgnDef = new DgnDefinition()) { dgnDef.SourceFileName = @"c:\Temp\yourdgnfile.dgn"; idDgnDef = dgnDict.SetAt("YourDgnFile", dgnDef); trans.AddNewlyCreatedDBObject(dgnDef, true); } BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); using (DgnReference dgn = new DgnReference()) { dgn.DefinitionId = idDgnDef; btr.AppendEntity(dgn); trans.AddNewlyCreatedDBObject(dgn, true); } trans.Commit(); } }
If you want to attach a dwf file the above code can be used. You just need to change the DgnDefinition to DwfDefinition ect.
I hope this helps.
Kind regards,
Irvin
Irvin
Thank you for your reply.
However what I really need to do is to replicate some of the functionallity of the DGNIMPORT command not the DGNUNDERLAY (for which your code works perfectly for).
That is I need to translate the entities from the DGN file into native AutoCAD entities.
But once again thank you for your time.
Jason
Hi Sandeep
Unfortunately, no I did not have any success in this area.
Bentley are able to read in AutoCAD dwg format very well because of Autodesk's RealDWG. However I don't think they have anything similar to offer and AutoCAD's implementation of this doesn't seem to be public.
Sorry.
Jason
this will work.
For
Each file As System.IO.FileInfo Infiles
TryDim sfilename AsString= file.FullName
Dim sfilenamedwg AsString = mypath & System.IO.Path.GetFileNameWithoutExtension(sfilename) & ".dwg"If System.IO.File.Exists(sfilenamedwg) = TrueThenSystem.IO.File.Delete(sfilenamedwg)
Application.DocumentManager.MdiActiveDocument.SendStringToExecute(
"-dgnimport " & sfilename & vbCr & vbCr & vbCr & vbCr, False, False, True)
Application.DocumentManager.MdiActiveDocument.SendStringToExecute(
"saveas" & vbCr & vbCr & sfilenamedwg & vbCr, False, False, True)
Catch ex AsException
MsgBox(ex.ToString)
EndTryNext
Can't find what you're looking for? Ask the community or share your knowledge.