.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DGNImport

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Anonymous
1255 Views, 6 Replies

DGNImport

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.

6 REPLIES 6
Message 2 of 7
Irvin
in reply to: Anonymous

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

Message 3 of 7
Anonymous
in reply to: 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

Message 4 of 7
sandeepkavade
in reply to: Anonymous

Hi Jason,

 

I know I am replying to old thread. But have you got any success about translating the DGN entities to DWG?

 

I am working on the same thing, so your inputs are greatly appreciated.

 

Thanks,

Sandeep

Tags (2)
Message 5 of 7
Anonymous
in reply to: sandeepkavade

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

Message 6 of 7
michael_vanhoose
in reply to: Anonymous

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

Message 7 of 7
Anonymous
in reply to: michael_vanhoose

Yes michael.vanhoose code really works fine

Thanks man

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost