C++ を使用して API に「ExportTo」という名前を付ける

次に、C++ を使用して API を「ExportTo」に変更する方法の例を示します。

ExportTo メソッドの詳細については、「ExportTo メソッド」を参照してください。

        public void StyleExportTest()
        {
            try
            {
                var dwgPathAndName = @"C:\STYLES_2021.dwg";
                if (!System.IO.File.Exists(dwgPathAndName))
                {
                    Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("No source file.\n");
                }
                var dbFrom = new Database(false, true);
                dbFrom.ReadDwgFile(dwgPathAndName, FileOpenMode.OpenForReadAndAllShare, false, null);
                var civDocFrom = CivilDocument.GetCivilDocument(dbFrom);
                var dbTo = HostApplicationServices.WorkingDatabase;

                using (var tr = dbTo.TransactionManager.StartOpenCloseTransaction())
                {
                    try
                    {
                        var lineStyles = civDocFrom.Styles.LabelStyles.GeneralLineLabelStyles;
                        var curveStyles = civDocFrom.Styles.LabelStyles.GeneralCurveLabelStyles;

                        ObjectIdCollection idsExport = new ObjectIdCollection(); ;
                        foreach (ObjectId id in lineStyles)
                            idsExport.Add(id);

                        foreach (ObjectId id in curveStyles)
                            idsExport.Add(id);

                        Autodesk.Civil.DatabaseServices.Styles.StyleBase.ExportTo(idsExport, dbTo, Autodesk.Civil.StyleConflictResolverType.Override);
                        tr.Commit();
                    }
                    catch (System.Exception ex)
                    {
                        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.Message + "Export failed.\n");
                    }
                }
            }
            catch (System.Exception ex)
            {
                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.Message + "Export failed.\n");
            }
        }