中望CAD机械接口(读写标题栏)(c#)

创建C#工程

创建工程

1、创建C#的控制台应用程序工程
中望CAD机械接口(读写标题栏)(c#)
2、设置工程适用x64或x86
右键点击解决方案,点击属性
中望CAD机械接口(读写标题栏)(c#)
3、选择代码优化
中望CAD机械接口(读写标题栏)(c#)
4、引入ZWCAD 2018 Type Library、 ZwmToolKit 1.0 Type Library依赖库
中望CAD机械接口(读写标题栏)(c#)

书写代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZWCAD;
using System.Runtime.InteropServices;
using System.IO;
using System.Text.RegularExpressions;
using ZwmToolKitLib;
namespace cadjxtest
{
    class Program
    {
        public static ZwmToolKitLib.ZwmDb m_objZwmDb;
        public static ZwmToolKitLib.Title m_objZwmTitle;
        static void Main(string[] args)
        {
            ZcadApplication m_cadApp;
            ZwmToolKitLib.ZwmApp m_objZwmApp;
            m_cadApp = new ZWCAD.ZcadApplication();
            m_cadApp.Visible = false;
            m_objZwmApp = m_cadApp.GetInterfaceObject("ZwmToolKit.ZwmApp");
            m_objZwmApp.GetDb(out m_objZwmDb);
            m_objZwmDb.OpenFile(args[0]);//dwg文件路径
            //m_objZwmDb.OpenFile("C:\\Users\\Administrator\\Desktop\\Drawing1.dwg");
            int framecount = 0;
            int nCount = 1;
            m_objZwmDb.GetFrameCount(out framecount);
            Console.WriteLine("framecount-->" + framecount);
            for (int i = 0; i < framecount; i++)
            {
                string bstrFrameName;
                m_objZwmDb.GetFrameName(i, out bstrFrameName);
                Console.WriteLine("bstrFrameName-->" + bstrFrameName);
                m_objZwmDb.SwitchFrame(bstrFrameName);
                if (m_objZwmDb != null && m_objZwmTitle == null)
                {
                    m_objZwmDb.GetTitle(ref m_objZwmTitle);
                }
                m_objZwmTitle.GetItemCount(ref nCount);
                for (int j = 0; j < nCount; j++)
                {
                    string strLabel = "";
                    string strName = "";
                    string strValue = "";
                    m_objZwmTitle.GetItem(j, ref strLabel, ref strName, ref strValue);
                    Console.WriteLine("strLabel----->>" + strLabel);
                    Console.WriteLine("strName----->>" + strName);
                    Console.WriteLine("strValue----->>" + strValue);
                    m_objZwmTitle.SetItem(strName, "要设置的值"); 
                }
            }
            m_objZwmDb.RefreshTitle();
            m_objZwmDb.Save();
            m_cadApp.Quit();
        }
    }
}

生成exe可执行文件