Export to DWG and automaticaly bind images

Export to DWG and automaticaly bind images

1161314
Enthusiast Enthusiast
2,195 Views
10 Replies
Message 1 of 11

Export to DWG and automaticaly bind images

1161314
Enthusiast
Enthusiast

Hi,

Is it possible to make revit export to dwg and binding any images that are placed in the sheets? Something like e-transmit in autocad. 

 

Thanks

0 Likes
Accepted solutions (2)
2,196 Views
10 Replies
Replies (10)
Message 2 of 11

jeremytammik
Autodesk
Autodesk

If you can achieve what you wish manually in the user interface, then it can probably be driven programmatically by the API as well.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 11

1161314
Enthusiast
Enthusiast

I didn't understand your answer. I was asking if is possible to write na addin for revit that manipulates dwg files. In concrete, to bind images in files exported from revit.

0 Likes
Message 4 of 11

jeremytammik
Autodesk
Autodesk

Can you achieve what you need manually in the user interface?

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 11

1161314
Enthusiast
Enthusiast

Autocad.png

In the Revit interface no.

In autocad, is the etransmit command. Can i cal that command in na addin runnig in Revit?

0 Likes
Message 6 of 11

jeremytammik
Autodesk
Autodesk

The Revit API does not support this. It only supports activities that can also be run manually through the Revit user interface.

 

However, you can in fact make use of the AutoCAD.NET API as well as the Revit API inside your Revit add-in.

 

So that should be possible. 

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 7 of 11

1161314
Enthusiast
Enthusiast

So far i've done this:

        public static void Etrans(string desenho,string destination)
        {

            try
            {
                TransmittalFile tf;
                TransmittalOperation to = new TransmittalOperation();
                TransmittalInfo ti = to.getTransmittalInfoInterface();

                System.Windows.MessageBox.Show(desenho);
                to.addDrawingFile(desenho, out tf);

            ti.destinationRoot = destination;

            ti.preserveSubdirs = 0;


            ti.organizedFolder = 0;

            ti.dataLinkRelativePath = 1;
            ti.DGNUnderlayRelativePath = 1;
            ti.DWFUnderlayRelativePath = 1;
            ti.imageRelativePath = 1;
            ti.PDFUnderlayRelativePath = 1;
            ti.xrefRelativePath = 1;

            ti.saveVersion = SaveDwgFormat.eAutoCADR21;

            ti.visualFidelity = 1;

            ti.includeXrefDwg = 1;
            ti.includeUnloadedReferences = 1;
            ti.includeUnloadedXrefDwg = 1;
            ti.includeNestedOverlayXrefDwg = 1;

            ti.BindType = BindType.eBind;

            ti.depathXrefs = 1;

            ti.includeImageFile = 1;
            ti.includeDGNUnderlay = 1;
            ti.includeDWFUnderlay = 1;
            ti.includePDFUnderlay = 1;
            ti.includeDataLinkFile = 1;

            ti.includeFontFile = 1;

            // Reset plotters for layouts in the drawings to None, 
            // and include plot style (CTB/STB) files (0 - False, 1 - True)
            ti.resetPlotter = 0;
            ti.includePlotFile = 0;

            ti.includePhotometricWebFile = 1;
            ti.includeMaterialTextureFile = 1;

            ti.purgeDatabase = 0;

            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.ToString());
            }
            
            try
            {
                //to.createTransmittalPackage();
            }
            catch
            {
                System.Windows.MessageBox.Show("ERRO");
            }
        }

And call it here:

foreach (var f in files)
                    {
                        MessageBox.Show(pathArquivo);
                        if(f.FullName.Contains(".dwg"))
                        {

                            ZiTools.Etrans(f.FullName, pathArquivo);
                        }

But i get this error:

image.png

I've created the interop "TRANSMITTALLib.dll" as indicated here:

https://help.autodesk.com/view/OARX/2019/ENU/?guid=GUID-FF7AD257-9C2A-4A4D-8408-FC5C209DC7E8

0 Likes
Message 8 of 11

jeremytammik
Autodesk
Autodesk

To simplify matters, it ill probably be safest for you to develop your AutoCAD.NET add-in as a stand-alone app first, before trying to run it within a Revit add-in. That way, you eliminate one potential cause for problems. If you have any problems in that scenario, I would suggest raising them in the AutoCAD.NET discussion forum.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 9 of 11

1161314
Enthusiast
Enthusiast

I've managed to get the dwg database, but i get na error in transation:

image.png

 

0 Likes
Message 10 of 11

1161314
Enthusiast
Enthusiast
Accepted solution
public static void Etrans(string desenho)
        {
            System.Windows.MessageBox.Show(desenho + " Passou");
            Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database myDB = new Autodesk.AutoCAD.DatabaseServices.Database(false, true);
            using (myDB)
            {
                myDB.ReadDwgFile(desenho, FileOpenMode.OpenForReadAndAllShare, true, "");
                System.Windows.MessageBox.Show("DB Passou");
                string verDb = myDB.Ltscale.ToString();
                System.Windows.MessageBox.Show(verDb);

                try
                {
                    System.Windows.MessageBox.Show("Entrou try");
                    DBDictionary nod2 = myDB.NamedObjectsDictionaryId.GetObject(OpenMode.ForRead) as DBDictionary;
                    ObjectId imageDictId2 = nod2.GetAt("ACAD_IMAGE_DICT");
                    string verDit = imageDictId2.IsNull.ToString();
                    System.Windows.Forms.MessageBox.Show(verDit);

                    using (Autodesk.AutoCAD.DatabaseServices.Transaction myTrans = myDB.TransactionManager.StartTransaction())
                    {
                        DBDictionary nod = myTrans.GetObject(myDB.NamedObjectsDictionaryId, OpenMode.ForRead) as DBDictionary;
                        ObjectId imageDictId = nod.GetAt("ACAD_IMAGE_DICT");

                        DBDictionary imageDict = myTrans.GetObject(imageDictId, OpenMode.ForRead) as DBDictionary;
                        foreach (DBDictionaryEntry dbDictEntry in imageDict)
                        {
                            RasterImageDef rasterImageDef = myTrans.GetObject(dbDictEntry.Value, OpenMode.ForWrite) as RasterImageDef;
                            try
                            {
                                if (System.IO.File.Exists(rasterImageDef.SourceFileName))
                                {
                                    dynamic dwgPathUri = new Uri(desenho);
                                    dynamic rasterImagePathUri = new Uri(rasterImageDef.SourceFileName);

                                    // Make the raster image path  
                                    // relative to the drawing path 
                                    dynamic relativeRasterPathUri = dwgPathUri.MakeRelativeUri(rasterImagePathUri);

                                    // Set the source path as relative 
                                    rasterImageDef.SourceFileName = Uri.UnescapeDataString(relativeRasterPathUri.ToString());

                                    // Reload for AutoCAD to  
                                    // resolve active path 
                                    rasterImageDef.Load();

                                    // Check if we found it 


                                    //RasterImage raster = new RasterImage();
                                }
                            }
                            catch (Exception ex)
                            {
                                System.Windows.MessageBox.Show("Erro_Raster");
                            }
                            myDB.SaveAs(desenho, DwgVersion.Current);
                            myDB.Dispose();
                        }


                    }

                }
                catch (Exception ex)
                {
                    System.Windows.MessageBox.Show(ex.ToString());
                }

            }

        }
        #endregion
    }

This is the code, called by:

foreach (var f in files)
                    {
                        
                        if(f.FullName.Contains(".dwg"))
                        {
                            ZiTools.Etrans(f.FullName);
                        }
0 Likes
Message 11 of 11

1161314
Enthusiast
Enthusiast
Accepted solution

Just for the record, i've made it. But i had to use cad core manager.

0 Likes