Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

C# to access the setup for the Layer Translator

dennis
Advisor

C# to access the setup for the Layer Translator

dennis
Advisor
Advisor

Can someone confirm whether this is possible, to access the Layer Translator setup in a DWS file.  I suspect the translation is stored in a Dictionary, and if so, then could it be accessed and modified via code, such as C#.

0 Likes
Reply
1,490 Views
3 Replies
Replies (3)

moogalm
Autodesk Support
Autodesk Support

Hi,

 

If I understand correctly, you would like access (r\w) the mapping information between layers in translation, the information is stored in DWS under AcStPlugin dictionary, AcStLay.AcStLayer2  which is a AcDbXRecord. ?

 

I'm not sure if we can retrieve the information, there is Activex lib for this AcStMgr.tlb, I'm investigating on this.

 

I will get back to you if I find any further information.

 

 

 

0 Likes

dennis
Advisor
Advisor

Thanks for the assist Madhukar

0 Likes

moogalm
Autodesk Support
Autodesk Support

Dennis, thank you for your patience

 

LayerTranslationMappings are stored in XDATA of each layer in DWS, DWS is same as DWG with different extension, readDWG API you can change Layer properties.(Thanks to lee from ACAD Documentation team for the tip)


The mappings can retrieved as following. 

 



 

For the attached DWS, following is the output

 

LAYER TRANSLATION MAPPING:
A:1
B:2
C:3

 

 

public static void tstreadDws()
        {
            // save old database
            Database oldDb = HostApplicationServices.WorkingDatabase;
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            // when using ReadDwgFile, never specify True to buildDefaultDwg
            // also, set noDocument=True because this drawing has no
            // AutoCAD Document associated with it
            using (Database db = new Database(false, true))
            {
                db.ReadDwgFile("D:\\Temp\\MyStandard.dws", FileOpenMode.OpenForReadAndWriteNoShare, true, "");
                // closing the input makes sure the whole dwg is read from disk
                // it also closes the file so you can SaveAs the same name
                db.CloseInput(true);
                string appName = "ACLAYTRANS";               
                string msg = "LAYER TRANSLATION MAPPING:\n";

                // ok time to set the working database

                HostApplicationServices.WorkingDatabase = db;
                using (Transaction t = db.TransactionManager.StartTransaction())
                {
                    LayerTable lt = t.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                    foreach(ObjectId oId in lt)
                    {
                        LayerTableRecord ltr = t.GetObject(oId, OpenMode.ForRead) as LayerTableRecord;
                        
                        ResultBuffer rb = ltr.GetXDataForApplication(appName);
                        if (rb != null)
                        {
                            string layerName = ltr.Name;
                            // Get the values in the xdata
                            foreach (TypedValue typeVal in rb)
                            {
                             
                                if(typeVal.TypeCode == 1000)
                                {
                                    msg = msg + layerName + ":" + typeVal.Value +"\n";
                                }
                            }
                        }
                        

                    }
                    t.Commit();
                }
                ed.WriteMessage(msg);
                // reset it back ASAP
              HostApplicationServices.WorkingDatabase = oldDb;
                
            }

        }