.NET

Reply
Active Member
jpkl
Posts: 7
Registered: ‎05-30-2008
Message 1 of 7 (576 Views)
Accepted Solution

DGNImport

576 Views, 6 Replies
12-15-2010 06:10 PM

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.

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

Distinguished Contributor
Irvin
Posts: 112
Registered: ‎04-22-2009
Message 2 of 7 (563 Views)

Re: DGNImport

12-16-2010 12:25 AM in reply to: jpkl

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

Active Member
jpkl
Posts: 7
Registered: ‎05-30-2008
Message 3 of 7 (527 Views)

Re: DGNImport

12-16-2010 03:39 PM 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

New Member
sandeepkavade
Posts: 1
Registered: ‎04-25-2013
Message 4 of 7 (289 Views)

Re: DGNImport

04-25-2013 11:26 PM in reply to: jpkl

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

Active Member
jpkl
Posts: 7
Registered: ‎05-30-2008
Message 5 of 7 (267 Views)

Re: DGNImport

04-28-2013 09:05 PM 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

Valued Contributor
michael.vanhoose
Posts: 71
Registered: ‎09-26-2007
Message 6 of 7 (250 Views)

Re: DGNImport

04-30-2013 09:07 AM in reply to: jpkl

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

Contributor
AbuFaisal
Posts: 13
Registered: ‎12-06-2012
Message 7 of 7 (184 Views)

Re: DGNImport

07-29-2013 11:31 PM in reply to: michael.vanhoose
Yes michael.vanhoose code really works fine

Thanks man
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.