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

C# to access the setup for the Layer Translator

3 REPLIES 3
Reply
Message 1 of 4
dennis
736 Views, 3 Replies

C# to access the setup for the Layer Translator

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#.

3 REPLIES 3
Message 2 of 4
moogalm
in reply to: dennis

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.

 

 

 

Message 3 of 4
dennis
in reply to: moogalm

Thanks for the assist Madhukar

Message 4 of 4
moogalm
in reply to: dennis

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;
                
            }

        }

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