跳转至

MyBlog

太原锅炉方案分析

方案一

先将所有零部件做成块
  • 所有的块需要遵循一个原则;要么所有图块的插入的基点在左边,要么基点在右边,建议统一个标准
  • 所有的块名定义按照**块名+视图**来命名
  • 如果有多个同名的块名,形状在2d上略有不同,那么块名---->**块名[编号]+视图**来命名
  • 件号需要重新插入,插入的时候选择零部件进行关联
  • 定型尺寸需要重新绘制在零部件的外框尺寸上
其它说明

[!WARNING]

由于存在块的尺寸与真实尺寸不一样的情况,这样定位尺寸和定型尺寸都不对

  • 需要保证尺寸标注标注在块的外框上
  • 除了在最左侧或最右侧的基准点,如果基准点在中间,需要保证基准点刚好是块的几何中心点

[!TIP]

  • 图纸上的尺寸标注数据基本都能提取出来,但是数据与块之间是没有关联关系的,需要人为去做一些处理告知程序这两者之间是有关联(比如在块上重新绘制标注信息)
  • 做成块是为了让零部件都是个整体,方便重新绘制件号与零部件关联,这样零部件对应的明细表信息就与部件关联起来了
我们能做什么
  • 将所有与块关联的尺寸提取出来
  • 将所有与块关联的明细表数据提取出来
  • 定位尺寸和定型尺寸如果不是真实尺寸,
  • 图纸上需要在块外框上标注尺寸
  • 需要保证基准点在最左端或最右端,或者在图块的中心,不然定位尺寸算不准
  • 开目图纸里的标注数据,如果只有一个文字可以将数据提取出来,但是与零部件的关联关系基本上是没有的
我们做不了什么
  • 提取的尺寸数据是有限的,如果没有关联关系,我们是无法将数据与图块进行联系
  • 开目图纸里除了只有一个文字的标注尺寸,其它的尺寸我们无法提取。文字数据太多也不清楚各个数据之间的关系以及表达方式。
  • 图块与图块之间是体现不了装配关系,所以单纯用图块来描述装配关系是描述不了
  • Excel表格大概需要109条数据,我们只能提取明细表的数据以及定位和定型尺寸数据

方案二

将所有的零部件做成块,然后为所有的零部件块增加自定义属性,

avatar

  • 每个零部件都增加一些自定义属性,零部件有一部分常规属性从图纸中获取,有一部分手动填写。
  • 自定义属性的好处在于,不管是要定型尺寸还是定位尺寸都可以手动填写。
  • 如果自动获取的数据不对也可以手动更改,方便随时调整更新
  • 不管什么数据都可以定义一个自定义信息
  • 不管是定型尺寸、定位尺寸、装配关系等,都可以自定义属性信息手动填写
  • 所有的数据都存储在当前dwg中,方便数据的导出

Vs自定义项目模板

image-20250415192756364

先配置好项目相关文件

导出项目相关文件

image-20250415192839962

导出为项目

image-20250415193017914

image-20250415193036748

image-20250415193112362

取消,需要对压缩文件进行处理

处理压缩包

image-20250415193410753

修改数据

img

修改完成后将压缩包放置到Visual Studio 2022\Templates\ProjectTemplates

Text Only
Visual Studio 2022\Templates\ProjectTemplates

image-20250415193604984

Text Only
MyTemplate.vstemplate
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
  <TemplateData>
    <Name>ZwObjectZrxNet</Name>
    <Description>ObjectZRX+WPF模板</Description>
    <ProjectType>CSharp</ProjectType>
    <ProjectSubType>
    </ProjectSubType>
    <SortOrder>1000</SortOrder>
    <CreateNewFolder>true</CreateNewFolder>
    <DefaultName>ZwObjectZrxNet</DefaultName>
    <ProvideDefaultName>true</ProvideDefaultName>
    <LocationField>Enabled</LocationField>
    <EnableLocationBrowseButton>true</EnableLocationBrowseButton>
    <Icon>__TemplateIcon.ico</Icon>
    <PreviewImage>__PreviewImage.ico</PreviewImage>
    <LanguageTag>CSharp</LanguageTag>
    <PlatformTag>Windows</PlatformTag>
    <ProjectTypeTag>Library</ProjectTypeTag>
  </TemplateData>
  <TemplateContent>
    <Project TargetFileName="$safeprojectname$.csproj" File="$safeprojectname$.csproj" ReplaceParameters="true">
      <ProjectItem ReplaceParameters="true" TargetFileName="app.config">app.config</ProjectItem>
      <ProjectItem ReplaceParameters="true" TargetFileName="Commands.cs">Commands.cs</ProjectItem>
      <Folder Name="Controls" TargetFolderName="Controls" />
      <Folder Name="Converters" TargetFolderName="Converters">
        <ProjectItem ReplaceParameters="true" TargetFileName="OptionToBooleanConverter.cs">OptionToBooleanConverter.cs</ProjectItem>
      </Folder>
      <Folder Name="Models" TargetFolderName="Models" />
      <ProjectItem ReplaceParameters="true" TargetFileName="packages.config">packages.config</ProjectItem>
      <ProjectItem ReplaceParameters="true" TargetFileName="PlugInApplication.cs">PlugInApplication.cs</ProjectItem>
      <Folder Name="Properties" TargetFolderName="Properties">
        <ProjectItem ReplaceParameters="true" TargetFileName="AssemblyInfo.cs">AssemblyInfo.cs</ProjectItem>
      </Folder>
      <Folder Name="Styles" TargetFolderName="Styles">
        <ProjectItem ReplaceParameters="true" TargetFileName="Styles.xaml">Styles.xaml</ProjectItem>
      </Folder>
      <Folder Name="ViewModel" TargetFolderName="ViewModel">
        <ProjectItem ReplaceParameters="true" TargetFileName="WpfDemoViewModel.cs">WpfDemoViewModel.cs</ProjectItem>
      </Folder>
      <Folder Name="Views" TargetFolderName="Views">
        <ProjectItem ReplaceParameters="true" TargetFileName="WpfDemo.xaml">WpfDemo.xaml</ProjectItem>
        <ProjectItem ReplaceParameters="true" TargetFileName="WpfDemo.xaml.cs">WpfDemo.xaml.cs</ProjectItem>
      </Folder>
    </Project>
  </TemplateContent>
</VSTemplate>

Csharp

Text Only
$safeprojectname$.csproj
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{$guid1$}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>$safeprojectname$</RootNamespace>
    <AssemblyName>$safeprojectname$</AssemblyName>
    <TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <Deterministic>true</Deterministic>
    <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    <NuGetPackageImportStamp>
    </NuGetPackageImportStamp>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>..\..\Out\Debug\bin\x64\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <LangVersion>7.3</LangVersion>
    <ErrorReport>prompt</ErrorReport>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
    <OutputPath>..\..\Out\Release\bin\x64\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <Optimize>true</Optimize>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <LangVersion>7.3</LangVersion>
    <ErrorReport>prompt</ErrorReport>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="CommunityToolkit.Mvvm, Version=8.4.0.0, Culture=neutral, PublicKeyToken=4aff67a105548ee2, processorArchitecture=MSIL">
      <HintPath>..\packages\CommunityToolkit.Mvvm.8.4.0\lib\netstandard2.0\CommunityToolkit.Mvvm.dll</HintPath>
    </Reference>
    <Reference Include="MaterialDesignColors, Version=5.2.1.0, Culture=neutral, PublicKeyToken=df2a72020bd7962a, processorArchitecture=MSIL">
      <HintPath>..\packages\MaterialDesignColors.5.2.1\lib\net462\MaterialDesignColors.dll</HintPath>
    </Reference>
    <Reference Include="MaterialDesignThemes.Wpf, Version=5.2.1.0, Culture=neutral, PublicKeyToken=df2a72020bd7962a, processorArchitecture=MSIL">
      <HintPath>..\packages\MaterialDesignThemes.5.2.1\lib\net462\MaterialDesignThemes.Wpf.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
      <HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.Xaml.Behaviors, Version=1.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <HintPath>..\packages\Microsoft.Xaml.Behaviors.Wpf.1.1.39\lib\net45\Microsoft.Xaml.Behaviors.dll</HintPath>
    </Reference>
    <Reference Include="PresentationCore" />
    <Reference Include="PresentationFramework" />
    <Reference Include="System.Buffers, Version=4.0.4.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
      <HintPath>..\packages\System.Buffers.4.6.0\lib\net462\System.Buffers.dll</HintPath>
    </Reference>
    <Reference Include="System.ComponentModel.Annotations, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <HintPath>..\packages\System.ComponentModel.Annotations.5.0.0\lib\net461\System.ComponentModel.Annotations.dll</HintPath>
    </Reference>
    <Reference Include="System.ComponentModel.DataAnnotations" />
    <Reference Include="System.Drawing" />
    <Reference Include="System.Memory, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
      <HintPath>..\packages\System.Memory.4.6.0\lib\net462\System.Memory.dll</HintPath>
    </Reference>
    <Reference Include="System.Numerics" />
    <Reference Include="System.Numerics.Vectors, Version=4.1.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <HintPath>..\packages\System.Numerics.Vectors.4.6.0\lib\net462\System.Numerics.Vectors.dll</HintPath>
    </Reference>
    <Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.1.0\lib\net462\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
    </Reference>
    <Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
      <HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
    </Reference>
    <Reference Include="System.Windows.Forms" />
    <Reference Include="System.Xaml" />
    <Reference Include="WindowsBase" />
    <Reference Include="WindowsFormsIntegration" />
    <Reference Include="ZcCui">
      <HintPath>$(ZrxSdk2025)\inc\ZcCui.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="ZcWindows">
      <HintPath>$(ZrxSdk2025)\inc\ZcWindows.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="ZdWindows">
      <HintPath>$(ZrxSdk2025)\inc\ZdWindows.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="ZwDatabaseMgd">
      <HintPath>$(ZrxSdk2025)\inc\ZwDatabaseMgd.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="ZwDatabaseMgdBrep">
      <HintPath>$(ZrxSdk2025)\inc\ZwDatabaseMgdBrep.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="ZwManaged">
      <HintPath>$(ZrxSdk2025)\inc\ZwManaged.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Commands.cs" />
    <Compile Include="Converters\OptionToBooleanConverter.cs" />
    <Compile Include="PlugInApplication.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
    <Compile Include="ViewModel\WpfDemoViewModel.cs" />
    <Compile Include="Views\WpfDemo.xaml.cs">
      <DependentUpon>WpfDemo.xaml</DependentUpon>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <Folder Include="Controls\" />
    <Folder Include="Models\" />
  </ItemGroup>
  <ItemGroup>
    <Page Include="Styles\Styles.xaml">
      <SubType>Designer</SubType>
      <Generator>MSBuild:Compile</Generator>
    </Page>
    <Page Include="Views\WpfDemo.xaml">
      <SubType>Designer</SubType>
      <Generator>MSBuild:Compile</Generator>
    </Page>
  </ItemGroup>
  <ItemGroup>
    <None Include="app.config" />
    <None Include="packages.config" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <Import Project="..\packages\MaterialDesignThemes.5.2.1\build\MaterialDesignThemes.targets" Condition="Exists('..\packages\MaterialDesignThemes.5.2.1\build\MaterialDesignThemes.targets')" />
  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('..\packages\MaterialDesignThemes.5.2.1\build\MaterialDesignThemes.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MaterialDesignThemes.5.2.1\build\MaterialDesignThemes.targets'))" />
    <Error Condition="!Exists('..\packages\CommunityToolkit.Mvvm.8.4.0\build\CommunityToolkit.Mvvm.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CommunityToolkit.Mvvm.8.4.0\build\CommunityToolkit.Mvvm.targets'))" />
  </Target>
  <Import Project="..\packages\CommunityToolkit.Mvvm.8.4.0\build\CommunityToolkit.Mvvm.targets" Condition="Exists('..\packages\CommunityToolkit.Mvvm.8.4.0\build\CommunityToolkit.Mvvm.targets')" />
</Project>

Csharp

image-20250416092345724

模版参数

.Net封装ObjectARX自定义实体类型

参考Github ManagedCircle

使用ARX自带的向导

选择.NET mixed managed code support工程

将props中关于arx的删除

配置信息按照如下所示:

image-20250407193241272

image-20250407193257438

image-20250407193310752

image-20250407193323409

image-20250407193335187

关于主代码

image-20250407193517842

acrxEntryPoint.cpp

C++
//-----------------------------------------------------------------------------
//----- acrxEntryPoint.cpp
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"
#include "ZwSerialNoMgd.h"

//-----------------------------------------------------------------------------
#define szRDS _RXST("")
AC_DECLARE_EXTENSION_MODULE(MgdWrapperDLL) ;
static AcMgObjectFactoryBase** g_PEs = NULL;

//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CMgdWrapperApp : public AcRxArxApp {

public:
    CMgdWrapperApp() : AcRxArxApp() {}

    virtual AcRx::AppRetCode On_kInitAppMsg(void *pkt) {
        // TODO: Load dependencies here
        // Save critical data pointers before running the constructors (see afxdllx.h for details)
        AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
        pModuleState->m_pClassInit = pModuleState->m_classList;
        pModuleState->m_pFactoryInit = pModuleState->m_factoryList;
        pModuleState->m_classList.m_pHead = NULL;
        pModuleState->m_factoryList.m_pHead = NULL;

        MgdWrapperDLL.AttachInstance (_hdllInstance) ;
        InitAcUiDLL () ;

        // You *must* call On_kInitAppMsg here
        AcRx::AppRetCode retCode = AcRxArxApp::On_kInitAppMsg(pkt);

        // TODO: Add your initialization code here
        AcMgObjectFactoryBase* PEs[] =
        {
            new AcMgObjectFactory<ZDN::CustomWrapper::ZwSerialNoMgd, CZwSerialNo>(),
                    NULL
        };

        g_PEs = PEs;
        return (retCode);
    }

    virtual AcRx::AppRetCode On_kUnloadAppMsg(void *pkt) {
        // TODO: Add your code here
        int i = 0;
        while (g_PEs[i] != NULL)
            delete g_PEs[i++];
        // You *must* call On_kUnloadAppMsg here
        AcRx::AppRetCode retCode = AcRxArxApp::On_kUnloadAppMsg(pkt);

        // TODO: Unload dependencies here
        MgdWrapperDLL.DetachInstance () ;

        return (retCode);
    }

    virtual void RegisterServerComponents() {
    }
};

//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CMgdWrapperApp)

image-20250407193555427

stdafx.h

C++
#pragma once
#define MGDWRAPPER_MODULE

#pragma pack (push, 8)
#pragma warning(disable: 4786 4996)
//#pragma warning(disable: 4098)

//-----------------------------------------------------------------------------
#define STRICT

#include <sdkddkver.h>

//- ObjectARX and OMF headers needs this
#include <map>

//-----------------------------------------------------------------------------
#include <afxwin.h>             //- MFC core and standard components
#include <afxext.h>             //- MFC extensions
#include <afxcmn.h>             //- MFC support for Windows Common Controls

//-----------------------------------------------------------------------------
#using <mscorlib.dll>
#using <System.dll>

//#using <acdbmgd.dll>
//#using <acmgd.dll>
//#using <AcCui.dll>

#include <vcclr.h>
//-----------------------------------------------------------------------------
#include <afxwin.h>             //- MFC core and standard components
#include <afxext.h>             //- MFC extensions

#ifndef _AFX_NO_OLE_SUPPORT
#include <afxole.h>             //- MFC OLE classes
#include <afxodlgs.h>           //- MFC OLE dialog classes
#include <afxdisp.h>            //- MFC Automation classes
#endif // _AFX_NO_OLE_SUPPORT

#ifndef _AFX_NO_DB_SUPPORT
#include <afxdb.h>              //- MFC ODBC database classes
#endif // _AFX_NO_DB_SUPPORT

#ifndef _AFX_NO_DAO_SUPPORT
#include <afxdao.h>             //- MFC DAO database classes
#endif // _AFX_NO_DAO_SUPPORT

#include <afxdtctl.h>           //- MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>             //- MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
//-----------------------------------------------------------------------------
//- Include ObjectDBX/ObjectARX headers
//- Uncomment one of the following lines to bring a given library in your project.
//#define _BREP_SUPPORT_                    //- Support for the BRep API
//#define _HLR_SUPPORT_                     //- Support for the Hidden Line Removal API
//#define _AMODELER_SUPPORT_                //- Support for the AModeler API
//#define _ASE_SUPPORT_                         //- Support for the ASI/ASE API
//#define _RENDER_SUPPORT_                  //- Support for the AutoCAD Render API
//#define _ARX_CUSTOM_DRAG_N_DROP_  //- Support for the ObjectARX Drag'n Drop API
//#define _INC_LEAGACY_HEADERS_         //- Include legacy headers in this project
#include "arxHeaders.h"

#include <afxcview.h>
//-----------------------------------------------------------------------------
#include "DocData.h" //- Your document specific data class holder

//- Declare it as an extern here so that it becomes available in all modules
extern AcApDataManager<CDocData> DocVars ;

#pragma pack (pop)

image-20250407193816704

ZwSerialNoMgd.h

C++
#pragma once
#include <CZwSerialNo.h>
using namespace System ;
using namespace ZwSoft::ZwCAD::Geometry ;
using namespace  ZwSoft::ZwCAD::DatabaseServices ;
namespace ZDN
{
    namespace CustomWrapper
    {
        [ZwSoft::ZwCAD::Runtime::Wrapper("CZwSerialNo")] 
        public ref class ZwSerialNoMgd
            : public ZwSoft::ZwCAD::DatabaseServices::Entity 
        {
         public:
          //- Constructor
          ZwSerialNoMgd();

        internal:

          ZwSerialNoMgd(System::IntPtr unmanagedPointer, bool bAutoDelete);

          //- Returns the unmanaged ARX Object
          inline CZwSerialNo *GetImpObj() {
            return (static_cast<CZwSerialNo *>(UnmanagedObject.ToPointer()));
          }

         public:
          void SetInsertPt(ZwSoft::ZwCAD::Geometry::Point3d center);
          void setScale(ZwSoft::ZwCAD::Geometry::Scale3d newScale);
          void setDescription(String ^ strDescription);
          void setTag(String ^ strDescription);
          void setValue(String ^ strDescription);
          void setGaugename(String ^ strDescription);
          void setGaugecode(String ^ strDescription);

         /* void setRadius(double radius);
          void gc2AcString(System::String ^ s);*/
          void convertFromMgdObjectId(ZwSoft::ZwCAD::DatabaseServices::ObjectId mgdId);
        };
    }

} // namespace ZDN

image-20250407193859988

ZwSerialNoMgd.cpp

C++
#include "StdAfx.h"
#include "ZwSerialNoMgd.h"
#include <gcroot.h>
#include "zmgdinterop.h"

ZDN::CustomWrapper::ZwSerialNoMgd::ZwSerialNoMgd() :
    ZwSoft::ZwCAD::DatabaseServices::Entity((System::IntPtr) new CZwSerialNo(), true)
{}
ZDN::CustomWrapper::ZwSerialNoMgd::ZwSerialNoMgd(System::IntPtr unmanagedPointer, bool bAutoDelete) :
    ZwSoft::ZwCAD::DatabaseServices::Entity(unmanagedPointer, bAutoDelete)
{}
void ZDN::CustomWrapper::ZwSerialNoMgd::SetInsertPt(ZwSoft::ZwCAD::Geometry::Point3d center)
{
    AcGePoint3d _center = GETPOINT3D(center);

    GetImpObj()->SetInsertPt(_center);
}

void ZDN::CustomWrapper::ZwSerialNoMgd::setScale(ZwSoft::ZwCAD::Geometry::Scale3d newScale)
{
    AcGeScale3d _center = GETSCALE3D(newScale);

    GetImpObj()->setScale(_center);
}

void ZDN::CustomWrapper::ZwSerialNoMgd::setDescription(String ^ strDescription)
{
    GetImpObj()->setDescription((LPCTSTR)StringToCIF(strDescription));
}

void ZDN::CustomWrapper::ZwSerialNoMgd::setTag(String ^ strDescription)
{
    GetImpObj()->setTag((LPCTSTR)StringToCIF(strDescription));
}

void ZDN::CustomWrapper::ZwSerialNoMgd::setValue(String ^ strDescription)
{
    GetImpObj()->setValue((LPCTSTR)StringToCIF(strDescription));
}

void ZDN::CustomWrapper::ZwSerialNoMgd::setGaugename(String ^ strDescription)
{
    GetImpObj()->setGaugename((LPCTSTR)StringToCIF(strDescription));
}

void ZDN::CustomWrapper::ZwSerialNoMgd::setGaugecode(String ^ strDescription)
{
    GetImpObj()->setGaugecode((LPCTSTR)StringToCIF(strDescription));
}

void ZDN::CustomWrapper::ZwSerialNoMgd::convertFromMgdObjectId(
    ZwSoft::ZwCAD::DatabaseServices::ObjectId mgdId)
{
    System::String ^ hStr = mgdId.Handle.ToString();
    UInt64     hInt = System::Convert::ToInt64(hStr, 16);
    AcDbHandle handle(hInt);

    AcDbObjectId      objId;
    Acad::ErrorStatus es =
        acdbHostApplicationServices()->workingDatabase()->getAcDbObjectId(objId, false, handle);
    if (es == Acad::eOk)
    {
        acutPrintf(ACRX_T("\nObjectClass from Id : %s"), objId.objectClass()->name());
    }
}

image-20250407193924510

.net中调用

C#
 [CommandMethod("TestNo")]
 public void TestNo()
 {
     Document doc = Application.DocumentManager.MdiActiveDocument;
     Database db = doc.Database;
     Editor ed = doc.Editor;

     PromptEntityOptions peo = new PromptEntityOptions("\nSelect custom object: ");
     peo.SetRejectMessage("\nInvalid selection...");
     peo.AddAllowedClass(typeof(ZwSerialNoMgd), true);

     PromptEntityResult per = ed.GetEntity(peo);

     if (per.Status != PromptStatus.OK)
         return;

     using (Transaction Tx = db.TransactionManager.StartTransaction())
     {
         ZwSerialNoMgd entity = Tx.GetObject(per.ObjectId, OpenMode.ForWrite)
             as ZwSerialNoMgd;

         entity.ColorIndex = 1;

         Tx.Commit();
     }
 }

启动ZW机械CAD

C#
private ZWCAD.ZcadApplication m_cadApp;
private ZwmToolKitLib.ZwmApp m_objZwmApp;
private ZwmToolKitLib.ZwmDb m_objZwmDb;
private ZwmToolKitLib.Title m_objZwmTitle;
private ZwmToolKitLib.Bom m_objZwmBom;
private ZwmToolKitLib.Frame m_objZwmFrame;

try
{
    //取得一个正在运行的ZWCAD实例 
    m_cadApp = (ZWCAD.ZcadApplication)Marshal.GetActiveObject("ZWCAD.Application.2025");

}//end of try 
catch
{
    try
    {
        //建立一个新的AUTOCAD实例,并标识已经建立成功。 
        //        m_cadApp = new AutoCAD.AcadApplication();
        //m_cadApp = new ZWCAD.ZcadApplication();
        Type comType = Type.GetTypeFromProgID("ZWCAD.Application.2025");
        object comObj = Activator.CreateInstance(comType);
        m_cadApp = (ZWCAD.ZcadApplication)comObj;
        m_cadApp.Visible = true;
    }
    catch
    {
        throw new Exception("无法起动CAD应用程序,确认已经安装");
    }
}//end of catch 
 if (m_cadApp != null && m_objZwmApp == null)
 {
     m_objZwmApp = m_cadApp.GetInterfaceObject("ZwmToolKit.ZwmApp");
     m_objZwmApp.GetDb(out m_objZwmDb);
     if (m_objZwmApp != null)
     {
         String strCadPath = "";
         String strZwmPath = "";
         String strVersion = "";

         m_objZwmApp.GetCadPath(out strCadPath);
         m_objZwmApp.GetZwmPath(out strZwmPath);
         m_objZwmApp.GetVersion(out strVersion);

         textBox_cad_path.Text = strCadPath;
         textBox_zwm_path.Text = strZwmPath;
         textBox_version.Text = strVersion;
     }
     else
         MessageBox.Show("创建 ZwmToolKit.ZwmApp 失败!请检查机械软件启动是否正常");
 }

image-20250604093310804

OverRule相关demo

image-20241105105959744

参考ADNblogdemo

Locking an Entity in AutoCAD using ObjectARX

CGripOverrule.h

C++
#pragma once
#include "dbentityoverrule.h"
class CGripOverrule : public AcDbGripOverrule
{
public:
    static CGripOverrule *_pTheOverrule;

    ACRX_DECLARE_MEMBERS(CGripOverrule);

    bool isApplicable(const AcRxObject *pOverruledSubject) const
    {

        return true;
    }

    // Add the overrule.

    // Take care about calling "CGripOverrule::rxInit();"

    // in "On_kInitAppMsg" of the arx that uses this overrule.

    static void CGripOverrule::AddOverrule()
    {
        if (_pTheOverrule != NULL)

            return;
        _pTheOverrule = new CGripOverrule();
        AcRxOverrule::addOverrule(AcDbCircle::desc(), _pTheOverrule, true);
        CGripOverrule::setIsOverruling(true);
    }

    static void CGripOverrule::RemoveOverrule()
    {
        if (_pTheOverrule == NULL)
            return;

        CGripOverrule::setIsOverruling(false);
        AcRxOverrule::removeOverrule(AcDbCircle::desc(), _pTheOverrule);
        delete _pTheOverrule;
        _pTheOverrule = NULL;
    }

    Acad::ErrorStatus CGripOverrule::getGripPoints(const AcDbEntity *pSubject,
                                                   AcGePoint3dArray &gripPoints,
                                                   AcDbIntArray &osnapModes,
                                                   AcDbIntArray &geomIds)
    {
        AcDbCircle *pCircle = AcDbCircle::cast(pSubject);
        if (pCircle != NULL)
        { // Remove the grip points, for a circle

            gripPoints.removeAll();
            return Acad::eNotApplicable;
        }

        return AcDbGripOverrule::getGripPoints(pSubject, gripPoints, osnapModes, geomIds);
    }

    Acad::ErrorStatus CGripOverrule::getGripPoints(
        const AcDbEntity *pSubject,
        AcDbGripDataPtrArray &grips,
        const double curViewUnitSize,
        const int gripSize,
        const AcGeVector3d &curViewDir,
        const int bitflags)
    {
        AcDbCircle *pCircle = AcDbCircle::cast(pSubject);
        if (pCircle != NULL)
        { // Remove the grip points, for a circle
            grips.removeAll();
            return Acad::eNotApplicable;
        }

        return AcDbGripOverrule::getGripPoints(
            pSubject,
            grips,
            curViewUnitSize,
            gripSize,
            curViewDir,
            bitflags);
    }
};

CGripOverrule *CGripOverrule::_pTheOverrule = NULL;
ACRX_NO_CONS_DEFINE_MEMBERS(CGripOverrule, AcDbGripOverrule);

CTransformOverrule.h

C++
#pragma once
#include "dbentityoverrule.h"
class CTransformOverrule :
    public AcDbTransformOverrule
{
public:
    static CTransformOverrule* _pTheOverrule;
    ACRX_DECLARE_MEMBERS(CTransformOverrule);
    bool isApplicable(const AcRxObject* pOverruledSubject) const
    {
        return true;
    }
    Acad::ErrorStatus transformBy(
        AcDbEntity* pSubject,
        const AcGeMatrix3d& xform)
    {
        if (pSubject->isA() != AcDbCircle::desc())
            return Acad::eOk;
        AcDbCircle* pCircle = AcDbCircle::cast(pSubject);
        if (pCircle != NULL)
            return Acad::eNotApplicable;
        return AcDbTransformOverrule::transformBy(pSubject, xform);
    }
    // Take care about calling "CTransformOverrule::rxInit();"
    // in "On_kInitAppMsg" of the arx that uses this overrule.
    static void CTransformOverrule::AddOverrule()
    {
        if (_pTheOverrule != NULL)
            return;
        _pTheOverrule = new CTransformOverrule();
        AcRxOverrule::addOverrule(
            AcDbCircle::desc(),
            _pTheOverrule,
            true
        );
        CTransformOverrule::setIsOverruling(true);
    }
    static void CTransformOverrule::RemoveOverrule()
    {
        if (_pTheOverrule == NULL)
            return;
        CTransformOverrule::setIsOverruling(false);
        AcRxOverrule::removeOverrule(
            AcDbCircle::desc(),
            _pTheOverrule);
        delete _pTheOverrule;
        _pTheOverrule = NULL;
    }
};
CTransformOverrule* CTransformOverrule::_pTheOverrule = NULL;
ACRX_NO_CONS_DEFINE_MEMBERS(CTransformOverrule, AcDbTransformOverrule);

On_kInitAppMsg

C++
1
2
3
4
5
6
7
8
virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt)
{
    AcRx::AppRetCode retCode = AcRxArxApp::On_kInitAppMsg (pkt) ;
    CGripOverrule::rxInit();
    CTransformOverrule::rxInit();
    acrxBuildClassHierarchy();
    return (retCode) ;
}

AddCommand

C++
// Command to enable overruling
static void asdkOverrule_Start(void)
{
    CTransformOverrule::AddOverrule();
    CGripOverrule::AddOverrule();
}
// Command to disable overruling
static void asdkOverrule_Stop(void)
{
    CTransformOverrule::RemoveOverrule();
    CGripOverrule::RemoveOverrule();
}

增加CDrawCircleOverRule

CDrawCircleOverRule.h

C++
1
2
3
4
5
6
7
8
9
class CDrawCircleOverRule: public AcGiDrawableOverrule
{
public:
    CDrawCircleOverRule();
    ~CDrawCircleOverRule();
    //ACRX_DECLARE_MEMBERS(CDrawCircleOverRule);
    virtual bool isApplicable(const AcRxObject* pOverruledSubject)  const;
    virtual Adesk::Boolean  worldDraw(AcGiDrawable* pSubject, AcGiWorldDraw * wd);
};

CDrawCircleOverRule.cpp

C++
#include "stdafx.h"
#include "CDrawCircleOverRule.h"
CDrawCircleOverRule::CDrawCircleOverRule()
{
}

CDrawCircleOverRule::~CDrawCircleOverRule()
{
}

bool CDrawCircleOverRule::isApplicable(const AcRxObject* pOverruledSubject)  const
{
    return true;
}

Adesk::Boolean CDrawCircleOverRule::worldDraw(AcGiDrawable* pSubject, AcGiWorldDraw * wd)
{
    AcDbCircle* pCircle = AcDbCircle::cast(pSubject);
    if (pCircle != nullptr)
    {
        AcGePoint3d cenPt = pCircle->center();
        double dRadius = pCircle->radius();

        AcDbLine pline;
        AcGePoint3d startPt, endPt;
        acutPolar(asDblArray(cenPt), PI, 1.5*dRadius, asDblArray(startPt));
        acutPolar(asDblArray(cenPt), 0, 1.5*dRadius, asDblArray(endPt));

        wd->geometry().circle(cenPt, dRadius, AcGeVector3d::kZAxis);
        wd->subEntityTraits().setColor(1);
        pline.setStartPoint(startPt);
        pline.setEndPoint(endPt);
        pline.worldDraw(wd);

        acutPolar(asDblArray(cenPt), PI/2, 1.5*dRadius, asDblArray(startPt));
        acutPolar(asDblArray(cenPt), 3*PI/2, 1.5*dRadius, asDblArray(endPt));
        pline.setStartPoint(startPt);
        pline.setEndPoint(endPt);
        pline.worldDraw(wd);

    }

    return Adesk::kTrue;
}

AddCommand

C++
CDrawCircleOverRule*  theOverrule = nullptr;

static void MyGroupStart() {
    // Put your command code here
    CTransformOverrule::AddOverrule();
    CGripOverrule::AddOverrule();
    if (theOverrule == nullptr)
    {
        theOverrule = new CDrawCircleOverRule();
        AcRxOverrule::addOverrule(AcDbCircle::desc(), theOverrule, true);
    }
    CDrawCircleOverRule::setIsOverruling(true);
}
static void MyGroupStop() {
    // Put your command code here
    CTransformOverrule::RemoveOverrule();
    CGripOverrule::RemoveOverrule();
    if (theOverrule != nullptr)
    {
        AcRxOverrule::removeOverrule(AcDbCircle::desc(), theOverrule);
        theOverrule = nullptr;
    }
}

CAD.net处理Ribbon界面

image-20241025111332961

image-20241025112036318

C#
//调用资源字典
ResourceDictionary resourceDictionary = (ResourceDictionary)System.Windows.Application.LoadComponent(new Uri("/RibbonDemo;component/RibbonDictionary.xaml", UriKind.Relative));

纯代码的方式加载ribbon界面

AddRibbon

C#
[CommandMethod("AddRibbon")]
public void AddRibbon()
{
    RibbonControl control = ComponentManager.Ribbon;//获取Ribbon界面
    RibbonTab tab = new RibbonTab();//创建选项卡
    tab.Title = "Csharp Ribbon";//设置选项卡的标题
    tab.Id = "ID_TabMyRibbon";//设置选项卡的AutoCAD标识符
    control.Tabs.Add(tab);//将选项卡添加到Ribbon界面中
    addPanel(tab);//为选项卡添加Ribbon面板
    tab.IsActive = true;//设置当前活动选项卡
}
private void addPanel(RibbonTab tab)
{
    //创建RibbonPanelSource对象,用来加入Ribbon元素(如按钮)
    RibbonPanelSource sourcePanel = new RibbonPanelSource();
    sourcePanel.Title = "演示";//Ribbon面板的标题
    RibbonPanel ribPanel = new RibbonPanel();//创建Ribbon面板
    ribPanel.Source = sourcePanel;//设置Ribbon面板的内容
    tab.Panels.Add(ribPanel);//将Ribbon面板添加到选项卡中
    RibbonButton buttonLine = new RibbonButton();//创建按钮
    buttonLine.Name = "直线";//按钮名称 
    buttonLine.Text = "直线";//按钮显示的文字
    buttonLine.ShowImage = true;//按钮显示图像
    buttonLine.ShowText = true;//按钮显示文字
    //设置按钮的大小图像
    buttonLine.Image = resourceDictionary["LineImage"] as BitmapImage;
    buttonLine.LargeImage = resourceDictionary["LineImage"] as BitmapImage;
    buttonLine.Size = RibbonItemSize.Large;//以大图像的形式表示按钮
    //按钮文字和图像的方向为竖直
    buttonLine.Orientation = System.Windows.Controls.Orientation.Vertical;
    buttonLine.CommandParameter = "Line ";//设置按钮的命令参数
    //设置按钮的命令处理程序
    buttonLine.CommandHandler = new RibbonCommandHandler();
    RibbonToolTip toolTipLine = new RibbonToolTip();//创建按钮提示
    toolTipLine.Command = "Line";//设置提示中显示的命令名
    toolTipLine.Title = "直线";//设置提示的标题
    toolTipLine.Content = "创建直线段";//设置提示的内容
    //设置提示的附加内容
    toolTipLine.ExpandedContent = "使用Line命令,可以创建一系列连续的直线段。每条线段都是可以单独进行编辑的直线对象。";
    //设置在提示附加内容下显示的图像
    toolTipLine.ExpandedImage = resourceDictionary["TooltipLineImage"] as BitmapImage;
    buttonLine.ToolTip = toolTipLine;//设置“直线”按钮的提示
    //创建“单行文字”按钮
    RibbonButton buttonText = new RibbonButton();
    buttonText.Name = "单行文字";
    buttonText.Text = "文字";
    buttonText.ShowImage = true;
    buttonText.LargeImage = resourceDictionary["TextImage"] as BitmapImage;
    buttonText.Image = resourceDictionary["TextImage"] as BitmapImage;
    buttonText.Size = RibbonItemSize.Large;
    buttonText.CommandParameter = "Text ";
    buttonText.CommandHandler = new RibbonCommandHandler();
    //创建“多行文字”按钮
    RibbonButton buttonMText = new RibbonButton();
    buttonMText.Name = "多行文字";
    buttonMText.Text = "文字";
    buttonMText.ShowImage = true;
    buttonMText.LargeImage = resourceDictionary["MTextImage"] as BitmapImage;
    buttonMText.Image = resourceDictionary["MTextImage"] as BitmapImage;
    buttonMText.Size = RibbonItemSize.Large;
    buttonMText.CommandParameter = "MText ";
    buttonMText.CommandHandler = new RibbonCommandHandler();
    //创建组合下拉按钮
    RibbonSplitButton splitButton = new RibbonSplitButton();
    splitButton.Text = "文字";
    splitButton.ShowText = true;
    splitButton.ShowImage = true;
    splitButton.Size = RibbonItemSize.Large;
    splitButton.Orientation = System.Windows.Controls.Orientation.Vertical;
    splitButton.Items.Add(buttonText);//添加“单行文本”按钮到组合下拉按钮
    splitButton.Items.Add(buttonMText);//添加“多行文本”按钮到组合下拉按钮
    //创建行面板
    RibbonRowPanel row1 = new RibbonRowPanel();
    //创建“移动”按钮
    RibbonButton buttonMove = new RibbonButton
    {
        Name = "移动",
        Text = "移动",
        ShowImage = true,
        ShowText = true,
        Image = resourceDictionary["MoveImage"] as BitmapImage,
        Size = RibbonItemSize.Standard,
        CommandParameter = "Move ",
        CommandHandler = new RibbonCommandHandler(),
    };
    row1.Items.Add(buttonMove);//添加“移动”按钮到行面板
    row1.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列
    //创建“复制”按钮
    RibbonButton buttonCopy = new RibbonButton
    {
        Name = "复制",
        Text = "复制",
        ShowImage = true,
        ShowText = true,
        Image = resourceDictionary["CopyImage"] as BitmapImage,
        Size = RibbonItemSize.Standard,
        CommandParameter = "Copy ",
        CommandHandler = new RibbonCommandHandler(),
    };
    row1.Items.Add(buttonCopy);
    row1.Items.Add(new RibbonRowBreak());
    //创建“拉伸”按钮
    RibbonButton buttonStretch = new RibbonButton
    {
        Name = "拉伸",
        Text = "拉伸",
        ShowImage = true,
        ShowText = true,
        Image = resourceDictionary["StretchImage"] as BitmapImage,
        Size = RibbonItemSize.Standard,
        CommandParameter = "Stretch ",
        CommandHandler = new RibbonCommandHandler()
    };
    row1.Items.Add(buttonStretch);
    row1.Items.Add(new RibbonRowBreak());
    //将“直线”按钮、组合下拉按钮、行面板添加到"演示"面板中
    sourcePanel.Items.Add(buttonLine);
    sourcePanel.Items.Add(splitButton);
    sourcePanel.Items.Add(row1);
}
public class RibbonCommandHandler : System.Windows.Input.ICommand
{
    public bool CanExecute(object parameter)
    {
        return true;//确定此命令可以在其当前状态下执行
    }
    //当出现影响是否应执行该命令的更改时发生
    public event EventHandler CanExecuteChanged;

    public void Execute(object parameter)
    {
        //获取发出命令的按钮对象
        RibbonButton button = parameter as RibbonButton;
        //如果发出命令的不是按钮或按钮未定义命令参数,则返回
        if (button == null || button.CommandParameter == null) return;
        //根据按钮的命令参数,执行对应的AutoCAD命令
        Document doc = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
        doc.SendStringToExecute(button.CommandParameter.ToString(), true, false, true);
    }
}

通过xaml方式加载

image-20241025111646650

xaml文件

Text Only
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:adw="clr-namespace:ZwSoft.Windows;assembly=ZdWindows">
    <BitmapImage x:Key="CopyImage" UriSource="Images/Copy.ico" />
    <!--    -->
    <BitmapImage x:Key="LineImage" UriSource="Images/Line.ico" />
    <BitmapImage x:Key="MoveImage" UriSource="Images/Move.ico" />
    <BitmapImage x:Key="MTextImage" UriSource="Images/MText.ico" />
    <BitmapImage x:Key="StretchImage" UriSource="Images/Stretch.ico" />
    <BitmapImage x:Key="TextImage" UriSource="Images/Text.ico" />
    <BitmapImage x:Key="TooltipLineImage" UriSource="Images/tooltip_line.gif" />
    <adw:RibbonTab
        x:Key="TabXaml"
        Title="XAML"
        Id="TabXaml_1">
        <adw:RibbonPanel>
            <adw:RibbonPanelSource Title="演示">
                <adw:RibbonButton
                    Name="直线"
                    CommandParameter="Line "
                    Id="ID_MyLine"
                    Image="{StaticResource LineImage}"
                    LargeImage="{StaticResource LineImage}"
                    Orientation="Vertical"
                    ShowImage="True"
                    ShowText="True"
                    Size="Large"
                    Text="直线">
                    <adw:RibbonButton.ToolTip>
                        <adw:RibbonToolTip
                            Title="直线"
                            Command="Line"
                            Content="创建直线段"
                            ExpandedContent="使用Line命令,可以创建一系列连续的直线段。每条线段都是可以单独进行编辑的直线对象。"
                            ExpandedImage="{StaticResource TooltipLineImage}" />
                    </adw:RibbonButton.ToolTip>
                </adw:RibbonButton>
                <adw:RibbonSplitButton
                    IsSplit="True"
                    Orientation="Vertical"
                    ShowImage="True"
                    ShowText="True"
                    Size="Large"
                    Text="文字">
                    <adw:RibbonButton
                        Name="单行文字"
                        CommandParameter="Text "
                        Id="ID_MyText"
                        Image="{StaticResource TextImage}"
                        LargeImage="{StaticResource TextImage}"
                        ShowImage="True"
                        ShowText="False"
                        Size="Large"
                        Text="文字" />
                    <adw:RibbonButton
                        Name="多行文字"
                        CommandParameter="MText "
                        Id="ID_MyMText"
                        Image="{StaticResource MTextImage}"
                        LargeImage="{StaticResource MTextImage}"
                        ShowImage="True"
                        ShowText="False"
                        Size="Large"
                        Text="文字" />
                </adw:RibbonSplitButton>
                <adw:RibbonRowPanel>
                    <adw:RibbonButton
                        Name="移动"
                        CommandParameter="Move "
                        Id="ID_MyMove"
                        Image="{StaticResource MoveImage}"
                        LargeImage="{StaticResource MoveImage}"
                        ShowImage="True"
                        ShowText="True"
                        Size="Standard"
                        Text="移动" />
                    <adw:RibbonRowBreak />
                    <adw:RibbonButton
                        Name="复制"
                        CommandParameter="Copy "
                        Id="ID_MyCopy"
                        Image="{StaticResource CopyImage}"
                        LargeImage="{StaticResource CopyImage}"
                        ShowImage="True"
                        ShowText="True"
                        Size="Standard"
                        Text="复制" />
                    <adw:RibbonRowBreak />
                    <adw:RibbonButton
                        Name="拉伸"
                        CommandParameter="Stretch "
                        Id="ID_MyStretch"
                        Image="{StaticResource StretchImage}"
                        LargeImage="{StaticResource StretchImage}"
                        ShowImage="True"
                        ShowText="True"
                        Size="Standard"
                        Text="拉伸" />
                    <adw:RibbonRowBreak />
                </adw:RibbonRowPanel>
            </adw:RibbonPanelSource>
        </adw:RibbonPanel>
    </adw:RibbonTab>
</ResourceDictionary>

AddRibbonXaml

C#
[CommandMethod("AddRibbonXAML")]
public void AddRibbonXAML()
{
    //获取由XAML定义的选项卡
    RibbonTab tab = resourceDictionary["TabXaml"] as RibbonTab;
    //查找Ribbon按钮并添加命令事件
    RibbonItemCollection items = tab.Panels[0].Source.Items;
    foreach (RibbonItem item in items)
    {
        if (item is RibbonButton)
            ((RibbonButton)item).CommandHandler = new RibbonCommandHandler();
        else if (item is RibbonRowPanel)
        {
            RibbonRowPanel row = (RibbonRowPanel)item;
            foreach (RibbonItem rowItem in row.Items)
            {
                if (rowItem is RibbonButton)
                    ((RibbonButton)rowItem).CommandHandler = new RibbonCommandHandler();
            }
        }
    }
    RibbonControl ribbonControl = ComponentManager.Ribbon;//获取Ribbon界面
    ribbonControl.Tabs.Add(tab);//将选项卡添加到Ribbon界面中
    ribbonControl.ActiveTab = tab;//设置当前活动选项卡
}

完整代码

Style样式:全局样式说明和资源字典的使用

image-20241021184738550

结果如下所示

image-20241021184756790

增加样式字典方式如下所示:

image-20241021184556692

ButtonStyle.xaml

C#
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style TargetType="Button">
        <Setter Property="Background" Value="WhiteSmoke" />
        <Setter Property="Foreground" Value="Black" />
        <Setter Property="FontSize" Value="20" />
        <Setter Property="Margin" Value="10,20" />
    </Style>
    <Style
        x:Key="LoginStyle"
        BasedOn="{StaticResource {x:Type Button}}"
        TargetType="Button">
        <Setter Property="Background" Value="Green" />
    </Style>
    <Style
        x:Key="QuitStyle"
        BasedOn="{StaticResource {x:Type Button}}"
        TargetType="Button">
        <Setter Property="Background" Value="Red" />
    </Style>

    <Style x:Key="MyButtonStyle" TargetType="Button">
        <Setter Property="Background" Value="LightBlue" />
        <Setter Property="Foreground" Value="Black" />
        <Setter Property="FontSize" Value="50" />
        <Setter Property="Margin" Value="10,20" />
    </Style>

    <Style
        x:Key="MyButtonStyle2"
        BasedOn="{StaticResource MyButtonStyle}"
        TargetType="Button">
        <Setter Property="Background" Value="LightGray" />
    </Style>

    <Style
        x:Key="MyButtonStyle3"
        BasedOn="{StaticResource MyButtonStyle}"
        TargetType="Button">
        <Setter Property="FontSize" Value="30" />
        <Setter Property="Background" Value="DarkKhaki" />
    </Style>
</ResourceDictionary>

App.xaml

C#
<Application
    x:Class="ButtonStyle.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:ButtonStyle"
    StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="ButtonStyle.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

MainWindow.xaml

C#
<Window
    x:Class="ButtonStyle.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:ButtonStyle"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="MainWindow"
    Width="800"
    Height="450"
    mc:Ignorable="d">
    <Grid>
        <StackPanel>
            <Button Content="登录" Style="{StaticResource LoginStyle}" />
            <Button Content="注册" Style="{StaticResource QuitStyle}" />
            <Button Content="退出" Style="{StaticResource MyButtonStyle2}" />
            <Button Content="保存" Style="{StaticResource MyButtonStyle3}" />
        </StackPanel>
    </Grid>
</Window>

wpf中读取dwg显示图片

Csharp预览DWG文件方法(一)直接读取文件结构

要在WPF中读取DWG文件并将其转换为Bitmap,可以使用一些第三方库来解析DWG文件,然后将其内容绘制到Bitmap上。以下是一个基本的步骤概述:

  1. 使用第三方库解析DWG文件
  2. 例如,您可以使用Teigha或Aspose.CAD等库来读取DWG文件。
  3. 将DWG内容绘制到Bitmap
  4. 使用解析库提供的绘图功能,将DWG文件的内容绘制到Bitmap对象上。
  5. 将Bitmap转换为WPF中的ImageSource
  6. 使用System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap方法将Bitmap转换为ImageSource,以便在WPF中显示。

以下是一个示例代码,展示了如何将Bitmap转换为ImageSource:

用如下方式使用,有部分图纸显示有问题

ImageSource img = BitmapToImageSource(ShowDWG(128, 128, file.FullName))

C#
using System; using System.Drawing; 
using System.Windows; 
using System.Windows.Media; 
using System.Windows.Media.Imaging;
using System.Windows.Interop; 

 struct BITMAPFILEHEADER
        {
            public short bfType;
            public int bfSize;
            public short bfReserved1;
            public short bfReserved2;
            public int bfOffBits;
        }
        public static System.Drawing.Image GetDwgImage(string FileName)
        {
            if (!(File.Exists(FileName)))
            {
                throw new FileNotFoundException("文件没有被找到");
            }

            FileStream DwgF = null;   //文件流
            int PosSentinel;   //文件描述块的位置
            BinaryReader br = null;   //读取二进制文件
            int TypePreview;   //缩略图格式
            int PosBMP;    //缩略图位置 
            int LenBMP;    //缩略图大小
            short biBitCount; //缩略图比特深度 
            BITMAPFILEHEADER biH; //BMP文件头,DWG文件中不包含位图文件头,要自行加上去
            byte[] BMPInfo;    //包含在DWG文件中的BMP文件体
            MemoryStream BMPF = new MemoryStream(); //保存位图的内存文件流
            BinaryWriter bmpr = new BinaryWriter(BMPF); //写二进制文件类
            System.Drawing.Image myImg = null;
            try
            {

                DwgF = new FileStream(FileName, FileMode.Open, FileAccess.Read); //文件流

                br = new BinaryReader(DwgF);
                DwgF.Seek(13, SeekOrigin.Begin); //从第十三字节开始读取
                PosSentinel = br.ReadInt32();   //第13到17字节指示缩略图描述块的位置
                DwgF.Seek(PosSentinel + 30, SeekOrigin.Begin);   //将指针移到缩略图描述块的第31字节
                TypePreview = br.ReadByte();   //第31字节为缩略图格式信息,2 为BMP格式,3为WMF格式
                if (TypePreview == 1)
                {
                }
                else if (TypePreview == 2 || TypePreview == 3)
                {
                    PosBMP = br.ReadInt32(); //DWG文件保存的位图所在位置
                    LenBMP = br.ReadInt32(); //位图的大小
                    DwgF.Seek(PosBMP + 14, SeekOrigin.Begin); //移动指针到位图块
                    biBitCount = br.ReadInt16(); //读取比特深度
                    DwgF.Seek(PosBMP, SeekOrigin.Begin); //从位图块开始处读取全部位图内容备用
                    BMPInfo = br.ReadBytes(LenBMP); //不包含文件头的位图信息
                    br.Close();
                    DwgF.Close();
                    biH.bfType = 19778; //建立位图文件头
                    if (biBitCount < 9)
                    {
                        biH.bfSize = 54 + 4 * (int)(Math.Pow(2, biBitCount)) + LenBMP;
                    }
                    else
                    {
                        biH.bfSize = 54 + LenBMP;
                    }
                    biH.bfReserved1 = 0; //保留字节
                    biH.bfReserved2 = 0; //保留字节
                    biH.bfOffBits = 14 + 40 + 1024; //图像数据偏移
                                                    //以下开始写入位图文件头
                    bmpr.Write(biH.bfType); //文件类型
                    bmpr.Write(biH.bfSize);   //文件大小
                    bmpr.Write(biH.bfReserved1); //0
                    bmpr.Write(biH.bfReserved2); //0
                    bmpr.Write(biH.bfOffBits); //图像数据偏移
                    bmpr.Write(BMPInfo); //写入位图
                    BMPF.Seek(0, SeekOrigin.Begin); //指针移到文件开始处 
                    myImg = System.Drawing.Image.FromStream(BMPF); //创建位图文件对象                    
                    bmpr.Close();
                    BMPF.Close();
                }
                return myImg;
            }
            catch (EndOfStreamException)
            {
                throw new EndOfStreamException("文件不是标准的DWG格式文件,无法预览!");
            }
            catch (IOException ex)
            {
                if (ex.Message == "试图将文件指针移到文件开头之前。/r/n")
                {
                    throw new IOException("文件不是标准的DWG格式文件,无法预览!");
                }
                else if (ex.Message == "文件“" + FileName + "”正由另一进程使用,因此该进程无法访问该文件。")
                {
                    //复制文件,继续预览
                    //File.Copy(FileName, System.Windows.Forms.Application.StartupPath + @"/linshi.dwg", true);
                    //System.Drawing.Image image = GetDwgImage(Application.StartupPath + @"/linshi.dwg");
                    //File.Delete(Application.StartupPath + @"/linshi.dwg");
                    //return image;
                    throw new IOException("文件“" + FileName + "”正由另一进程使用,因此该进程无法访问该文件。");
                }
                else
                {
                    throw new Exception(ex.Message);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (DwgF != null)
                {
                    DwgF.Close();
                }
                if (br != null)
                {
                    br.Close();
                }
                bmpr.Close();
                BMPF.Close();

            }
        }



        ///读取出来的背景色为白色,效果比较差,很多颜色显示不出来,当时认为显示DWG文件出错误了,问了些高手,(呵呵,别人告诉自己本身取出的就是白色背景,需要自己改变背景色,在此鄙视一下自己)所以继续用C#操作返回的IMAGE对象,改变背景色
        ///<summary>
        ///显示DWG文件
        ///</summary>
        ///<param name="Pwidth">要显示的宽度</param>
        ///<param name="PHeight">要显示的高度</param>
        ///<returns></returns>
        public static System.Drawing.Image ShowDWG(int Pwidth, int PHeight, string FilePath)
        {
            System.Drawing.Image image = GetDwgImage(FilePath);
            Bitmap bitmap = new Bitmap(image);
            int Height = bitmap.Height;
            int Width = bitmap.Width;
            Bitmap newbitmap = new Bitmap(Width, Height);
            Bitmap oldbitmap = (Bitmap)bitmap;
            System.Drawing.Color pixel;
            for (int x = 1; x < Width; x++)
            {
                for (int y = 1; y < Height; y++)
                {

                    pixel = oldbitmap.GetPixel(x, y);
                    int r = pixel.R, g = pixel.G, b = pixel.B;
                    if (pixel.Name == "ffffffff" || pixel.Name == "ff000000")
                    {
                        r = 255 - pixel.R;
                        g = 255 - pixel.G;
                        b = 255 - pixel.B;
                    }

                    newbitmap.SetPixel(x, y, Color.FromArgb(r, g, b));
                }
            }
            Bitmap bt = new Bitmap(newbitmap, Pwidth, PHeight);

            return newbitmap;
        }
        /// <summary>
        /// Bitmap转ImageSource
        /// </summary>
        /// <param name="hObject"></param>
        /// <returns></returns>
        [DllImport("gdi32.dll", SetLastError = true)]
        private static extern bool DeleteObject(IntPtr hObject);
        public static ImageSource ToImageSource( Bitmap bitmap)
        {
            IntPtr hBitmap = bitmap.GetHbitmap();
            ImageSource wpfBitmap = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
            // 记得要进行内存释放。否则会有内存不足的报错。
            if (!DeleteObject(hBitmap))
            {
                throw new Win32Exception();
            }
            return wpfBitmap;
        }

        public static ImageSource BitmapToImageSource(System.Drawing.Image processImage)
        {
            Bitmap bmp = new Bitmap(processImage);
            IntPtr hBitmap = bmp.GetHbitmap();
            ImageSource wpfBitmap = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
            return wpfBitmap;
        }

可以直接使用Database.ThumbnailBitmap接口来处理

C#
 [System.Runtime.InteropServices.DllImport("gdi32.dll", SetLastError = true)]
        private static extern bool DeleteObject(IntPtr hObject);
        public static ImageSource ToImageSource(System.Drawing.Bitmap bitmap)
        {
            IntPtr hBitmap = bitmap.GetHbitmap();
            ImageSource wpfBitmap = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
            // 记得要进行内存释放。否则会有内存不足的报错。
            if (!DeleteObject(hBitmap))
            {
                throw new Win32Exception();
            }
            return wpfBitmap;
        }
        public static System.Drawing.Bitmap GetDwgImage(string fileName)
        {
            System.Drawing.Bitmap outBM = null;
            ZwSoft.ZwCAD.DatabaseServices.Database sourceDb = new ZwSoft.ZwCAD.DatabaseServices.Database(false, true);
            try
            {
                //把DWG文件读入到一个临时的数据库中
                if (File.Exists(fileName))
                {
                    sourceDb.ReadDwgFile(fileName, FileShare.Read, false, String.Empty);
                    outBM = sourceDb.ThumbnailBitmap;
                }
            }
            catch (ZwSoft.ZwCAD.Runtime.Exception ex)
            {
                ZwSoft.ZwCAD.ApplicationServices.Application.ShowAlertDialog("复制错误: " + ex.Message);
            }
            //操作完成,销毁源数据库
            sourceDb.Dispose();
            return outBM;
        }

        ///读取出来的背景色为白色,效果比较差,很多颜色显示不出来,当时认为显示DWG文件出错误了,问了些高手,(呵呵,别人告诉自己本身取出的就是白色背景,需要自己改变背景色,在此鄙视一下自己)所以继续用C#操作返回的IMAGE对象,改变背景色
        ///<summary>
        ///显示DWG文件
        ///</summary>
        ///<param name="Pwidth">要显示的宽度</param>
        ///<param name="PHeight">要显示的高度</param>
        ///<returns></returns>
        public static System.Drawing.Bitmap ShowDWG(int Pwidth, int PHeight, string FilePath)
        {
            System.Drawing.Bitmap bitmap = GetDwgImage(FilePath);
            int Height = bitmap.Height;
            int Width = bitmap.Width;
            System.Drawing.Bitmap newbitmap = new System.Drawing.Bitmap(Width, Height);
            System.Drawing.Bitmap oldbitmap = (System.Drawing.Bitmap)bitmap;
            System.Drawing.Color pixel;
            for (int x = 1; x < Width; x++)
            {
                for (int y = 1; y < Height; y++)
                {

                    pixel = oldbitmap.GetPixel(x, y);
                    int r = pixel.R, g = pixel.G, b = pixel.B;
                    if (pixel.Name == "ffffffff" || pixel.Name == "ff000000")
                    {
                        r = 255 - pixel.R;
                        g = 255 - pixel.G;
                        b = 255 - pixel.B;
                    }

                    newbitmap.SetPixel(x, y, System.Drawing.Color.FromArgb(r, g, b));
                }
            }
            System.Drawing.Bitmap bt = new System.Drawing.Bitmap(newbitmap, Pwidth, PHeight);

            return newbitmap;
        }

效果不好,还是直接选用读取bmp文件的方式来处理。

激活IDM

第一步:https://www.internetdownloadmanager.com/官网下载IDM

第二步:安装idm并运行idm,在Windows搜索栏中输入:“powershell”右键以管理员运行。

第三步:在power shell窗口中,右键粘贴代码:

irm https://massgrave.dev/ias | iex

回车键运行,按数字键2,再按数字键9 等待片刻,关闭所有窗口再次启动你的IDM下载器,就完成激活了。

image-20240923114031157 Github

WPF中使用GsPreviewCtrl预览图块

winform控件处理

GsPreviewCtrl.cs

C#
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
using System;
using System.IO;
using System.Diagnostics;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using AcadApp = ZwSoft.ZwCAD.ApplicationServices.Application;
using ZwSoft.ZwCAD.ApplicationServices;
using ZwSoft.ZwCAD.DatabaseServices;
using ZwSoft.ZwCAD.Windows;
using ZwSoft.ZwCAD.EditorInput;
using ZwSoft.ZwCAD.Runtime;
using ZwSoft.ZwCAD.Geometry;
using ZwSoft.ZwCAD.GraphicsSystem;
namespace BlockView.NET
{
    public class GsPreviewCtrl : Control
    {
        public GsPreviewCtrl()
        {
        }



        // current dwg
        public Database mCurrentDwg = null;
        // Gs specific
        public ZwSoft.ZwCAD.GraphicsSystem.Manager mpManager = null;
        public ZwSoft.ZwCAD.GraphicsSystem.Device mpDevice = null;
        public ZwSoft.ZwCAD.GraphicsSystem.Model mpModel = null;
        public ZwSoft.ZwCAD.GraphicsSystem.View mpView = null;
        public bool mZooming = false;
        public bool mMouseDown = false;
        public bool mMouseMoving = false;
        public bool mbPanning = false;
        public bool mbOrbiting = false;
        public System.Drawing.Point mStartPoint;
        public System.Drawing.Point mEndPoint;

        public static bool IsDesignMode
        {
            get
            {
                return Utils.IsDesignMode(null);
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                // clear up the GS view gadgets
                if (!IsDesignMode)
                    ClearAll();
                if (mCurrentDwg != null)
                {
                    mCurrentDwg.Dispose();
                    mCurrentDwg = null;
                }
            }
            base.Dispose(disposing);

        }

        // called from InitDrawingControl, does GsPreviewCtrl specific initialization
        public void Init(Document doc, Database db)
        {
            mCurrentDwg = db;
            // check to see if the manager is already initalised
            if (null == mpManager)
            {
                // if not let's set it up
                mpManager = doc.GraphicsManager;
                // here's some test code to show the GS Events working
                mpManager.ViewToBeDestroyed += new ViewToBeDestroyedEventHandler(GSUtil.mpManager_ViewToBeDestroyed);
                mpManager.ViewWasCreated += new ViewWasCreatedEventHandler(GSUtil.mpManager_ViewWasCreated);
                mpManager.GsToBeUnloaded += new GsToBeUnloadedEventHandler(GSUtil.mpManager_GsToBeUnloaded);
                mpManager.ConfigWasModified += new ConfigWasModifiedEventHandler(GSUtil.mpManager_ConfigWasModified);

                KernelDescriptor descriptor = new KernelDescriptor();
                descriptor.addRequirement(ZwSoft.ZwCAD.UniqueString.Intern("3D Drawing"));
                GraphicsKernel kernal = Manager.AcquireGraphicsKernel(descriptor);
                // now create the Gs control, create the autocad device passing the handle to the Windows panel
                mpDevice = mpManager.CreateZWCADDevice(kernal, this.Handle);
                // resize the device to the panel size
                mpDevice.OnSize(this.Size);
                // now create a new gs view
                mpView = new ZwSoft.ZwCAD.GraphicsSystem.View();
                // and create the model
                mpModel = mpManager.CreateZWCADModel(kernal);

                // add the view to the device
                mpDevice.Add(mpView);
            }

            SetViewTo(mpView, mCurrentDwg);
            using (Transaction tr = mCurrentDwg.TransactionManager.StartTransaction())
            {
                BlockTableRecord curSpace = tr.GetObject(mCurrentDwg.CurrentSpaceId, OpenMode.ForRead, true) as BlockTableRecord;
                // 在这里进行你的操作
                mpView.Add(curSpace, mpModel);
                tr.Commit();
            }

            refreshView();
        }


        public void ClearAll()
        {
            if (!IsDesignMode)
            {
                if (!(mpDevice is null))
                {
                    bool b = mpDevice.Erase(mpView);
                }
                if (!(mpView is null))
                {
                    mpView.EraseAll();
                    mpView.Dispose();
                    mpView = null;
                }
                if (!(mpManager is null))
                {
                    if (!(mpModel is null))
                    {
                        mpModel.Dispose();
                        mpModel = null;
                    }

                    if (!(mpDevice is null))
                    {
                        mpDevice.Dispose();
                        mpDevice = null;
                    }
                    mpManager = null;
                }
            }
        }

        // [TT]: Refactored to exclude AutoCAD types from methods that run in the designer:

        public void ErasePreview()
        {
            if (!IsDesignMode)
                InternalErasePreview();
        }

        public void InternalErasePreview()
        {
            if (mpView != null)
                mpView.EraseAll();
            if (mpManager != null && mpModel != null)
            {
                mpModel.Dispose();
                mpModel = null;
            }
        }

        private void RubberRectangle(Point p1, Point p2)
        {
            Rectangle rc = new Rectangle();

            // Convert the points to screen coordinates.
            p1 = PointToScreen(p1);
            p2 = PointToScreen(p2);
            // Normalize the rectangle.
            if (p1.X < p2.X)
            {
                rc.X = p1.X;
                rc.Width = p2.X - p1.X;
            }
            else
            {
                rc.X = p2.X;
                rc.Width = p1.X - p2.X;
            }
            if (p1.Y < p2.Y)
            {
                rc.Y = p1.Y;
                rc.Height = p2.Y - p1.Y;
            }
            else
            {
                rc.Y = p2.Y;
                rc.Height = p1.Y - p2.Y;
            }
            // Draw the reversible frame.
            ControlPaint.DrawReversibleFrame(rc, Color.White, FrameStyle.Dashed);
        }

        // [TT]: Refactored to exclude AutoCAD types from methods that run in the designer:

        public void refreshView()
        {
            if (!IsDesignMode)
            {
                InternalRefreshView();
            }
        }

        // This method will never be jit'ed in the designer:

        void InternalRefreshView()
        {
            if (mpView != null)
            {
                mpView.Invalidate();
                mpView.Update();
            }
        }

        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            base.OnPaint(e);
            refreshView();
        }

        // [TT]: Refactored to exclude AutoCAD types from methods that run in the designer:

        protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (!IsDesignMode)
            {
                InternalOnMouseMove(e);
            }
        }

        private void InternalOnMouseMove(System.Windows.Forms.MouseEventArgs e)
        {
            if (mpView != null)
            {
                if (mZooming)
                {
                    // if left button is down
                    if (mMouseDown)
                    {
                        if (mMouseMoving)
                        {
                            // erase the old rectangle
                            RubberRectangle(mStartPoint, mEndPoint);
                        }
                        // draw the new rectangle
                        RubberRectangle(mStartPoint, e.Location);
                        mMouseMoving = true;
                        // save the new point for next time
                        mEndPoint = e.Location;
                    }
                }
                else
                {
                    if (mbPanning)
                    {
                        //transform the point from device coordinates to
                        //world coordinates
                        Vector3d pan_vec = new Vector3d(-(e.Location.X - mStartPoint.X), e.Location.Y - mStartPoint.Y, 0);
                        /*pan_vec = */
                        pan_vec.TransformBy(mpView.ViewingMatrix * mpView.WorldToDeviceMatrix.Inverse());
                        mpView.Dolly(pan_vec);
                        refreshView();
                        mStartPoint = e.Location;
                    }
                    if (mbOrbiting)
                    {
                        double Half_Pi = 1.570796326795;

                        System.Drawing.Rectangle view_rect = new System.Drawing.Rectangle((int)mpView.ViewportExtents.MinPoint.X, (int)mpView.ViewportExtents.MinPoint.Y,
                                                                               (int)(mpView.ViewportExtents.MaxPoint.X - mpView.ViewportExtents.MinPoint.X),
                                                                               (int)(mpView.ViewportExtents.MaxPoint.Y - mpView.ViewportExtents.MinPoint.Y));

                        int nViewportX = (view_rect.Right - view_rect.Left) + 1;
                        int nViewportY = (view_rect.Bottom - view_rect.Top) + 1;

                        int centerX = (int)(nViewportX / 2.0f + view_rect.Left);
                        int centerY = (int)(nViewportY / 2.0f + view_rect.Top);

                        double radius = System.Math.Min(nViewportX, nViewportY) * 0.4f;

                        // compute two vectors from last and new cursor positions:

                        Vector3d last_vector = new Vector3d((mStartPoint.X - centerX) / radius,
                             -(mStartPoint.Y - centerY) / radius,
                             0.0);
                        if (last_vector.LengthSqrd > 1.0)     // outside the radius
                        {
                            double x = last_vector.X / last_vector.Length;
                            double y = last_vector.Y / last_vector.Length;
                            double z = last_vector.Z / last_vector.Length;
                            last_vector = new Vector3d(x, y, z);

                        }
                        else
                        {
                            double x = last_vector.X;
                            double y = last_vector.Y;
                            double z = System.Math.Sqrt(1.0 - last_vector.X * last_vector.X - last_vector.Y * last_vector.Y);
                            last_vector = new Vector3d(x, y, z);
                        }

                        Vector3d new_vector = new Vector3d((e.Location.X - centerX) / radius, -(e.Location.Y - centerY) / radius, 0.0);

                        if (new_vector.LengthSqrd > 1.0)     // outside the radius
                        {
                            double x = new_vector.X / new_vector.Length;
                            double y = new_vector.Y / new_vector.Length;
                            double z = new_vector.Z / new_vector.Length;
                            new_vector = new Vector3d(x, y, z);

                        }
                        else
                        {
                            double x = new_vector.X;
                            double y = new_vector.Y;
                            double z = System.Math.Sqrt(1.0 - new_vector.X * new_vector.X - new_vector.Y * new_vector.Y);
                            new_vector = new Vector3d(x, y, z);
                        }

                        // determine angles for proper sequence of camera manipulations:

                        Vector3d rotation_vector = last_vector;
                        rotation_vector = rotation_vector.CrossProduct(new_vector);  // rotation_vector = last_vector x new_vector

                        Vector3d work_vector = rotation_vector;
                        work_vector = new Vector3d(work_vector.X, work_vector.Y, 0.0f);                      // projection of rotation_vector onto xy plane

                        double roll_angle = System.Math.Atan2(work_vector.X,
                             work_vector.Y);        // assuming that the camera's up vector is "up",
                                                    // this computes the angle between the up vector 
                                                    // and the work vector, which is the roll required
                                                    // to make the up vector coincident with the rotation_vector
                        double length = rotation_vector.Length;
                        double orbit_y_angle = (length != 0.0) ? System.Math.Acos(rotation_vector.Z / length) + Half_Pi : Half_Pi;                   // represents inverse cosine of the dot product of the
                        if (length > 1.0f)                                              // rotation_vector and the up_vector divided by the
                            length = 1.0f;                                              // magnitude of both vectors.  We add pi/2 because we 
                                                                                        // are making the up-vector parallel to the the rotation
                        double rotation_angle = System.Math.Asin(length);                // vector ... up-vector is perpin. to the eye-vector.

                        // perform view manipulations

                        mpView.Roll(roll_angle);               // 1: roll camera to make up vector coincident with rotation vector
                        mpView.Orbit(0.0f, orbit_y_angle);     // 2: orbit along y to make up vector parallel with rotation vector
                        mpView.Orbit(rotation_angle, 0.0f);     // 3: orbit along x by rotation angle
                        mpView.Orbit(0.0f, -orbit_y_angle);     // 4: orbit along y by the negation of 2
                        mpView.Roll(-roll_angle);               // 5: roll camera by the negation of 1
                        refreshView();
                        mStartPoint = e.Location;
                    }
                }
            }
        }
        public void SetViewTo(ZwSoft.ZwCAD.GraphicsSystem.View view, Database db)
        {
            // just check we have valid extents
            if (db.Extmax.X < db.Extmin.X || db.Extmax.Y < db.Extmin.Y || db.Extmax.Z < db.Extmax.Z)
            {
                db.Extmin = new Point3d(0, 0, 0);
                db.Extmax = new Point3d(400, 400, 400);
            }
            // get the dwg extents
            Point3d extMax = db.Extmax;
            Point3d extMin = db.Extmin;
            // now the active viewport info
            double height = 0.0, width = 0.0, viewTwist = 0.0;
            Point3d targetView = new Point3d();
            Vector3d viewDir = new Vector3d();
            GSUtil.GetActiveViewPortInfo(ref height, ref width, ref targetView, ref viewDir, ref viewTwist, true);
            // from the data returned let's work out the viewmatrix
            viewDir = viewDir.GetNormal();
            Vector3d viewXDir = viewDir.GetPerpendicularVector().GetNormal();
            viewXDir = viewXDir.RotateBy(viewTwist, -viewDir);
            Vector3d viewYDir = viewDir.CrossProduct(viewXDir);
            Point3d boxCenter = extMin + 0.5 * (extMax - extMin);
            Matrix3d viewMat;
            viewMat = Matrix3d.AlignCoordinateSystem(boxCenter, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis,
              boxCenter, viewXDir, viewYDir, viewDir).Inverse();
            Extents3d wcsExtents = new Extents3d(extMin, extMax);
            Extents3d viewExtents = wcsExtents;
            viewExtents.TransformBy(viewMat);
            double xMax = System.Math.Abs(viewExtents.MaxPoint.X - viewExtents.MinPoint.X);
            double yMax = System.Math.Abs(viewExtents.MaxPoint.Y - viewExtents.MinPoint.Y);
            Point3d eye = boxCenter + viewDir;
            // finally set the Gs view to the dwg view
            view.SetView(eye, boxCenter, viewYDir, xMax, yMax);

            // now update
            refreshView();
        }

        // [TT]: Refactored to exclude AutoCAD types from methods that run in the designer:
        protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
        {
            base.OnMouseDown(e);
            if (!IsDesignMode)
            {
                InternalOnMouseDown(e);
            }
        }

        private void InternalOnMouseDown(System.Windows.Forms.MouseEventArgs e)
        {
            if (mpView != null)
            {
                if (e.Button == System.Windows.Forms.MouseButtons.Left)
                {
                    // if zooming
                    if (mZooming)
                    {
                        mMouseDown = true;
                        mMouseMoving = false;
                    }
                    else
                    {
                        mbOrbiting = true;
                        this.Focus();
                    }

                }
                else if (e.Button == System.Windows.Forms.MouseButtons.Middle)
                {
                    mbPanning = true;
                }
                mStartPoint = e.Location;
            }
        }

        // [TT]: Refactored to exclude AutoCAD types from methods that run in the designer:
        protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
        {
            base.OnMouseUp(e);
            if (!IsDesignMode)
            {
                InternalOnMouseUp(e);
            }
        }

        private void InternalOnMouseUp(System.Windows.Forms.MouseEventArgs e)
        {
            if (mpView != null)
            {
                if (e.Button == System.Windows.Forms.MouseButtons.Left)
                {
                    if (mZooming && mMouseDown)
                    {
                        // end zoom
                        mZooming = false;
                        mMouseDown = false;
                        mMouseMoving = false;


                        mpView.ZoomWindow(new Point2d(mStartPoint.X, this.Bottom - mStartPoint.Y), new Point2d(mEndPoint.X, this.Bottom - mEndPoint.Y));

                        refreshView();
                    }
                    else
                    {
                        mbOrbiting = false;
                    }
                }
                else if (e.Button == System.Windows.Forms.MouseButtons.Middle)
                {
                    mbPanning = false;
                }
            }
        }

        // [TT]: Refactored to exclude AutoCAD types from methods that run in the designer:
        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);

            /// No AutoCAD types can be in this method, so we've
            /// moved the following code to another method which
            /// appears below, and only call that method when not 
            /// running in the designer:

            //if( mpDevice != null )
            //{
            //   mpDevice.OnSize( this.Size );
            //}

            if (!IsDesignMode)
            {
                InternalOnSizeChanged();
            }
        }

        // This method will never be jit'ed in the designer
        void InternalOnSizeChanged()
        {
            if (!(mpDevice is null))
            {
                mpDevice.OnSize(this.Size);
            }
        }
    }

    /// <summary>
    /// [TT]: Depreciated (using ControlPaint.DrawReversibleFrame() instead)
    /// </summary>

    public class GSUtil
    {
        public const String strActive = "*Active";
        public const String strActiveSettings = "ACAD_RENDER_ACTIVE_SETTINGS";
        public static void CustomUpdate(System.IntPtr parmeter, int left, int right, int bottom, int top)
        {
            MessageBox.Show("Left:" + left + "Right" + right + "Bottom" + bottom + "Top" + top);
        }
        public static System.Drawing.Color[] MyAcadColorPs =
    {
      System.Drawing.Color.FromArgb(255, 0, 0, 255),    //----- 0 - lets make it red for an example
      //{255, 255, 255, 255},//----- 0 - ByBlock - White
      System.Drawing.Color.FromArgb(255, 0, 0, 255),    //----- 1 - Red 
      System.Drawing.Color.FromArgb(255, 255, 0, 255),    //----- 2 - Yellow
      System.Drawing.Color.FromArgb(0, 255, 0, 255),    //----- 3 - Green
      System.Drawing.Color.FromArgb(0, 255, 255, 255),    //----- 4 - Cyan
      System.Drawing.Color.FromArgb(0, 0, 255, 255),    //----- 5 - Blue
      System.Drawing.Color.FromArgb(255, 0, 255, 255),    //----- 6 - Magenta
      System.Drawing.Color.FromArgb(255, 0, 0, 255),    //----- 7 - More red Red 
      System.Drawing.Color.FromArgb(255, 0, 0, 255),    //----- 8 - More red Red 
      System.Drawing.Color.FromArgb(255, 0, 0, 255),    //----- 9 - More red Red 
      /*System.Drawing.Color.FromArgb(255, 255, 255, 255),//----- 7 - White
      System.Drawing.Color.FromArgb(255, 255, 255, 255),//----- 8
      System.Drawing.Color.FromArgb(255, 255, 255, 255),//----- 9*/
      System.Drawing.Color.FromArgb(255, 0, 0, 255),    //----- 10
      System.Drawing.Color.FromArgb(255, 127, 127, 255),//----- 11
      System.Drawing.Color.FromArgb(165, 0, 0, 255),    //----- 12
      System.Drawing.Color.FromArgb(165, 82, 82, 255),    //----- 13
      System.Drawing.Color.FromArgb(127, 0, 0, 255),    //----- 14
      System.Drawing.Color.FromArgb(127, 63, 63, 255),    //----- 15
      System.Drawing.Color.FromArgb(76, 0, 0, 255),        //----- 16
      System.Drawing.Color.FromArgb(76, 38, 38, 255),    //----- 17
      System.Drawing.Color.FromArgb(38, 0, 0, 255),        //----- 18
      System.Drawing.Color.FromArgb(38, 19, 19, 255),    //----- 19
      System.Drawing.Color.FromArgb(255, 63, 0, 255),    //----- 20
      System.Drawing.Color.FromArgb(255, 159, 127, 255),//----- 21
      System.Drawing.Color.FromArgb(165, 41, 0, 255),    //----- 22
      System.Drawing.Color.FromArgb(165, 103, 82, 255),    //----- 23
      System.Drawing.Color.FromArgb(127, 31, 0, 255),    //----- 24
      System.Drawing.Color.FromArgb(127, 79, 63, 255),    //----- 25
      System.Drawing.Color.FromArgb(76, 19, 0, 255),    //----- 26
      System.Drawing.Color.FromArgb(76, 47, 38, 255),    //----- 27
      System.Drawing.Color.FromArgb(38, 9, 0, 255),        //----- 28
      System.Drawing.Color.FromArgb(38, 23, 19, 255),    //----- 29
      System.Drawing.Color.FromArgb(255, 127, 0, 255),    //----- 30
      System.Drawing.Color.FromArgb(255, 191, 127, 255),//----- 31
      System.Drawing.Color.FromArgb(165, 82, 0, 255),    //----- 32
      System.Drawing.Color.FromArgb(165, 124, 82, 255),    //----- 33
      System.Drawing.Color.FromArgb(127, 63, 0, 255),    //----- 34
      System.Drawing.Color.FromArgb(127, 95, 63, 255),    //----- 35
      System.Drawing.Color.FromArgb(76, 38, 0, 255),    //----- 36
      System.Drawing.Color.FromArgb(76, 57, 38, 255),    //----- 37
      System.Drawing.Color.FromArgb(38, 19, 0, 255),    //----- 38
      System.Drawing.Color.FromArgb(38, 28, 19, 255),    //----- 39
      System.Drawing.Color.FromArgb(255, 191, 0, 255),    //----- 40
      System.Drawing.Color.FromArgb(255, 223, 127, 255),//----- 41
      System.Drawing.Color.FromArgb(165, 124, 0, 255),    //----- 42
      System.Drawing.Color.FromArgb(165, 145, 82, 255),    //----- 43
      System.Drawing.Color.FromArgb(127, 95, 0, 255),    //----- 44
      System.Drawing.Color.FromArgb(127, 111, 63, 255),    //----- 45
      System.Drawing.Color.FromArgb(76, 57, 0, 255),    //----- 46
      System.Drawing.Color.FromArgb(76, 66, 38, 255),    //----- 47
      System.Drawing.Color.FromArgb(38, 28, 0, 255),    //----- 48
      System.Drawing.Color.FromArgb(38, 33, 19, 255),    //----- 49
      System.Drawing.Color.FromArgb(255, 255, 0, 255),    //----- 50
      System.Drawing.Color.FromArgb(255, 255, 127, 255),//----- 51
      System.Drawing.Color.FromArgb(165, 165, 0, 255),    //----- 52
      System.Drawing.Color.FromArgb(165, 165, 82, 255),    //----- 53
      System.Drawing.Color.FromArgb(127, 127, 0, 255),    //----- 54
      System.Drawing.Color.FromArgb(127, 127, 63, 255),    //----- 55
      System.Drawing.Color.FromArgb(76, 76, 0, 255),    //----- 56
      System.Drawing.Color.FromArgb(76, 76, 38, 255),    //----- 57
      System.Drawing.Color.FromArgb(38, 38, 0, 255),    //----- 58
      System.Drawing.Color.FromArgb(38, 38, 19, 255),    //----- 59
      System.Drawing.Color.FromArgb(191, 255, 0, 255),    //----- 60
      System.Drawing.Color.FromArgb(223, 255, 127, 255),//----- 61
      System.Drawing.Color.FromArgb(124, 165, 0, 255),    //----- 62
      System.Drawing.Color.FromArgb(145, 165, 82, 255),    //----- 63
      System.Drawing.Color.FromArgb(95, 127, 0, 255),    //----- 64
      System.Drawing.Color.FromArgb(111, 127, 63, 255),    //----- 65
      System.Drawing.Color.FromArgb(57, 76, 0, 255),    //----- 66
      System.Drawing.Color.FromArgb(66, 76, 38, 255),    //----- 67
      System.Drawing.Color.FromArgb(28, 38, 0, 255),    //----- 68
      System.Drawing.Color.FromArgb(33, 38, 19, 255),    //----- 69
      System.Drawing.Color.FromArgb(127, 255, 0, 255),    //----- 70
      System.Drawing.Color.FromArgb(191, 255, 127, 255),//----- 71
      System.Drawing.Color.FromArgb(82, 165, 0, 255),    //----- 72
      System.Drawing.Color.FromArgb(124, 165, 82, 255),    //----- 73
      System.Drawing.Color.FromArgb(63, 127, 0, 255),    //----- 74
      System.Drawing.Color.FromArgb(95, 127, 63, 255),    //----- 75
      System.Drawing.Color.FromArgb(38, 76, 0, 255),    //----- 76
      System.Drawing.Color.FromArgb(57, 76, 38, 255),    //----- 77
      System.Drawing.Color.FromArgb(19, 38, 0, 255),    //----- 78
      System.Drawing.Color.FromArgb(28, 38, 19, 255),    //----- 79
      System.Drawing.Color.FromArgb(63, 255, 0, 255),    //----- 80
      System.Drawing.Color.FromArgb(159, 255, 127, 255),//----- 81
      System.Drawing.Color.FromArgb(41, 165, 0, 255),    //----- 82
      System.Drawing.Color.FromArgb(103, 165, 82, 255),    //----- 83
      System.Drawing.Color.FromArgb(31, 127, 0, 255),    //----- 84
      System.Drawing.Color.FromArgb(79, 127, 63, 255),    //----- 85
      System.Drawing.Color.FromArgb(19, 76, 0, 255),    //----- 86
      System.Drawing.Color.FromArgb(47, 76, 38, 255),    //----- 87
      System.Drawing.Color.FromArgb(9, 38, 0, 255),        //----- 88
      System.Drawing.Color.FromArgb(23, 38, 19, 255),    //----- 89
      System.Drawing.Color.FromArgb(0, 255, 0, 255),    //----- 90
      System.Drawing.Color.FromArgb(127, 255, 127, 255),//----- 91
      System.Drawing.Color.FromArgb(0, 165, 0, 255),    //----- 92
      System.Drawing.Color.FromArgb(82, 165, 82, 255),    //----- 93
      System.Drawing.Color.FromArgb(0, 127, 0, 255),    //----- 94
      System.Drawing.Color.FromArgb(63, 127, 63, 255),    //----- 95
      System.Drawing.Color.FromArgb(0, 76, 0, 255),        //----- 96
      System.Drawing.Color.FromArgb(38, 76, 38, 255),    //----- 97
      System.Drawing.Color.FromArgb(0, 38, 0, 255),        //----- 98
      System.Drawing.Color.FromArgb(19, 38, 19, 255),    //----- 99
      System.Drawing.Color.FromArgb(0, 255, 63, 255),    //----- 100
      System.Drawing.Color.FromArgb(127, 255, 159, 255),//----- 101
      System.Drawing.Color.FromArgb(0, 165, 41, 255),    //----- 102
      System.Drawing.Color.FromArgb(82, 165, 103, 255),    //----- 103
      System.Drawing.Color.FromArgb(0, 127, 31, 255),    //----- 104
      System.Drawing.Color.FromArgb(63, 127, 79, 255),    //----- 105
      System.Drawing.Color.FromArgb(0, 76, 19, 255),    //----- 106
      System.Drawing.Color.FromArgb(38, 76, 47, 255),    //----- 107
      System.Drawing.Color.FromArgb(0, 38, 9, 255),        //----- 108
      System.Drawing.Color.FromArgb(19, 38, 23, 255),    //----- 109
      System.Drawing.Color.FromArgb(0, 255, 127, 255),    //----- 110
      System.Drawing.Color.FromArgb(127, 255, 191, 255),//----- 111
      System.Drawing.Color.FromArgb(0, 165, 82, 255),    //----- 112
      System.Drawing.Color.FromArgb(82, 165, 124, 255),    //----- 113
      System.Drawing.Color.FromArgb(0, 127, 63, 255),    //----- 114
      System.Drawing.Color.FromArgb(63, 127, 95, 255),    //----- 115
      System.Drawing.Color.FromArgb(0, 76, 38, 255),    //----- 116
      System.Drawing.Color.FromArgb(38, 76, 57, 255),    //----- 117
      System.Drawing.Color.FromArgb(0, 38, 19, 255),    //----- 118
      System.Drawing.Color.FromArgb(19, 38, 28, 255),    //----- 119
      System.Drawing.Color.FromArgb(0, 255, 191, 255),    //----- 120
      System.Drawing.Color.FromArgb(127, 255, 223, 255),//----- 121
      System.Drawing.Color.FromArgb(0, 165, 124, 255),    //----- 122
      System.Drawing.Color.FromArgb(82, 165, 145, 255),    //----- 123
      System.Drawing.Color.FromArgb(0, 127, 95, 255),    //----- 124
      System.Drawing.Color.FromArgb(63, 127, 111, 255),    //----- 125
      System.Drawing.Color.FromArgb(0, 76, 57, 255),    //----- 126
      System.Drawing.Color.FromArgb(38, 76, 66, 255),    //----- 127
      System.Drawing.Color.FromArgb(0, 38, 28, 255),    //----- 128
      System.Drawing.Color.FromArgb(19, 38, 33, 255),    //----- 129
      System.Drawing.Color.FromArgb(0, 255, 255, 255),    //----- 130
      System.Drawing.Color.FromArgb(127, 255, 255, 255),//----- 131
      System.Drawing.Color.FromArgb(0, 165, 165, 255),    //----- 132
      System.Drawing.Color.FromArgb(82, 165, 165, 255),    //----- 133
      System.Drawing.Color.FromArgb(0, 127, 127, 255),    //----- 134
      System.Drawing.Color.FromArgb(63, 127, 127, 255),    //----- 135
      System.Drawing.Color.FromArgb(0, 76, 76, 255),    //----- 136
      System.Drawing.Color.FromArgb(38, 76, 76, 255),    //----- 137
      System.Drawing.Color.FromArgb(0, 38, 38, 255),    //----- 138
      System.Drawing.Color.FromArgb(19, 38, 38, 255),    //----- 139
      System.Drawing.Color.FromArgb(0, 191, 255, 255),    //----- 140
      System.Drawing.Color.FromArgb(127, 223, 255, 255),//----- 141
      System.Drawing.Color.FromArgb(0, 124, 165, 255),    //----- 142
      System.Drawing.Color.FromArgb(82, 145, 165, 255),    //----- 143
      System.Drawing.Color.FromArgb(0, 95, 127, 255),    //----- 144
      System.Drawing.Color.FromArgb(63, 111, 127, 255),    //----- 145
      System.Drawing.Color.FromArgb(0, 57, 76, 255),    //----- 146
      System.Drawing.Color.FromArgb(38, 66, 76, 255),    //----- 147
      System.Drawing.Color.FromArgb(0, 28, 38, 255),    //----- 148
      System.Drawing.Color.FromArgb(19, 33, 38, 255),    //----- 149
      System.Drawing.Color.FromArgb(0, 127, 255, 255),    //----- 150
      System.Drawing.Color.FromArgb(127, 191, 255, 255),//----- 151
      System.Drawing.Color.FromArgb(0, 82, 165, 255),    //----- 152
      System.Drawing.Color.FromArgb(82, 124, 165, 255),    //----- 153
      System.Drawing.Color.FromArgb(0, 63, 127, 255),    //----- 154
      System.Drawing.Color.FromArgb(63, 95, 127, 255),    //----- 155
      System.Drawing.Color.FromArgb(0, 38, 76, 255),    //----- 156
      System.Drawing.Color.FromArgb(38, 57, 76, 255),    //----- 157
      System.Drawing.Color.FromArgb(0, 19, 38, 255),    //----- 158
      System.Drawing.Color.FromArgb(19, 28, 38, 255),    //----- 159
      System.Drawing.Color.FromArgb(0, 63, 255, 255),    //----- 160
      System.Drawing.Color.FromArgb(127, 159, 255, 255),//----- 161
      System.Drawing.Color.FromArgb(0, 41, 165, 255),    //----- 162
      System.Drawing.Color.FromArgb(82, 103, 165, 255),    //----- 163
      System.Drawing.Color.FromArgb(0, 31, 127, 255),    //----- 164
      System.Drawing.Color.FromArgb(63, 79, 127, 255),    //----- 165
      System.Drawing.Color.FromArgb(0, 19, 76, 255),    //----- 166
      System.Drawing.Color.FromArgb(38, 47, 76, 255),    //----- 167
      System.Drawing.Color.FromArgb(0, 9, 38, 255),        //----- 168
      System.Drawing.Color.FromArgb(19, 23, 38, 255),    //----- 169
      System.Drawing.Color.FromArgb(0, 0, 255, 255),    //----- 170
      System.Drawing.Color.FromArgb(127, 127, 255, 255),//----- 171
      System.Drawing.Color.FromArgb(0, 0, 165, 255),    //----- 172
      System.Drawing.Color.FromArgb(82, 82, 165, 255),    //----- 173
      System.Drawing.Color.FromArgb(0, 0, 127, 255),    //----- 174
      System.Drawing.Color.FromArgb(63, 63, 127, 255),    //----- 175
      System.Drawing.Color.FromArgb(0, 0, 76, 255),        //----- 176
      System.Drawing.Color.FromArgb(38, 38, 76, 255),    //----- 177
      System.Drawing.Color.FromArgb(0, 0, 38, 255),        //----- 178
      System.Drawing.Color.FromArgb(19, 19, 38, 255),    //----- 179
      System.Drawing.Color.FromArgb(63, 0, 255, 255),    //----- 180
      System.Drawing.Color.FromArgb(159, 127, 255, 255),//----- 181
      System.Drawing.Color.FromArgb(41, 0, 165, 255),    //----- 182
      System.Drawing.Color.FromArgb(103, 82, 165, 255),    //----- 183
      System.Drawing.Color.FromArgb(31, 0, 127, 255),    //----- 184
      System.Drawing.Color.FromArgb(79, 63, 127, 255),    //----- 185
      System.Drawing.Color.FromArgb(19, 0, 76, 255),    //----- 186
      System.Drawing.Color.FromArgb(47, 38, 76, 255),    //----- 187
      System.Drawing.Color.FromArgb(9, 0, 38, 255),        //----- 188
      System.Drawing.Color.FromArgb(23, 19, 38, 255),    //----- 189
      System.Drawing.Color.FromArgb(127, 0, 255, 255),    //----- 190
      System.Drawing.Color.FromArgb(191, 127, 255, 255),//----- 191
      System.Drawing.Color.FromArgb(82, 0, 165, 255),    //----- 192
      System.Drawing.Color.FromArgb(124, 82, 165, 255),    //----- 193
      System.Drawing.Color.FromArgb(63, 0, 127, 255),    //----- 194
      System.Drawing.Color.FromArgb(95, 63, 127, 255),    //----- 195
      System.Drawing.Color.FromArgb(38, 0, 76, 255),    //----- 196
      System.Drawing.Color.FromArgb(57, 38, 76, 255),    //----- 197
      System.Drawing.Color.FromArgb(19, 0, 38, 255),    //----- 198
      System.Drawing.Color.FromArgb(28, 19, 38, 255),    //----- 199
      System.Drawing.Color.FromArgb(191, 0, 255, 255),    //----- 200
      System.Drawing.Color.FromArgb(223, 127, 255, 255),//----- 201
      System.Drawing.Color.FromArgb(124, 0, 165, 255),    //----- 202
      System.Drawing.Color.FromArgb(145, 82, 165, 255),    //----- 203
      System.Drawing.Color.FromArgb(95, 0, 127, 255),    //----- 204
      System.Drawing.Color.FromArgb(111, 63, 127, 255),    //----- 205
      System.Drawing.Color.FromArgb(57, 0, 76, 255),    //----- 206
      System.Drawing.Color.FromArgb(66, 38, 76, 255),    //----- 207
      System.Drawing.Color.FromArgb(28, 0, 38, 255),    //----- 208
      System.Drawing.Color.FromArgb(33, 19, 38, 255),    //----- 209
      System.Drawing.Color.FromArgb(255, 0, 255, 255),    //----- 210
      System.Drawing.Color.FromArgb(255, 127, 255, 255),//----- 211
      System.Drawing.Color.FromArgb(165, 0, 165, 255),    //----- 212
      System.Drawing.Color.FromArgb(165, 82, 165, 255),    //----- 213
      System.Drawing.Color.FromArgb(127, 0, 127, 255),    //----- 214
      System.Drawing.Color.FromArgb(127, 63, 127, 255),    //----- 215
      System.Drawing.Color.FromArgb(76, 0, 76, 255),    //----- 216
      System.Drawing.Color.FromArgb(76, 38, 76, 255),    //----- 217
      System.Drawing.Color.FromArgb(38, 0, 38, 255),    //----- 218
      System.Drawing.Color.FromArgb(38, 19, 38, 255),    //----- 219
      System.Drawing.Color.FromArgb(255, 0, 191, 255),    //----- 220
      System.Drawing.Color.FromArgb(255, 127, 223, 255),//----- 221
      System.Drawing.Color.FromArgb(165, 0, 124, 255),    //----- 222
      System.Drawing.Color.FromArgb(165, 82, 145, 255),    //----- 223
      System.Drawing.Color.FromArgb(127, 0, 95, 255),    //----- 224
      System.Drawing.Color.FromArgb(127, 63, 111, 255),    //----- 225
      System.Drawing.Color.FromArgb(76, 0, 57, 255),    //----- 226
      System.Drawing.Color.FromArgb(76, 38, 66, 255),    //----- 227
      System.Drawing.Color.FromArgb(38, 0, 28, 255),    //----- 228
      System.Drawing.Color.FromArgb(38, 19, 33, 255),    //----- 229
      System.Drawing.Color.FromArgb(255, 0, 127, 255),    //----- 230
      System.Drawing.Color.FromArgb(255, 127, 191, 255),//----- 231
      System.Drawing.Color.FromArgb(165, 0, 82, 255),    //----- 232
      System.Drawing.Color.FromArgb(165, 82, 124, 255),    //----- 233
      System.Drawing.Color.FromArgb(127, 0, 63, 255),    //----- 234
      System.Drawing.Color.FromArgb(127, 63, 95, 255),    //----- 235
      System.Drawing.Color.FromArgb(76, 0, 38, 255),    //----- 236
      System.Drawing.Color.FromArgb(76, 38, 57, 255),    //----- 237
      System.Drawing.Color.FromArgb(38, 0, 19, 255),    //----- 238
      System.Drawing.Color.FromArgb(38, 19, 28, 255),    //----- 239
      System.Drawing.Color.FromArgb(255, 0, 63, 255),    //----- 240
      System.Drawing.Color.FromArgb(255, 127, 159, 255),//----- 241
      System.Drawing.Color.FromArgb(165, 0, 41, 255),    //----- 242
      System.Drawing.Color.FromArgb(165, 82, 103, 255),    //----- 243
      System.Drawing.Color.FromArgb(127, 0, 31, 255),    //----- 244
      System.Drawing.Color.FromArgb(127, 63, 79, 255),    //----- 245
      System.Drawing.Color.FromArgb(76, 0, 19, 255),    //----- 246
      System.Drawing.Color.FromArgb(76, 38, 47, 255),    //----- 247
      System.Drawing.Color.FromArgb(38, 0, 9, 255),        //----- 248
      System.Drawing.Color.FromArgb(38, 19, 23, 255),    //----- 249
      System.Drawing.Color.FromArgb(84, 84, 84, 255),    //----- 250
      System.Drawing.Color.FromArgb(118, 118, 118, 255),//----- 251
      System.Drawing.Color.FromArgb(152, 152, 152, 255),//----- 252
      System.Drawing.Color.FromArgb(186, 186, 186, 255),//----- 253
      System.Drawing.Color.FromArgb(220, 220, 220, 255),//----- 254
      System.Drawing.Color.FromArgb(255, 255, 255, 255),//----- 255
    };

        //////////////////////////////////////////////////////////////////////////////
        // standard autocad colours
        public static System.Drawing.Color[] MyAcadColorMs =
    {
      System.Drawing.Color.FromArgb(255, 255, 255, 255),//----- 0 - ByBlock - White
      System.Drawing.Color.FromArgb(255, 0, 0, 255),    //----- 1 - Red 
      System.Drawing.Color.FromArgb(255, 255, 0, 255),    //----- 2 - Yellow
      System.Drawing.Color.FromArgb(0, 255, 0, 255),    //----- 3 - Green
      System.Drawing.Color.FromArgb(0, 255, 255, 255),    //----- 4 - Cyan
      System.Drawing.Color.FromArgb(0, 0, 255, 255),    //----- 5 - Blue
      System.Drawing.Color.FromArgb(255, 0, 255, 255),    //----- 6 - Magenta
      System.Drawing.Color.FromArgb(255, 255, 255, 255),//----- 7 - White
      System.Drawing.Color.FromArgb(255, 255, 255, 255),//----- 8
      System.Drawing.Color.FromArgb(255, 255, 255, 255),//----- 9
      System.Drawing.Color.FromArgb(255, 0, 0, 255),    //----- 10
      System.Drawing.Color.FromArgb(255, 127, 127, 255),//----- 11
      System.Drawing.Color.FromArgb(165, 0, 0, 255),    //----- 12
      System.Drawing.Color.FromArgb(165, 82, 82, 255),    //----- 13
      System.Drawing.Color.FromArgb(127, 0, 0, 255),    //----- 14
      System.Drawing.Color.FromArgb(127, 63, 63, 255),    //----- 15
      System.Drawing.Color.FromArgb(76, 0, 0, 255),        //----- 16
      System.Drawing.Color.FromArgb(76, 38, 38, 255),    //----- 17
      System.Drawing.Color.FromArgb(38, 0, 0, 255),        //----- 18
      System.Drawing.Color.FromArgb(38, 19, 19, 255),    //----- 19
      System.Drawing.Color.FromArgb(255, 63, 0, 255),    //----- 20
      System.Drawing.Color.FromArgb(255, 159, 127, 255),//----- 21
      System.Drawing.Color.FromArgb(165, 41, 0, 255),    //----- 22
      System.Drawing.Color.FromArgb(165, 103, 82, 255),    //----- 23
      System.Drawing.Color.FromArgb(127, 31, 0, 255),    //----- 24
      System.Drawing.Color.FromArgb(127, 79, 63, 255),    //----- 25
      System.Drawing.Color.FromArgb(76, 19, 0, 255),    //----- 26
      System.Drawing.Color.FromArgb(76, 47, 38, 255),    //----- 27
      System.Drawing.Color.FromArgb(38, 9, 0, 255),        //----- 28
      System.Drawing.Color.FromArgb(38, 23, 19, 255),    //----- 29
      System.Drawing.Color.FromArgb(255, 127, 0, 255),    //----- 30
      System.Drawing.Color.FromArgb(255, 191, 127, 255),//----- 31
      System.Drawing.Color.FromArgb(165, 82, 0, 255),    //----- 32
      System.Drawing.Color.FromArgb(165, 124, 82, 255),    //----- 33
      System.Drawing.Color.FromArgb(127, 63, 0, 255),    //----- 34
      System.Drawing.Color.FromArgb(127, 95, 63, 255),    //----- 35
      System.Drawing.Color.FromArgb(76, 38, 0, 255),    //----- 36
      System.Drawing.Color.FromArgb(76, 57, 38, 255),    //----- 37
      System.Drawing.Color.FromArgb(38, 19, 0, 255),    //----- 38
      System.Drawing.Color.FromArgb(38, 28, 19, 255),    //----- 39
      System.Drawing.Color.FromArgb(255, 191, 0, 255),    //----- 40
      System.Drawing.Color.FromArgb(255, 223, 127, 255),//----- 41
      System.Drawing.Color.FromArgb(165, 124, 0, 255),    //----- 42
      System.Drawing.Color.FromArgb(165, 145, 82, 255),    //----- 43
      System.Drawing.Color.FromArgb(127, 95, 0, 255),    //----- 44
      System.Drawing.Color.FromArgb(127, 111, 63, 255),    //----- 45
      System.Drawing.Color.FromArgb(76, 57, 0, 255),    //----- 46
      System.Drawing.Color.FromArgb(76, 66, 38, 255),    //----- 47
      System.Drawing.Color.FromArgb(38, 28, 0, 255),    //----- 48
      System.Drawing.Color.FromArgb(38, 33, 19, 255),    //----- 49
      System.Drawing.Color.FromArgb(255, 255, 0, 255),    //----- 50
      System.Drawing.Color.FromArgb(255, 255, 127, 255),//----- 51
      System.Drawing.Color.FromArgb(165, 165, 0, 255),    //----- 52
      System.Drawing.Color.FromArgb(165, 165, 82, 255),    //----- 53
      System.Drawing.Color.FromArgb(127, 127, 0, 255),    //----- 54
      System.Drawing.Color.FromArgb(127, 127, 63, 255),    //----- 55
      System.Drawing.Color.FromArgb(76, 76, 0, 255),    //----- 56
      System.Drawing.Color.FromArgb(76, 76, 38, 255),    //----- 57
      System.Drawing.Color.FromArgb(38, 38, 0, 255),    //----- 58
      System.Drawing.Color.FromArgb(38, 38, 19, 255),    //----- 59
      System.Drawing.Color.FromArgb(191, 255, 0, 255),    //----- 60
      System.Drawing.Color.FromArgb(223, 255, 127, 255),//----- 61
      System.Drawing.Color.FromArgb(124, 165, 0, 255),    //----- 62
      System.Drawing.Color.FromArgb(145, 165, 82, 255),    //----- 63
      System.Drawing.Color.FromArgb(95, 127, 0, 255),    //----- 64
      System.Drawing.Color.FromArgb(111, 127, 63, 255),    //----- 65
      System.Drawing.Color.FromArgb(57, 76, 0, 255),    //----- 66
      System.Drawing.Color.FromArgb(66, 76, 38, 255),    //----- 67
      System.Drawing.Color.FromArgb(28, 38, 0, 255),    //----- 68
      System.Drawing.Color.FromArgb(33, 38, 19, 255),    //----- 69
      System.Drawing.Color.FromArgb(127, 255, 0, 255),    //----- 70
      System.Drawing.Color.FromArgb(191, 255, 127, 255),//----- 71
      System.Drawing.Color.FromArgb(82, 165, 0, 255),    //----- 72
      System.Drawing.Color.FromArgb(124, 165, 82, 255),    //----- 73
      System.Drawing.Color.FromArgb(63, 127, 0, 255),    //----- 74
      System.Drawing.Color.FromArgb(95, 127, 63, 255),    //----- 75
      System.Drawing.Color.FromArgb(38, 76, 0, 255),    //----- 76
      System.Drawing.Color.FromArgb(57, 76, 38, 255),    //----- 77
      System.Drawing.Color.FromArgb(19, 38, 0, 255),    //----- 78
      System.Drawing.Color.FromArgb(28, 38, 19, 255),    //----- 79
      System.Drawing.Color.FromArgb(63, 255, 0, 255),    //----- 80
      System.Drawing.Color.FromArgb(159, 255, 127, 255),//----- 81
      System.Drawing.Color.FromArgb(41, 165, 0, 255),    //----- 82
      System.Drawing.Color.FromArgb(103, 165, 82, 255),    //----- 83
      System.Drawing.Color.FromArgb(31, 127, 0, 255),    //----- 84
      System.Drawing.Color.FromArgb(79, 127, 63, 255),    //----- 85
      System.Drawing.Color.FromArgb(19, 76, 0, 255),    //----- 86
      System.Drawing.Color.FromArgb(47, 76, 38, 255),    //----- 87
      System.Drawing.Color.FromArgb(9, 38, 0, 255),        //----- 88
      System.Drawing.Color.FromArgb(23, 38, 19, 255),    //----- 89
      System.Drawing.Color.FromArgb(0, 255, 0, 255),    //----- 90
      System.Drawing.Color.FromArgb(127, 255, 127, 255),//----- 91
      System.Drawing.Color.FromArgb(0, 165, 0, 255),    //----- 92
      System.Drawing.Color.FromArgb(82, 165, 82, 255),    //----- 93
      System.Drawing.Color.FromArgb(0, 127, 0, 255),    //----- 94
      System.Drawing.Color.FromArgb(63, 127, 63, 255),    //----- 95
      System.Drawing.Color.FromArgb(0, 76, 0, 255),        //----- 96
      System.Drawing.Color.FromArgb(38, 76, 38, 255),    //----- 97
      System.Drawing.Color.FromArgb(0, 38, 0, 255),        //----- 98
      System.Drawing.Color.FromArgb(19, 38, 19, 255),    //----- 99
      System.Drawing.Color.FromArgb(0, 255, 63, 255),    //----- 100
      System.Drawing.Color.FromArgb(127, 255, 159, 255),//----- 101
      System.Drawing.Color.FromArgb(0, 165, 41, 255),    //----- 102
      System.Drawing.Color.FromArgb(82, 165, 103, 255),    //----- 103
      System.Drawing.Color.FromArgb(0, 127, 31, 255),    //----- 104
      System.Drawing.Color.FromArgb(63, 127, 79, 255),    //----- 105
      System.Drawing.Color.FromArgb(0, 76, 19, 255),    //----- 106
      System.Drawing.Color.FromArgb(38, 76, 47, 255),    //----- 107
      System.Drawing.Color.FromArgb(0, 38, 9, 255),        //----- 108
      System.Drawing.Color.FromArgb(19, 38, 23, 255),    //----- 109
      System.Drawing.Color.FromArgb(0, 255, 127, 255),    //----- 110
      System.Drawing.Color.FromArgb(127, 255, 191, 255),//----- 111
      System.Drawing.Color.FromArgb(0, 165, 82, 255),    //----- 112
      System.Drawing.Color.FromArgb(82, 165, 124, 255),    //----- 113
      System.Drawing.Color.FromArgb(0, 127, 63, 255),    //----- 114
      System.Drawing.Color.FromArgb(63, 127, 95, 255),    //----- 115
      System.Drawing.Color.FromArgb(0, 76, 38, 255),    //----- 116
      System.Drawing.Color.FromArgb(38, 76, 57, 255),    //----- 117
      System.Drawing.Color.FromArgb(0, 38, 19, 255),    //----- 118
      System.Drawing.Color.FromArgb(19, 38, 28, 255),    //----- 119
      System.Drawing.Color.FromArgb(0, 255, 191, 255),    //----- 120
      System.Drawing.Color.FromArgb(127, 255, 223, 255),//----- 121
      System.Drawing.Color.FromArgb(0, 165, 124, 255),    //----- 122
      System.Drawing.Color.FromArgb(82, 165, 145, 255),    //----- 123
      System.Drawing.Color.FromArgb(0, 127, 95, 255),    //----- 124
      System.Drawing.Color.FromArgb(63, 127, 111, 255),    //----- 125
      System.Drawing.Color.FromArgb(0, 76, 57, 255),    //----- 126
      System.Drawing.Color.FromArgb(38, 76, 66, 255),    //----- 127
      System.Drawing.Color.FromArgb(0, 38, 28, 255),    //----- 128
      System.Drawing.Color.FromArgb(19, 38, 33, 255),    //----- 129
      System.Drawing.Color.FromArgb(0, 255, 255, 255),    //----- 130
      System.Drawing.Color.FromArgb(127, 255, 255, 255),//----- 131
      System.Drawing.Color.FromArgb(0, 165, 165, 255),    //----- 132
      System.Drawing.Color.FromArgb(82, 165, 165, 255),    //----- 133
      System.Drawing.Color.FromArgb(0, 127, 127, 255),    //----- 134
      System.Drawing.Color.FromArgb(63, 127, 127, 255),    //----- 135
      System.Drawing.Color.FromArgb(0, 76, 76, 255),    //----- 136
      System.Drawing.Color.FromArgb(38, 76, 76, 255),    //----- 137
      System.Drawing.Color.FromArgb(0, 38, 38, 255),    //----- 138
      System.Drawing.Color.FromArgb(19, 38, 38, 255),    //----- 139
      System.Drawing.Color.FromArgb(0, 191, 255, 255),    //----- 140
      System.Drawing.Color.FromArgb(127, 223, 255, 255),//----- 141
      System.Drawing.Color.FromArgb(0, 124, 165, 255),    //----- 142
      System.Drawing.Color.FromArgb(82, 145, 165, 255),    //----- 143
      System.Drawing.Color.FromArgb(0, 95, 127, 255),    //----- 144
      System.Drawing.Color.FromArgb(63, 111, 127, 255),    //----- 145
      System.Drawing.Color.FromArgb(0, 57, 76, 255),    //----- 146
      System.Drawing.Color.FromArgb(38, 66, 76, 255),    //----- 147
      System.Drawing.Color.FromArgb(0, 28, 38, 255),    //----- 148
      System.Drawing.Color.FromArgb(19, 33, 38, 255),    //----- 149
      System.Drawing.Color.FromArgb(0, 127, 255, 255),    //----- 150
      System.Drawing.Color.FromArgb(127, 191, 255, 255),//----- 151
      System.Drawing.Color.FromArgb(0, 82, 165, 255),    //----- 152
      System.Drawing.Color.FromArgb(82, 124, 165, 255),    //----- 153
      System.Drawing.Color.FromArgb(0, 63, 127, 255),    //----- 154
      System.Drawing.Color.FromArgb(63, 95, 127, 255),    //----- 155
      System.Drawing.Color.FromArgb(0, 38, 76, 255),    //----- 156
      System.Drawing.Color.FromArgb(38, 57, 76, 255),    //----- 157
      System.Drawing.Color.FromArgb(0, 19, 38, 255),    //----- 158
      System.Drawing.Color.FromArgb(19, 28, 38, 255),    //----- 159
      System.Drawing.Color.FromArgb(0, 63, 255, 255),    //----- 160
      System.Drawing.Color.FromArgb(127, 159, 255, 255),//----- 161
      System.Drawing.Color.FromArgb(0, 41, 165, 255),    //----- 162
      System.Drawing.Color.FromArgb(82, 103, 165, 255),    //----- 163
      System.Drawing.Color.FromArgb(0, 31, 127, 255),    //----- 164
      System.Drawing.Color.FromArgb(63, 79, 127, 255),    //----- 165
      System.Drawing.Color.FromArgb(0, 19, 76, 255),    //----- 166
      System.Drawing.Color.FromArgb(38, 47, 76, 255),    //----- 167
      System.Drawing.Color.FromArgb(0, 9, 38, 255),        //----- 168
      System.Drawing.Color.FromArgb(19, 23, 38, 255),    //----- 169
      System.Drawing.Color.FromArgb(0, 0, 255, 255),    //----- 170
      System.Drawing.Color.FromArgb(127, 127, 255, 255),//----- 171
      System.Drawing.Color.FromArgb(0, 0, 165, 255),    //----- 172
      System.Drawing.Color.FromArgb(82, 82, 165, 255),    //----- 173
      System.Drawing.Color.FromArgb(0, 0, 127, 255),    //----- 174
      System.Drawing.Color.FromArgb(63, 63, 127, 255),    //----- 175
      System.Drawing.Color.FromArgb(0, 0, 76, 255),        //----- 176
      System.Drawing.Color.FromArgb(38, 38, 76, 255),    //----- 177
      System.Drawing.Color.FromArgb(0, 0, 38, 255),        //----- 178
      System.Drawing.Color.FromArgb(19, 19, 38, 255),    //----- 179
      System.Drawing.Color.FromArgb(63, 0, 255, 255),    //----- 180
      System.Drawing.Color.FromArgb(159, 127, 255, 255),//----- 181
      System.Drawing.Color.FromArgb(41, 0, 165, 255),    //----- 182
      System.Drawing.Color.FromArgb(103, 82, 165, 255),    //----- 183
      System.Drawing.Color.FromArgb(31, 0, 127, 255),    //----- 184
      System.Drawing.Color.FromArgb(79, 63, 127, 255),    //----- 185
      System.Drawing.Color.FromArgb(19, 0, 76, 255),    //----- 186
      System.Drawing.Color.FromArgb(47, 38, 76, 255),    //----- 187
      System.Drawing.Color.FromArgb(9, 0, 38, 255),        //----- 188
      System.Drawing.Color.FromArgb(23, 19, 38, 255),    //----- 189
      System.Drawing.Color.FromArgb(127, 0, 255, 255),    //----- 190
      System.Drawing.Color.FromArgb(191, 127, 255, 255),//----- 191
      System.Drawing.Color.FromArgb(82, 0, 165, 255),    //----- 192
      System.Drawing.Color.FromArgb(124, 82, 165, 255),    //----- 193
      System.Drawing.Color.FromArgb(63, 0, 127, 255),    //----- 194
      System.Drawing.Color.FromArgb(95, 63, 127, 255),    //----- 195
      System.Drawing.Color.FromArgb(38, 0, 76, 255),    //----- 196
      System.Drawing.Color.FromArgb(57, 38, 76, 255),    //----- 197
      System.Drawing.Color.FromArgb(19, 0, 38, 255),    //----- 198
      System.Drawing.Color.FromArgb(28, 19, 38, 255),    //----- 199
      System.Drawing.Color.FromArgb(191, 0, 255, 255),    //----- 200
      System.Drawing.Color.FromArgb(223, 127, 255, 255),//----- 201
      System.Drawing.Color.FromArgb(124, 0, 165, 255),    //----- 202
      System.Drawing.Color.FromArgb(145, 82, 165, 255),    //----- 203
      System.Drawing.Color.FromArgb(95, 0, 127, 255),    //----- 204
      System.Drawing.Color.FromArgb(111, 63, 127, 255),    //----- 205
      System.Drawing.Color.FromArgb(57, 0, 76, 255),    //----- 206
      System.Drawing.Color.FromArgb(66, 38, 76, 255),    //----- 207
      System.Drawing.Color.FromArgb(28, 0, 38, 255),    //----- 208
      System.Drawing.Color.FromArgb(33, 19, 38, 255),    //----- 209
      System.Drawing.Color.FromArgb(255, 0, 255, 255),    //----- 210
      System.Drawing.Color.FromArgb(255, 127, 255, 255),//----- 211
      System.Drawing.Color.FromArgb(165, 0, 165, 255),    //----- 212
      System.Drawing.Color.FromArgb(165, 82, 165, 255),    //----- 213
      System.Drawing.Color.FromArgb(127, 0, 127, 255),    //----- 214
      System.Drawing.Color.FromArgb(127, 63, 127, 255),    //----- 215
      System.Drawing.Color.FromArgb(76, 0, 76, 255),    //----- 216
      System.Drawing.Color.FromArgb(76, 38, 76, 255),    //----- 217
      System.Drawing.Color.FromArgb(38, 0, 38, 255),    //----- 218
      System.Drawing.Color.FromArgb(38, 19, 38, 255),    //----- 219
      System.Drawing.Color.FromArgb(255, 0, 191, 255),    //----- 220
      System.Drawing.Color.FromArgb(255, 127, 223, 255),//----- 221
      System.Drawing.Color.FromArgb(165, 0, 124, 255),    //----- 222
      System.Drawing.Color.FromArgb(165, 82, 145, 255),    //----- 223
      System.Drawing.Color.FromArgb(127, 0, 95, 255),    //----- 224
      System.Drawing.Color.FromArgb(127, 63, 111, 255),    //----- 225
      System.Drawing.Color.FromArgb(76, 0, 57, 255),    //----- 226
      System.Drawing.Color.FromArgb(76, 38, 66, 255),    //----- 227
      System.Drawing.Color.FromArgb(38, 0, 28, 255),    //----- 228
      System.Drawing.Color.FromArgb(38, 19, 33, 255),    //----- 229
      System.Drawing.Color.FromArgb(255, 0, 127, 255),    //----- 230
      System.Drawing.Color.FromArgb(255, 127, 191, 255),//----- 231
      System.Drawing.Color.FromArgb(165, 0, 82, 255),    //----- 232
      System.Drawing.Color.FromArgb(165, 82, 124, 255),    //----- 233
      System.Drawing.Color.FromArgb(127, 0, 63, 255),    //----- 234
      System.Drawing.Color.FromArgb(127, 63, 95, 255),    //----- 235
      System.Drawing.Color.FromArgb(76, 0, 38, 255),    //----- 236
      System.Drawing.Color.FromArgb(76, 38, 57, 255),    //----- 237
      System.Drawing.Color.FromArgb(38, 0, 19, 255),    //----- 238
      System.Drawing.Color.FromArgb(38, 19, 28, 255),    //----- 239
      System.Drawing.Color.FromArgb(255, 0, 63, 255),    //----- 240
      System.Drawing.Color.FromArgb(255, 127, 159, 255),//----- 241
      System.Drawing.Color.FromArgb(165, 0, 41, 255),    //----- 242
      System.Drawing.Color.FromArgb(165, 82, 103, 255),    //----- 243
      System.Drawing.Color.FromArgb(127, 0, 31, 255),    //----- 244
      System.Drawing.Color.FromArgb(127, 63, 79, 255),    //----- 245
      System.Drawing.Color.FromArgb(76, 0, 19, 255),    //----- 246
      System.Drawing.Color.FromArgb(76, 38, 47, 255),    //----- 247
      System.Drawing.Color.FromArgb(38, 0, 9, 255),        //----- 248
      System.Drawing.Color.FromArgb(38, 19, 23, 255),    //----- 249
      System.Drawing.Color.FromArgb(84, 84, 84, 255),    //----- 250
      System.Drawing.Color.FromArgb(118, 118, 118, 255),//----- 251
      System.Drawing.Color.FromArgb(152, 152, 152, 255),//----- 252
      System.Drawing.Color.FromArgb(186, 186, 186, 255),//----- 253
      System.Drawing.Color.FromArgb(220, 220, 220, 255),//----- 254
      System.Drawing.Color.FromArgb(255, 255, 255, 255),//----- 255
    };

        public static bool GetActiveViewPortInfo(ref double height, ref double width, ref Point3d target, ref Vector3d viewDir, ref double viewTwist, bool getViewCenter)
        {
            // get the editor object
            Editor ed = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            ed.UpdateTiledViewportsInDatabase();
            Database db = HostApplicationServices.WorkingDatabase;
            using (Transaction t = db.TransactionManager.StartTransaction())
            {
                ViewportTable vt = (ViewportTable)t.GetObject(db.ViewportTableId, OpenMode.ForRead);
                ViewportTableRecord btr = (ViewportTableRecord)t.GetObject(vt[GSUtil.strActive], OpenMode.ForRead);
                height = btr.Height;
                width = btr.Width;
                target = btr.Target;
                viewDir = btr.ViewDirection;
                viewTwist = btr.ViewTwist;
                t.Commit();
            }
            return true;
        }
        public static void mpManager_ViewToBeDestroyed(Object sender, ViewEventArgs e)
        {
            // get the editor object
            Editor ed = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            ed.WriteMessage("BlockView: Event ViewToBeDestroyed fired");
        }
        public static void mpManager_ViewWasCreated(Object sender, ViewEventArgs e)
        {
            // get the editor object
            Editor ed = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            ed.WriteMessage("BlockView: Event ViewWasCreated fired");
        }
        public static void mpManager_GsToBeUnloaded(Object sender, EventArgs e)
        {
            // get the editor object
            Editor ed = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            ed.WriteMessage("BlockView: Event GsToBeUnloaded fired");
        }
        public static void mpManager_ConfigWasModified(Object sender, EventArgs e)
        {
            // get the editor object
            Editor ed = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            ed.WriteMessage("BlockView: Event ConfigWasModified fired");
        }

        /// <summary>
        /// [TT]: Depreciated (using ControlPaint.DrawReversibleFrame() instead)
        /// </summary>

        public class RubberbandRectangle
        {
            public enum PenStyles
            {
                PS_SOLID = 0,
                PS_DASH = 1,
                PS_DOT = 2,
                PS_DASHDOT = 3,
                PS_DASHDOTDOT = 4
            }
            // These values come from the larger set of defines in WinGDI.h,
            // but are all that are needed for this application.  If this class
            // is expanded for more generic rectangle drawing, they should be
            // replaced by enums from those sets of defones.
            private int NULL_BRUSH = 5;
            private int R2_XORPEN = 7;
            private PenStyles penStyle;
            private int BLACK_PEN = 0;

            // Default contructor - sets member fields
            public RubberbandRectangle()
            {
                penStyle = PenStyles.PS_DOT;
            }

            // penStyles property get/set.
            public PenStyles PenStyle
            {
                get
                {
                    return penStyle;
                }
                set
                {
                    penStyle = value;
                }
            }

            public void DrawXORRectangle(Graphics grp, System.Drawing.Point startPt, System.Drawing.Point endPt)
            {
                int X1 = startPt.X;
                int Y1 = startPt.Y;
                int X2 = endPt.X;
                int Y2 = endPt.Y;
                // Extract the Win32 HDC from the Graphics object supplied.
                IntPtr hdc = grp.GetHdc();

                // Create a pen with a dotted style to draw the border of the
                // rectangle.
                IntPtr gdiPen = CreatePen(penStyle,
                                  1, BLACK_PEN);

                // Set the ROP cdrawint mode to XOR.
                SetROP2(hdc, R2_XORPEN);

                // Select the pen into the device context.
                IntPtr oldPen = SelectObject(hdc, gdiPen);

                // Create a stock NULL_BRUSH brush and select it into the device
                // context so that the rectangle isn't filled.
                IntPtr oldBrush = SelectObject(hdc,
                                            GetStockObject(NULL_BRUSH));

                // Now XOR the hollow rectangle on the Graphics object with
                // a dotted outline.
                Rectangle(hdc, X1, Y1, X2, Y2);

                // Put the old stuff back where it was.
                SelectObject(hdc, oldBrush); // no need to delete a stock object
                SelectObject(hdc, oldPen);
                DeleteObject(gdiPen);       // but we do need to delete the pen

                // Return the device context to Windows.
                grp.ReleaseHdc(hdc);
            }

            // Use Interop to call the corresponding Win32 GDI functions
            [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
            private static extern int SetROP2(
                      IntPtr hdc,       // Handle to a Win32 device context
                      int enDrawMode    // Drawing mode
                      );
            [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
            private static extern IntPtr CreatePen(
                      PenStyles enPenStyle, // Pen style from enum PenStyles
                      int nWidth,               // Width of pen
                      int crColor               // Color of pen
                      );
            [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
            private static extern bool DeleteObject(
                      IntPtr hObject    // Win32 GDI handle to object to delete
                      );
            [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
            private static extern IntPtr SelectObject(
                      IntPtr hdc,       // Win32 GDI device context
                      IntPtr hObject    // Win32 GDI handle to object to select
                      );
            [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
            private static extern void Rectangle(
                      IntPtr hdc,           // Handle to a Win32 device context
                      int X1,               // x-coordinate of top left corner
                      int Y1,               // y-cordinate of top left corner
                      int X2,               // x-coordinate of bottom right corner
                      int Y2                // y-coordinate of bottm right corner
                      );
            [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
            private static extern IntPtr GetStockObject(
                      int brStyle   // Selected from the WinGDI.h BrushStyles enum
                      );

            // Csharp version of Win32 RGB macro
            private static int RGB(int R, int G, int B)
            {
                return (R | (G << 8) | (B << 16));
            }
        }
    }
}

EnumToolStripMenuItem.cs

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//using GsRenderMode = Autodesk.AutoCAD.GraphicsSystem.RenderMode;
using System.ComponentModel;
using System.Reflection;

namespace BlockView.NET
{

    // A specialization of ToolStripMenuItem that can be used
    // to represent memberss of an enum type

    public class EnumToolStripMenuItem : ToolStripMenuItem
    {
        bool isFlag = false;
        long intval = 0L;

        EnumToolStripMenuItem( Enum value, EventHandler onClick )
            : base( GetItemText( value ) )
        {
            base.Tag = value;
            if( onClick != null )
                base.Click += onClick;
            isFlag = IsFlags( value.GetType() );
            intval = Convert.ToInt64( value );
        }

        public static EnumToolStripMenuItem[] CreateItems<T>() where T : struct 
        {
            return CreateItems( typeof(T), null );
        }

        public static EnumToolStripMenuItem[] CreateItems<T>( EventHandler onClick ) where T : struct
        {
            return CreateItems( typeof( T ), onClick );
        }

        public static EnumToolStripMenuItem[] CreateItems<T>( IEnumerable<T> items, EventHandler onClick ) where T : struct
        {
            return CreateItems( items.Cast<Enum>(), onClick );
        }

        public static EnumToolStripMenuItem[] CreateItems( Type enumType )
        {
            return CreateItems( enumType, null );
        }

        public static EnumToolStripMenuItem[] CreateItems( Type enumType, EventHandler onClick )
        {
            if( enumType == null )
                throw new ArgumentNullException( "enumType" );
            if( !enumType.IsEnum )
                throw new ArgumentException( "Requires an Enum type" );
            return CreateItems( Enum.GetValues( enumType ).Cast<Enum>().Distinct(), onClick );
        }

        // This override can be used to selectively add a specific set of members:
        public static EnumToolStripMenuItem[] CreateItems( IEnumerable<Enum> values, EventHandler onClick )
        {
            return values.Select( v => new EnumToolStripMenuItem( v, onClick ) ).ToArray();
        }

        public static void UpdateCheckedState( ToolStripItemCollection items, Enum value )
        {
            foreach( EnumToolStripMenuItem item in items.OfType<EnumToolStripMenuItem>() )
            {
                item.UpdateCheckedState( value );
            }
        }

        public void UpdateCheckedState( Enum value )
        {
            if( base.Tag != null && base.Tag.GetType() == value.GetType() )
            {
                Int64 flags = Convert.ToInt64( value );
                base.Checked = isFlag ? ( ( intval & flags ) == intval ) : intval == flags;
            }
        }

        static string GetItemText( Enum value )
        {
            FieldInfo fi = value.GetType().GetField( value.ToString() );
            if( fi != null )
            {
                DescriptionAttribute[] att = (DescriptionAttribute[])
                    fi.GetCustomAttributes( typeof( DescriptionAttribute ), false );
                if( att != null && att.Length > 0 )
                {
                    string desc = att[0].Description;
                    if( !string.IsNullOrEmpty( desc ) )
                        return desc;
                }
            }
            return value.ToString();
        }

        public Enum Value
        {
            get
            {
                return (Enum) base.Tag;
            }
        }

        public Int64 IntVal
        {
            get
            {
                return intval;
            }
        }

        static bool IsFlags( Type enumType )
        {
            var a = enumType.GetCustomAttributes( typeof( FlagsAttribute ), false );
            return a != null && a.Length > 0;
        }
    }

}

Helpers.cs

CSS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.IO;
using System.Diagnostics;
using System.Windows.Forms;

namespace BlockView.NET
{
    public static class BlockViewExtensionMethods
    {
        /// <summary>
        /// 
        /// This extension method can be called on any IEnumerable<T> 
        /// where the element type T implements the IDisposable interface.
        /// It's purpose is to guarantee the entire sequence is disposed
        /// even if an exception is thrown by the call to Dispose() on any
        /// element in the sequence.
        /// 
        /// </summary>

        public static void DisposeItems<T>( this IEnumerable<T> items ) where T : IDisposable
        {
            DisposeItems( items.GetEnumerator() );
        }

        static void DisposeItems( IEnumerator e ) 
        {
            while( e.MoveNext() )
            {
                try
                {
                    IDisposable disposable = e.Current as IDisposable;
                    if( disposable != null )
                        disposable.Dispose();
                }
                catch
                {
                    DisposeItems( e );
                    throw;
                }
            }

        }
    }

    /// <summary>
    ///
    /// [TT]: Detecting design-time execution:
    /// 
    /// The IsDesignMode method of this class should be used in preference
    /// to the DesignMode property of Control. The latter is only true when
    /// called on a control that is being designed. It is NOT true when it
    /// is called on an instance of a control that is a child of a control 
    /// that's being designed (e.g., the GsPreviewCtrl), or when called on 
    /// an instance of a base type of a control that is being designed.
    /// 
    /// For example, within the GsPreviewCtrl class, if the GsPreviewCtrl's
    /// DesignMode property is read when the BlockViewDialog is open in the 
    /// designer, it will return false because the GsPreviewCtrl is not what
    /// is being designed (the BlockViewDialog is what's being designed).
    /// 
    /// </summary>

    public static class Utils
    {
        static bool designMode = string.Equals(
            Path.GetFileNameWithoutExtension( Process.GetCurrentProcess().MainModule.FileName ),
            "devenv",
            StringComparison.OrdinalIgnoreCase );

        public static bool IsDesignMode( this Control control )
        {
            return designMode;
        }

        public static bool DesignMode
        {
            get
            {
                return designMode;
            }
        }
    }
}

image-20250415083021590

wpf相关处理

MainWindow.xaml

C#
<Window
    x:Class="WpfApp1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:WpfApp1"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:wf="clr-namespace:BlockView.NET;assembly=BlockView.NET"
    Title="MainWindow"
    Width="800"
    Height="450"
    mc:Ignorable="d">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="2*" />
        </Grid.ColumnDefinitions>
        <WindowsFormsHost
            Name="winFormsHost"
            Grid.RowSpan="2"
            Grid.Column="1">
            <wf:GsPreviewCtrl x:Name="blockView" />
        </WindowsFormsHost>
        <StackPanel Margin="10,20">
            <Button
                Name="btnLoad"
                Margin="0,5"
                Click="btnLoad_Click">
                Load
            </Button>
            <Button
                Name="btnSave"
                Margin="0,5"
                Click="BtnSave_Click">
                Save
            </Button>
            <Button
                Name="btnClear"
                Margin="0,5"
                Click="BtnClear_Click">
                Clear
            </Button>
        </StackPanel>
    </Grid>
</Window>

MainWindow.xaml.cs

C#
namespace WpfApp1
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        Document document;
        public MainWindow()
        {
            InitializeComponent();
            document = AcadApp.DocumentManager.MdiActiveDocument;
            blockView.Init(document, document.Database);
        }

        private void btnLoad_Click(object sender, RoutedEventArgs e)
        {
            //创建文件选择对话框选择dwg文件
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "dwg文件|*.dwg";
            if (openFileDialog.ShowDialog() == true)
            {
                //打开dwg文件
                Database dwg = new Database(false, true);
                // now read it in
                dwg.ReadDwgFile(openFileDialog.FileName, FileOpenMode.OpenForReadAndReadShare, true, "");
                // initialising the drawing control, pass the existing document still as the gs view still refers to it
                blockView.Init(document, dwg);
            }
        }
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {

        }

        private void BtnClear_Click(object sender, RoutedEventArgs e)
        {
            blockView.Init(document, document.Database);
        }
    }
}

image-20250415083557963

Text Only
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
    private void RubberRectangle(Point p1, Point p2)
    {
        Rectangle rc = new Rectangle();

        // Convert the points to screen coordinates.
        p1 = PointToScreen(p1);
        p2 = PointToScreen(p2);
        // Normalize the rectangle.
        if (p1.X < p2.X)
        {
            rc.X = p1.X;
            rc.Width = p2.X - p1.X;
        }
        else
        {
            rc.X = p2.X;
            rc.Width = p1.X - p2.X;
        }
        if (p1.Y < p2.Y)
        {
            rc.Y = p1.Y;
            rc.Height = p2.Y - p1.Y;
        }
        else
        {
            rc.Y = p2.Y;
            rc.Height = p1.Y - p2.Y;
        }
        // Draw the reversible frame.
        ControlPaint.DrawReversibleFrame(rc, Color.White, FrameStyle.Dashed);
    }

    // [TT]: Refactored to exclude AutoCAD types from methods that run in the designer:

    public void refreshView()
    {
        if (!IsDesignMode)
        {
            InternalRefreshView();
        }
    }

    // This method will never be jit'ed in the designer:

    void InternalRefreshView()
    {
        if (mpView != null)
        {
            mpView.Invalidate();
            mpView.Update();
        }
    }

    protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
    {
        base.OnPaint(e);
        refreshView();
    }

    // [TT]: Refactored to exclude AutoCAD types from methods that run in the designer:

    protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
    {
        base.OnMouseMove(e);
        if (!IsDesignMode)
        {
            InternalOnMouseMove(e);
        }
    }

    private void InternalOnMouseMove(System.Windows.Forms.MouseEventArgs e)
    {
        if (mpView != null)
        {
            if (mZooming)
            {
                // if left button is down
                if (mMouseDown)
                {
                    if (mMouseMoving)
                    {
                        // erase the old rectangle
                        RubberRectangle(mStartPoint, mEndPoint);
                    }
                    // draw the new rectangle
                    RubberRectangle(mStartPoint, e.Location);
                    mMouseMoving = true;
                    // save the new point for next time
                    mEndPoint = e.Location;
                }
            }
            else
            {
                if (mbPanning)
                {
                    //transform the point from device coordinates to
                    //world coordinates
                    Vector3d pan_vec = new Vector3d(-(e.Location.X - mStartPoint.X), e.Location.Y - mStartPoint.Y, 0);
                    /*pan_vec = */
                    pan_vec.TransformBy(mpView.ViewingMatrix * mpView.WorldToDeviceMatrix.Inverse());
                    mpView.Dolly(pan_vec);
                    refreshView();
                    mStartPoint = e.Location;
                }
                if (mbOrbiting)
                {
                    double Half_Pi = 1.570796326795;

                    System.Drawing.Rectangle view_rect = new System.Drawing.Rectangle((int)mpView.ViewportExtents.MinPoint.X, (int)mpView.ViewportExtents.MinPoint.Y,
                                                                           (int)(mpView.ViewportExtents.MaxPoint.X - mpView.ViewportExtents.MinPoint.X),
                                                                           (int)(mpView.ViewportExtents.MaxPoint.Y - mpView.ViewportExtents.MinPoint.Y));

                    int nViewportX = (view_rect.Right - view_rect.Left) + 1;
                    int nViewportY = (view_rect.Bottom - view_rect.Top) + 1;

                    int centerX = (int)(nViewportX / 2.0f + view_rect.Left);
                    int centerY = (int)(nViewportY / 2.0f + view_rect.Top);

                    double radius = System.Math.Min(nViewportX, nViewportY) * 0.4f;

                    // compute two vectors from last and new cursor positions:

                    Vector3d last_vector = new Vector3d((mStartPoint.X - centerX) / radius,
                         -(mStartPoint.Y - centerY) / radius,
                         0.0);
                    if (last_vector.LengthSqrd > 1.0)     // outside the radius
                    {
                        double x = last_vector.X / last_vector.Length;
                        double y = last_vector.Y / last_vector.Length;
                        double z = last_vector.Z / last_vector.Length;
                        last_vector = new Vector3d(x, y, z);

                    }
                    else
                    {
                        double x = last_vector.X;
                        double y = last_vector.Y;
                        double z = System.Math.Sqrt(1.0 - last_vector.X * last_vector.X - last_vector.Y * last_vector.Y);
                        last_vector = new Vector3d(x, y, z);
                    }

                    Vector3d new_vector = new Vector3d((e.Location.X - centerX) / radius, -(e.Location.Y - centerY) / radius, 0.0);

                    if (new_vector.LengthSqrd > 1.0)     // outside the radius
                    {
                        double x = new_vector.X / new_vector.Length;
                        double y = new_vector.Y / new_vector.Length;
                        double z = new_vector.Z / new_vector.Length;
                        new_vector = new Vector3d(x, y, z);

                    }
                    else
                    {
                        double x = new_vector.X;
                        double y = new_vector.Y;
                        double z = System.Math.Sqrt(1.0 - new_vector.X * new_vector.X - new_vector.Y * new_vector.Y);
                        new_vector = new Vector3d(x, y, z);
                    }

                    // determine angles for proper sequence of camera manipulations:

                    Vector3d rotation_vector = last_vector;
                    rotation_vector = rotation_vector.CrossProduct(new_vector);  // rotation_vector = last_vector x new_vector

                    Vector3d work_vector = rotation_vector;
                    work_vector = new Vector3d(work_vector.X, work_vector.Y, 0.0f);                      // projection of rotation_vector onto xy plane

                    double roll_angle = System.Math.Atan2(work_vector.X,
                         work_vector.Y);        // assuming that the camera's up vector is "up",
                                                // this computes the angle between the up vector 
                                                // and the work vector, which is the roll required
                                                // to make the up vector coincident with the rotation_vector
                    double length = rotation_vector.Length;
                    double orbit_y_angle = (length != 0.0) ? System.Math.Acos(rotation_vector.Z / length) + Half_Pi : Half_Pi;                   // represents inverse cosine of the dot product of the
                    if (length > 1.0f)                                              // rotation_vector and the up_vector divided by the
                        length = 1.0f;                                              // magnitude of both vectors.  We add pi/2 because we 
                                                                                    // are making the up-vector parallel to the the rotation
                    double rotation_angle = System.Math.Asin(length);                // vector ... up-vector is perpin. to the eye-vector.

                    // perform view manipulations

                    mpView.Roll(roll_angle);               // 1: roll camera to make up vector coincident with rotation vector
                    mpView.Orbit(0.0f, orbit_y_angle);     // 2: orbit along y to make up vector parallel with rotation vector
                    mpView.Orbit(rotation_angle, 0.0f);     // 3: orbit along x by rotation angle
                    mpView.Orbit(0.0f, -orbit_y_angle);     // 4: orbit along y by the negation of 2
                    mpView.Roll(-roll_angle);               // 5: roll camera by the negation of 1
                    refreshView();
                    mStartPoint = e.Location;
                }
            }
        }
    }
    public void SetViewTo(ZwSoft.ZwCAD.GraphicsSystem.View view, Database db)
    {
        // just check we have valid extents
        if (db.Extmax.X < db.Extmin.X || db.Extmax.Y < db.Extmin.Y || db.Extmax.Z < db.Extmax.Z)
        {
            db.Extmin = new Point3d(0, 0, 0);
            db.Extmax = new Point3d(400, 400, 400);
        }
        // get the dwg extents
        Point3d extMax = db.Extmax;
        Point3d extMin = db.Extmin;
        // now the active viewport info
        double height = 0.0, width = 0.0, viewTwist = 0.0;
        Point3d targetView = new Point3d();
        Vector3d viewDir = new Vector3d();
        GSUtil.GetActiveViewPortInfo(ref height, ref width, ref targetView, ref viewDir, ref viewTwist, true);
        // from the data returned let's work out the viewmatrix
        viewDir = viewDir.GetNormal();
        Vector3d viewXDir = viewDir.GetPerpendicularVector().GetNormal();
        viewXDir = viewXDir.RotateBy(viewTwist, -viewDir);
        Vector3d viewYDir = viewDir.CrossProduct(viewXDir);
        Point3d boxCenter = extMin + 0.5 * (extMax - extMin);
        Matrix3d viewMat;
        viewMat = Matrix3d.AlignCoordinateSystem(boxCenter, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis,
          boxCenter, viewXDir, viewYDir, viewDir).Inverse();
        Extents3d wcsExtents = new Extents3d(extMin, extMax);
        Extents3d viewExtents = wcsExtents;
        viewExtents.TransformBy(viewMat);
        double xMax = System.Math.Abs(viewExtents.MaxPoint.X - viewExtents.MinPoint.X);
        double yMax = System.Math.Abs(viewExtents.MaxPoint.Y - viewExtents.MinPoint.Y);
        Point3d eye = boxCenter + viewDir;
        // finally set the Gs view to the dwg view
        view.SetView(eye, boxCenter, viewYDir, xMax, yMax);

        // now update
        refreshView();
    }

    // [TT]: Refactored to exclude AutoCAD types from methods that run in the designer:
    protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
    {
        base.OnMouseDown(e);
        if (!IsDesignMode)
        {
            InternalOnMouseDown(e);
        }
    }

    private void InternalOnMouseDown(System.Windows.Forms.MouseEventArgs e)
    {
        if (mpView != null)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                // if zooming
                if (mZooming)
                {
                    mMouseDown = true;
                    mMouseMoving = false;
                }
                else
                {
                    mbOrbiting = true;
                    this.Focus();
                }

            }
            else if (e.Button == System.Windows.Forms.MouseButtons.Middle)
            {
                mbPanning = true;
            }
            mStartPoint = e.Location;
        }
    }

    // [TT]: Refactored to exclude AutoCAD types from methods that run in the designer:
    protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
    {
        base.OnMouseUp(e);
        if (!IsDesignMode)
        {
            InternalOnMouseUp(e);
        }
    }

    private void InternalOnMouseUp(System.Windows.Forms.MouseEventArgs e)
    {
        if (mpView != null)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                if (mZooming && mMouseDown)
                {
                    // end zoom
                    mZooming = false;
                    mMouseDown = false;
                    mMouseMoving = false;


                    mpView.ZoomWindow(new Point2d(mStartPoint.X, this.Bottom - mStartPoint.Y), new Point2d(mEndPoint.X, this.Bottom - mEndPoint.Y));

                    refreshView();
                }
                else
                {
                    mbOrbiting = false;
                }
            }
            else if (e.Button == System.Windows.Forms.MouseButtons.Middle)
            {
                mbPanning = false;
            }
        }
    }

    // [TT]: Refactored to exclude AutoCAD types from methods that run in the designer:
    protected override void OnSizeChanged(EventArgs e)
    {
        base.OnSizeChanged(e);

        /// No AutoCAD types can be in this method, so we've
        /// moved the following code to another method which
        /// appears below, and only call that method when not 
        /// running in the designer:

        //if( mpDevice != null )
        //{
        //   mpDevice.OnSize( this.Size );
        //}

        if (!IsDesignMode)
        {
            InternalOnSizeChanged();
        }
    }

    // This method will never be jit'ed in the designer
    void InternalOnSizeChanged()
    {
        if (!(mpDevice is null))
        {
            mpDevice.OnSize(this.Size);
        }
    }
}

/// <summary>
/// [TT]: Depreciated (using ControlPaint.DrawReversibleFrame() instead)
/// </summary>

public class GSUtil
{
    public const String strActive = "*Active";
    public const String strActiveSettings = "ACAD_RENDER_ACTIVE_SETTINGS";
    public static void CustomUpdate(System.IntPtr parmeter, int left, int right, int bottom, int top)
    {
        MessageBox.Show("Left:" + left + "Right" + right + "Bottom" + bottom + "Top" + top);
    }
    public static System.Drawing.Color[] MyAcadColorPs =
{
  System.Drawing.Color.FromArgb(255, 0, 0, 255),    //----- 0 - lets make it red for an example
  //{255, 255, 255, 255},//----- 0 - ByBlock - White
  System.Drawing.Color.FromArgb(255, 0, 0, 255),    //----- 1 - Red 
  System.Drawing.Color.FromArgb(255, 255, 0, 255),    //----- 2 - Yellow
  System.Drawing.Color.FromArgb(0, 255, 0, 255),    //----- 3 - Green
  System.Drawing.Color.FromArgb(0, 255, 255, 255),    //----- 4 - Cyan
  System.Drawing.Color.FromArgb(0, 0, 255, 255),    //----- 5 - Blue
  System.Drawing.Color.FromArgb(255, 0, 255, 255),    //----- 6 - Magenta
  System.Drawing.Color.FromArgb(255, 0, 0, 255),    //----- 7 - More red Red 
  System.Drawing.Color.FromArgb(255, 0, 0, 255),    //----- 8 - More red Red 
  System.Drawing.Color.FromArgb(255, 0, 0, 255),    //----- 9 - More red Red 
  /*System.Drawing.Color.FromArgb(255, 255, 255, 255),//----- 7 - White
  System.Drawing.Color.FromArgb(255, 255, 255, 255),//----- 8
  System.Drawing.Color.FromArgb(255, 255, 255, 255),//----- 9*/
  System.Drawing.Color.FromArgb(255, 0, 0, 255),    //----- 10
  System.Drawing.Color.FromArgb(255, 127, 127, 255),//----- 11
  System.Drawing.Color.FromArgb(165, 0, 0, 255),    //----- 12
  System.Drawing.Color.FromArgb(165, 82, 82, 255),    //----- 13
  System.Drawing.Color.FromArgb(127, 0, 0, 255),    //----- 14
  System.Drawing.Color.FromArgb(127, 63, 63, 255),    //----- 15
  System.Drawing.Color.FromArgb(76, 0, 0, 255),        //----- 16
  System.Drawing.Color.FromArgb(76, 38, 38, 255),    //----- 17
  System.Drawing.Color.FromArgb(38, 0, 0, 255),        //----- 18
  System.Drawing.Color.FromArgb(38, 19, 19, 255),    //----- 19
  System.Drawing.Color.FromArgb(255, 63, 0, 255),    //----- 20
  System.Drawing.Color.FromArgb(255, 159, 127, 255),//----- 21
  System.Drawing.Color.FromArgb(165, 41, 0, 255),    //----- 22
  System.Drawing.Color.FromArgb(165, 103, 82, 255),    //----- 23
  System.Drawing.Color.FromArgb(127, 31, 0, 255),    //----- 24
  System.Drawing.Color.FromArgb(127, 79, 63, 255),    //----- 25
  System.Drawing.Color.FromArgb(76, 19, 0, 255),    //----- 26
  System.Drawing.Color.FromArgb(76, 47, 38, 255),    //----- 27
  System.Drawing.Color.FromArgb(38, 9, 0, 255),        //----- 28
  System.Drawing.Color.FromArgb(38, 23, 19, 255),    //----- 29
  System.Drawing.Color.FromArgb(255, 127, 0, 255),    //----- 30
  System.Drawing.Color.FromArgb(255, 191, 127, 255),//----- 31
  System.Drawing.Color.FromArgb(165, 82, 0, 255),    //----- 32
  System.Drawing.Color.FromArgb(165, 124, 82, 255),    //----- 33
  System.Drawing.Color.FromArgb(127, 63, 0, 255),    //----- 34
  System.Drawing.Color.FromArgb(127, 95, 63, 255),    //----- 35
  System.Drawing.Color.FromArgb(76, 38, 0, 255),    //----- 36
  System.Drawing.Color.FromArgb(76, 57, 38, 255),    //----- 37
  System.Drawing.Color.FromArgb(38, 19, 0, 255),    //----- 38
  System.Drawing.Color.FromArgb(38, 28, 19, 255),    //----- 39
  System.Drawing.Color.FromArgb(255, 191, 0, 255),    //----- 40
  System.Drawing.Color.FromArgb(255, 223, 127, 255),//----- 41
  System.Drawing.Color.FromArgb(165, 124, 0, 255),    //----- 42
  System.Drawing.Color.FromArgb(165, 145, 82, 255),    //----- 43
  System.Drawing.Color.FromArgb(127, 95, 0, 255),    //----- 44
  System.Drawing.Color.FromArgb(127, 111, 63, 255),    //----- 45
  System.Drawing.Color.FromArgb(76, 57, 0, 255),    //----- 46
  System.Drawing.Color.FromArgb(76, 66, 38, 255),    //----- 47
  System.Drawing.Color.FromArgb(38, 28, 0, 255),    //----- 48
  System.Drawing.Color.FromArgb(38, 33, 19, 255),    //----- 49
  System.Drawing.Color.FromArgb(255, 255, 0, 255),    //----- 50
  System.Drawing.Color.FromArgb(255, 255, 127, 255),//----- 51
  System.Drawing.Color.FromArgb(165, 165, 0, 255),    //----- 52
  System.Drawing.Color.FromArgb(165, 165, 82, 255),    //----- 53
  System.Drawing.Color.FromArgb(127, 127, 0, 255),    //----- 54
  System.Drawing.Color.FromArgb(127, 127, 63, 255),    //----- 55
  System.Drawing.Color.FromArgb(76, 76, 0, 255),    //----- 56
  System.Drawing.Color.FromArgb(76, 76, 38, 255),    //----- 57
  System.Drawing.Color.FromArgb(38, 38, 0, 255),    //----- 58
  System.Drawing.Color.FromArgb(38, 38, 19, 255),    //----- 59
  System.Drawing.Color.FromArgb(191, 255, 0, 255),    //----- 60
  System.Drawing.Color.FromArgb(223, 255, 127, 255),//----- 61
  System.Drawing.Color.FromArgb(124, 165, 0, 255),    //----- 62
  System.Drawing.Color.FromArgb(145, 165, 82, 255),    //----- 63
  System.Drawing.Color.FromArgb(95, 127, 0, 255),    //----- 64
  System.Drawing.Color.FromArgb(111, 127, 63, 255),    //----- 65
  System.Drawing.Color.FromArgb(57, 76, 0, 255),    //----- 66
  System.Drawing.Color.FromArgb(66, 76, 38, 255),    //----- 67
  System.Drawing.Color.FromArgb(28, 38, 0, 255),    //----- 68
  System.Drawing.Color.FromArgb(33, 38, 19, 255),    //----- 69
  System.Drawing.Color.FromArgb(127, 255, 0, 255),    //----- 70
  System.Drawing.Color.FromArgb(191, 255, 127, 255),//----- 71
  System.Drawing.Color.FromArgb(82, 165, 0, 255),    //----- 72
  System.Drawing.Color.FromArgb(124, 165, 82, 255),    //----- 73
  System.Drawing.Color.FromArgb(63, 127, 0, 255),    //----- 74
  System.Drawing.Color.FromArgb(95, 127, 63, 255),    //----- 75
  System.Drawing.Color.FromArgb(38, 76, 0, 255),    //----- 76
  System.Drawing.Color.FromArgb(57, 76, 38, 255),    //----- 77
  System.Drawing.Color.FromArgb(19, 38, 0, 255),    //----- 78
  System.Drawing.Color.FromArgb(28, 38, 19, 255),    //----- 79
  System.Drawing.Color.FromArgb(63, 255, 0, 255),    //----- 80
  System.Drawing.Color.FromArgb(159, 255, 127, 255),//----- 81
  System.Drawing.Color.FromArgb(41, 165, 0, 255),    //----- 82
  System.Drawing.Color.FromArgb(103, 165, 82, 255),    //----- 83
  System.Drawing.Color.FromArgb(31, 127, 0, 255),    //----- 84
  System.Drawing.Color.FromArgb(79, 127, 63, 255),    //----- 85
  System.Drawing.Color.FromArgb(19, 76, 0, 255),    //----- 86
  System.Drawing.Color.FromArgb(47, 76, 38, 255),    //----- 87
  System.Drawing.Color.FromArgb(9, 38, 0, 255),        //----- 88
  System.Drawing.Color.FromArgb(23, 38, 19, 255),    //----- 89
  System.Drawing.Color.FromArgb(0, 255, 0, 255),    //----- 90
  System.Drawing.Color.FromArgb(127, 255, 127, 255),//----- 91
  System.Drawing.Color.FromArgb(0, 165, 0, 255),    //----- 92
  System.Drawing.Color.FromArgb(82, 165, 82, 255),    //----- 93
  System.Drawing.Color.FromArgb(0, 127, 0, 255),    //----- 94
  System.Drawing.Color.FromArgb(63, 127, 63, 255),    //----- 95
  System.Drawing.Color.FromArgb(0, 76, 0, 255),        //----- 96
  System.Drawing.Color.FromArgb(38, 76, 38, 255),    //----- 97
  System.Drawing.Color.FromArgb(0, 38, 0, 255),        //----- 98
  System.Drawing.Color.FromArgb(19, 38, 19, 255),    //----- 99
  System.Drawing.Color.FromArgb(0, 255, 63, 255),    //----- 100
  System.Drawing.Color.FromArgb(127, 255, 159, 255),//----- 101
  System.Drawing.Color.FromArgb(0, 165, 41, 255),    //----- 102
  System.Drawing.Color.FromArgb(82, 165, 103, 255),    //----- 103
  System.Drawing.Color.FromArgb(0, 127, 31, 255),    //----- 104
  System.Drawing.Color.FromArgb(63, 127, 79, 255),    //----- 105
  System.Drawing.Color.FromArgb(0, 76, 19, 255),    //----- 106
  System.Drawing.Color.FromArgb(38, 76, 47, 255),    //----- 107
  System.Drawing.Color.FromArgb(0, 38, 9, 255),        //----- 108
  System.Drawing.Color.FromArgb(19, 38, 23, 255),    //----- 109
  System.Drawing.Color.FromArgb(0, 255, 127, 255),    //----- 110
  System.Drawing.Color.FromArgb(127, 255, 191, 255),//----- 111
  System.Drawing.Color.FromArgb(0, 165, 82, 255),    //----- 112
  System.Drawing.Color.FromArgb(82, 165, 124, 255),    //----- 113
  System.Drawing.Color.FromArgb(0, 127, 63, 255),    //----- 114
  System.Drawing.Color.FromArgb(63, 127, 95, 255),    //----- 115
  System.Drawing.Color.FromArgb(0, 76, 38, 255),    //----- 116
  System.Drawing.Color.FromArgb(38, 76, 57, 255),    //----- 117
  System.Drawing.Color.FromArgb(0, 38, 19, 255),    //----- 118
  System.Drawing.Color.FromArgb(19, 38, 28, 255),    //----- 119
  System.Drawing.Color.FromArgb(0, 255, 191, 255),    //----- 120
  System.Drawing.Color.FromArgb(127, 255, 223, 255),//----- 121
  System.Drawing.Color.FromArgb(0, 165, 124, 255),    //----- 122
  System.Drawing.Color.FromArgb(82, 165, 145, 255),    //----- 123
  System.Drawing.Color.FromArgb(0, 127, 95, 255),    //----- 124
  System.Drawing.Color.FromArgb(63, 127, 111, 255),    //----- 125
  System.Drawing.Color.FromArgb(0, 76, 57, 255),    //----- 126
  System.Drawing.Color.FromArgb(38, 76, 66, 255),    //----- 127
  System.Drawing.Color.FromArgb(0, 38, 28, 255),    //----- 128
  System.Drawing.Color.FromArgb(19, 38, 33, 255),    //----- 129
  System.Drawing.Color.FromArgb(0, 255, 255, 255),    //----- 130
  System.Drawing.Color.FromArgb(127, 255, 255, 255),//----- 131
  System.Drawing.Color.FromArgb(0, 165, 165, 255),    //----- 132
  System.Drawing.Color.FromArgb(82, 165, 165, 255),    //----- 133
  System.Drawing.Color.FromArgb(0, 127, 127, 255),    //----- 134
  System.Drawing.Color.FromArgb(63, 127, 127, 255),    //----- 135
  System.Drawing.Color.FromArgb(0, 76, 76, 255),    //----- 136
  System.Drawing.Color.FromArgb(38, 76, 76, 255),    //----- 137
  System.Drawing.Color.FromArgb(0, 38, 38, 255),    //----- 138
  System.Drawing.Color.FromArgb(19, 38, 38, 255),    //----- 139
  System.Drawing.Color.FromArgb(0, 191, 255, 255),    //----- 140
  System.Drawing.Color.FromArgb(127, 223, 255, 255),//----- 141
  System.Drawing.Color.FromArgb(0, 124, 165, 255),    //----- 142
  System.Drawing.Color.FromArgb(82, 145, 165, 255),    //----- 143
  System.Drawing.Color.FromArgb(0, 95, 127, 255),    //----- 144
  System.Drawing.Color.FromArgb(63, 111, 127, 255),    //----- 145
  System.Drawing.Color.FromArgb(0, 57, 76, 255),    //----- 146
  System.Drawing.Color.FromArgb(38, 66, 76, 255),    //----- 147
  System.Drawing.Color.FromArgb(0, 28, 38, 255),    //----- 148
  System.Drawing.Color.FromArgb(19, 33, 38, 255),    //----- 149
  System.Drawing.Color.FromArgb(0, 127, 255, 255),    //----- 150
  System.Drawing.Color.FromArgb(127, 191, 255, 255),//----- 151
  System.Drawing.Color.FromArgb(0, 82, 165, 255),    //----- 152
  System.Drawing.Color.FromArgb(82, 124, 165, 255),    //----- 153
  System.Drawing.Color.FromArgb(0, 63, 127, 255),    //----- 154
  System.Drawing.Color.FromArgb(63, 95, 127, 255),    //----- 155
  System.Drawing.Color.FromArgb(0, 38, 76, 255),    //----- 156
  System.Drawing.Color.FromArgb(38, 57, 76, 255),    //----- 157
  System.Drawing.Color.FromArgb(0, 19, 38, 255),    //----- 158
  System.Drawing.Color.FromArgb(19, 28, 38, 255),    //----- 159
  System.Drawing.Color.FromArgb(0, 63, 255, 255),    //----- 160
  System.Drawing.Color.FromArgb(127, 159, 255, 255),//----- 161
  System.Drawing.Color.FromArgb(0, 41, 165, 255),    //----- 162
  System.Drawing.Color.FromArgb(82, 103, 165, 255),    //----- 163
  System.Drawing.Color.FromArgb(0, 31, 127, 255),    //----- 164
  System.Drawing.Color.FromArgb(63, 79, 127, 255),    //----- 165
  System.Drawing.Color.FromArgb(0, 19, 76, 255),    //----- 166
  System.Drawing.Color.FromArgb(38, 47, 76, 255),    //----- 167
  System.Drawing.Color.FromArgb(0, 9, 38, 255),        //----- 168
  System.Drawing.Color.FromArgb(19, 23, 38, 255),    //----- 169
  System.Drawing.Color.FromArgb(0, 0, 255, 255),    //----- 170
  System.Drawing.Color.FromArgb(127, 127, 255, 255),//----- 171
  System.Drawing.Color.FromArgb(0, 0, 165, 255),    //----- 172
  System.Drawing.Color.FromArgb(82, 82, 165, 255),    //----- 173
  System.Drawing.Color.FromArgb(0, 0, 127, 255),    //----- 174
  System.Drawing.Color.FromArgb(63, 63, 127, 255),    //----- 175
  System.Drawing.Color.FromArgb(0, 0, 76, 255),        //----- 176
  System.Drawing.Color.FromArgb(38, 38, 76, 255),    //----- 177
  System.Drawing.Color.FromArgb(0, 0, 38, 255),        //----- 178
  System.Drawing.Color.FromArgb(19, 19, 38, 255),    //----- 179
  System.Drawing.Color.FromArgb(63, 0, 255, 255),    //----- 180
  System.Drawing.Color.FromArgb(159, 127, 255, 255),//----- 181
  System.Drawing.Color.FromArgb(41, 0, 165, 255),    //----- 182
  System.Drawing.Color.FromArgb(103, 82, 165, 255),    //----- 183
  System.Drawing.Color.FromArgb(31, 0, 127, 255),    //----- 184
  System.Drawing.Color.FromArgb(79, 63, 127, 255),    //----- 185
  System.Drawing.Color.FromArgb(19, 0, 76, 255),    //----- 186
  System.Drawing.Color.FromArgb(47, 38, 76, 255),    //----- 187
  System.Drawing.Color.FromArgb(9, 0, 38, 255),        //----- 188
  System.Drawing.Color.FromArgb(23, 19, 38, 255),    //----- 189
  System.Drawing.Color.FromArgb(127, 0, 255, 255),    //----- 190
  System.Drawing.Color.FromArgb(191, 127, 255, 255),//----- 191
  System.Drawing.Color.FromArgb(82, 0, 165, 255),    //----- 192
  System.Drawing.Color.FromArgb(124, 82, 165, 255),    //----- 193
  System.Drawing.Color.FromArgb(63, 0, 127, 255),    //----- 194
  System.Drawing.Color.FromArgb(95, 63, 127, 255),    //----- 195
  System.Drawing.Color.FromArgb(38, 0, 76, 255),    //----- 196
  System.Drawing.Color.FromArgb(57, 38, 76, 255),    //----- 197
  System.Drawing.Color.FromArgb(19, 0, 38, 255),    //----- 198
  System.Drawing.Color.FromArgb(28, 19, 38, 255),    //----- 199
  System.Drawing.Color.FromArgb(191, 0, 255, 255),    //----- 200
  System.Drawing.Color.FromArgb(223, 127, 255, 255),//----- 201
  System.Drawing.Color.FromArgb(124, 0, 165, 255),    //----- 202
  System.Drawing.Color.FromArgb(145, 82, 165, 255),    //----- 203
  System.Drawing.Color.FromArgb(95, 0, 127, 255),    //----- 204
  System.Drawing.Color.FromArgb(111, 63, 127, 255),    //----- 205
  System.Drawing.Color.FromArgb(57, 0, 76, 255),    //----- 206
  System.Drawing.Color.FromArgb(66, 38, 76, 255),    //----- 207
  System.Drawing.Color.FromArgb(28, 0, 38, 255),    //----- 208
  System.Drawing.Color.FromArgb(33, 19, 38, 255),    //----- 209
  System.Drawing.Color.FromArgb(255, 0, 255, 255),    //----- 210
  System.Drawing.Color.FromArgb(255, 127, 255, 255),//----- 211
  System.Drawing.Color.FromArgb(165, 0, 165, 255),    //----- 212
  System.Drawing.Color.FromArgb(165, 82, 165, 255),    //----- 213
  System.Drawing.Color.FromArgb(127, 0, 127, 255),    //----- 214
  System.Drawing.Color.FromArgb(127, 63, 127, 255),    //----- 215
  System.Drawing.Color.FromArgb(76, 0, 76, 255),    //----- 216
  System.Drawing.Color.FromArgb(76, 38, 76, 255),    //----- 217
  System.Drawing.Color.FromArgb(38, 0, 38, 255),    //----- 218
  System.Drawing.Color.FromArgb(38, 19, 38, 255),    //----- 219
  System.Drawing.Color.FromArgb(255, 0, 191, 255),    //----- 220
  System.Drawing.Color.FromArgb(255, 127, 223, 255),//----- 221
  System.Drawing.Color.FromArgb(165, 0, 124, 255),    //----- 222
  System.Drawing.Color.FromArgb(165, 82, 145, 255),    //----- 223
  System.Drawing.Color.FromArgb(127, 0, 95, 255),    //----- 224
  System.Drawing.Color.FromArgb(127, 63, 111, 255),    //----- 225
  System.Drawing.Color.FromArgb(76, 0, 57, 255),    //----- 226
  System.Drawing.Color.FromArgb(76, 38, 66, 255),    //----- 227
  System.Drawing.Color.FromArgb(38, 0, 28, 255),    //----- 228
  System.Drawing.Color.FromArgb(38, 19, 33, 255),    //----- 229
  System.Drawing.Color.FromArgb(255, 0, 127, 255),    //----- 230
  System.Drawing.Color.FromArgb(255, 127, 191, 255),//----- 231
  System.Drawing.Color.FromArgb(165, 0, 82, 255),    //----- 232
  System.Drawing.Color.FromArgb(165, 82, 124, 255),    //----- 233
  System.Drawing.Color.FromArgb(127, 0, 63, 255),    //----- 234
  System.Drawing.Color.FromArgb(127, 63, 95, 255),    //----- 235
  System.Drawing.Color.FromArgb(76, 0, 38, 255),    //----- 236
  System.Drawing.Color.FromArgb(76, 38, 57, 255),    //----- 237
  System.Drawing.Color.FromArgb(38, 0, 19, 255),    //----- 238
  System.Drawing.Color.FromArgb(38, 19, 28, 255),    //----- 239
  System.Drawing.Color.FromArgb(255, 0, 63, 255),    //----- 240
  System.Drawing.Color.FromArgb(255, 127, 159, 255),//----- 241
  System.Drawing.Color.FromArgb(165, 0, 41, 255),    //----- 242
  System.Drawing.Color.FromArgb(165, 82, 103, 255),    //----- 243
  System.Drawing.Color.FromArgb(127, 0, 31, 255),    //----- 244
  System.Drawing.Color.FromArgb(127, 63, 79, 255),    //----- 245
  System.Drawing.Color.FromArgb(76, 0, 19, 255),    //----- 246
  System.Drawing.Color.FromArgb(76, 38, 47, 255),    //----- 247
  System.Drawing.Color.FromArgb(38, 0, 9, 255),        //----- 248
  System.Drawing.Color.FromArgb(38, 19, 23, 255),    //----- 249
  System.Drawing.Color.FromArgb(84, 84, 84, 255),    //----- 250
  System.Drawing.Color.FromArgb(118, 118, 118, 255),//----- 251
  System.Drawing.Color.FromArgb(152, 152, 152, 255),//----- 252
  System.Drawing.Color.FromArgb(186, 186, 186, 255),//----- 253
  System.Drawing.Color.FromArgb(220, 220, 220, 255),//----- 254
  System.Drawing.Color.FromArgb(255, 255, 255, 255),//----- 255
};

    //////////////////////////////////////////////////////////////////////////////
    // standard autocad colours
    public static System.Drawing.Color[] MyAcadColorMs =
{
  System.Drawing.Color.FromArgb(255, 255, 255, 255),//----- 0 - ByBlock - White
  System.Drawing.Color.FromArgb(255, 0, 0, 255),    //----- 1 - Red 
  System.Drawing.Color.FromArgb(255, 255, 0, 255),    //----- 2 - Yellow
  System.Drawing.Color.FromArgb(0, 255, 0, 255),    //----- 3 - Green
  System.Drawing.Color.FromArgb(0, 255, 255, 255),    //----- 4 - Cyan
  System.Drawing.Color.FromArgb(0, 0, 255, 255),    //----- 5 - Blue
  System.Drawing.Color.FromArgb(255, 0, 255, 255),    //----- 6 - Magenta
  System.Drawing.Color.FromArgb(255, 255, 255, 255),//----- 7 - White
  System.Drawing.Color.FromArgb(255, 255, 255, 255),//----- 8
  System.Drawing.Color.FromArgb(255, 255, 255, 255),//----- 9
  System.Drawing.Color.FromArgb(255, 0, 0, 255),    //----- 10
  System.Drawing.Color.FromArgb(255, 127, 127, 255),//----- 11
  System.Drawing.Color.FromArgb(165, 0, 0, 255),    //----- 12
  System.Drawing.Color.FromArgb(165, 82, 82, 255),    //----- 13
  System.Drawing.Color.FromArgb(127, 0, 0, 255),    //----- 14
  System.Drawing.Color.FromArgb(127, 63, 63, 255),    //----- 15
  System.Drawing.Color.FromArgb(76, 0, 0, 255),        //----- 16
  System.Drawing.Color.FromArgb(76, 38, 38, 255),    //----- 17
  System.Drawing.Color.FromArgb(38, 0, 0, 255),        //----- 18
  System.Drawing.Color.FromArgb(38, 19, 19, 255),    //----- 19
  System.Drawing.Color.FromArgb(255, 63, 0, 255),    //----- 20
  System.Drawing.Color.FromArgb(255, 159, 127, 255),//----- 21
  System.Drawing.Color.FromArgb(165, 41, 0, 255),    //----- 22
  System.Drawing.Color.FromArgb(165, 103, 82, 255),    //----- 23
  System.Drawing.Color.FromArgb(127, 31, 0, 255),    //----- 24
  System.Drawing.Color.FromArgb(127, 79, 63, 255),    //----- 25
  System.Drawing.Color.FromArgb(76, 19, 0, 255),    //----- 26
  System.Drawing.Color.FromArgb(76, 47, 38, 255),    //----- 27
  System.Drawing.Color.FromArgb(38, 9, 0, 255),        //----- 28
  System.Drawing.Color.FromArgb(38, 23, 19, 255),    //----- 29
  System.Drawing.Color.FromArgb(255, 127, 0, 255),    //----- 30
  System.Drawing.Color.FromArgb(255, 191, 127, 255),//----- 31
  System.Drawing.Color.FromArgb(165, 82, 0, 255),    //----- 32
  System.Drawing.Color.FromArgb(165, 124, 82, 255),    //----- 33
  System.Drawing.Color.FromArgb(127, 63, 0, 255),    //----- 34
  System.Drawing.Color.FromArgb(127, 95, 63, 255),    //----- 35
  System.Drawing.Color.FromArgb(76, 38, 0, 255),    //----- 36
  System.Drawing.Color.FromArgb(76, 57, 38, 255),    //----- 37
  System.Drawing.Color.FromArgb(38, 19, 0, 255),    //----- 38
  System.Drawing.Color.FromArgb(38, 28, 19, 255),    //----- 39
  System.Drawing.Color.FromArgb(255, 191, 0, 255),    //----- 40
  System.Drawing.Color.FromArgb(255, 223, 127, 255),//----- 41
  System.Drawing.Color.FromArgb(165, 124, 0, 255),    //----- 42
  System.Drawing.Color.FromArgb(165, 145, 82, 255),    //----- 43
  System.Drawing.Color.FromArgb(127, 95, 0, 255),    //----- 44
  System.Drawing.Color.FromArgb(127, 111, 63, 255),    //----- 45
  System.Drawing.Color.FromArgb(76, 57, 0, 255),    //----- 46
  System.Drawing.Color.FromArgb(76, 66, 38, 255),    //----- 47
  System.Drawing.Color.FromArgb(38, 28, 0, 255),    //----- 48
  System.Drawing.Color.FromArgb(38, 33, 19, 255),    //----- 49
  System.Drawing.Color.FromArgb(255, 255, 0, 255),    //----- 50
  System.Drawing.Color.FromArgb(255, 255, 127, 255),//----- 51
  System.Drawing.Color.FromArgb(165, 165, 0, 255),    //----- 52
  System.Drawing.Color.FromArgb(165, 165, 82, 255),    //----- 53
  System.Drawing.Color.FromArgb(127, 127, 0, 255),    //----- 54
  System.Drawing.Color.FromArgb(127, 127, 63, 255),    //----- 55
  System.Drawing.Color.FromArgb(76, 76, 0, 255),    //----- 56
  System.Drawing.Color.FromArgb(76, 76, 38, 255),    //----- 57
  System.Drawing.Color.FromArgb(38, 38, 0, 255),    //----- 58
  System.Drawing.Color.FromArgb(38, 38, 19, 255),    //----- 59
  System.Drawing.Color.FromArgb(191, 255, 0, 255),    //----- 60
  System.Drawing.Color.FromArgb(223, 255, 127, 255),//----- 61
  System.Drawing.Color.FromArgb(124, 165, 0, 255),    //----- 62
  System.Drawing.Color.FromArgb(145, 165, 82, 255),    //----- 63
  System.Drawing.Color.FromArgb(95, 127, 0, 255),    //----- 64
  System.Drawing.Color.FromArgb(111, 127, 63, 255),    //----- 65
  System.Drawing.Color.FromArgb(57, 76, 0, 255),    //----- 66
  System.Drawing.Color.FromArgb(66, 76, 38, 255),    //----- 67
  System.Drawing.Color.FromArgb(28, 38, 0, 255),    //----- 68
  System.Drawing.Color.FromArgb(33, 38, 19, 255),    //----- 69
  System.Drawing.Color.FromArgb(127, 255, 0, 255),    //----- 70
  System.Drawing.Color.FromArgb(191, 255, 127, 255),//----- 71
  System.Drawing.Color.FromArgb(82, 165, 0, 255),    //----- 72
  System.Drawing.Color.FromArgb(124, 165, 82, 255),    //----- 73
  System.Drawing.Color.FromArgb(63, 127, 0, 255),    //----- 74
  System.Drawing.Color.FromArgb(95, 127, 63, 255),    //----- 75
  System.Drawing.Color.FromArgb(38, 76, 0, 255),    //----- 76
  System.Drawing.Color.FromArgb(57, 76, 38, 255),    //----- 77
  System.Drawing.Color.FromArgb(19, 38, 0, 255),    //----- 78
  System.Drawing.Color.FromArgb(28, 38, 19, 255),    //----- 79
  System.Drawing.Color.FromArgb(63, 255, 0, 255),    //----- 80
  System.Drawing.Color.FromArgb(159, 255, 127, 255),//----- 81
  System.Drawing.Color.FromArgb(41, 165, 0, 255),    //----- 82
  System.Drawing.Color.FromArgb(103, 165, 82, 255),    //----- 83
  System.Drawing.Color.FromArgb(31, 127, 0, 255),    //----- 84
  System.Drawing.Color.FromArgb(79, 127, 63, 255),    //----- 85
  System.Drawing.Color.FromArgb(19, 76, 0, 255),    //----- 86
  System.Drawing.Color.FromArgb(47, 76, 38, 255),    //----- 87
  System.Drawing.Color.FromArgb(9, 38, 0, 255),        //----- 88
  System.Drawing.Color.FromArgb(23, 38, 19, 255),    //----- 89
  System.Drawing.Color.FromArgb(0, 255, 0, 255),    //----- 90
  System.Drawing.Color.FromArgb(127, 255, 127, 255),//----- 91
  System.Drawing.Color.FromArgb(0, 165, 0, 255),    //----- 92
  System.Drawing.Color.FromArgb(82, 165, 82, 255),    //----- 93
  System.Drawing.Color.FromArgb(0, 127, 0, 255),    //----- 94
  System.Drawing.Color.FromArgb(63, 127, 63, 255),    //----- 95
  System.Drawing.Color.FromArgb(0, 76, 0, 255),        //----- 96
  System.Drawing.Color.FromArgb(38, 76, 38, 255),    //----- 97
  System.Drawing.Color.FromArgb(0, 38, 0, 255),        //----- 98
  System.Drawing.Color.FromArgb(19, 38, 19, 255),    //----- 99
  System.Drawing.Color.FromArgb(0, 255, 63, 255),    //----- 100
  System.Drawing.Color.FromArgb(127, 255, 159, 255),//----- 101
  System.Drawing.Color.FromArgb(0, 165, 41, 255),    //----- 102
  System.Drawing.Color.FromArgb(82, 165, 103, 255),    //----- 103
  System.Drawing.Color.FromArgb(0, 127, 31, 255),    //----- 104
  System.Drawing.Color.FromArgb(63, 127, 79, 255),    //----- 105
  System.Drawing.Color.FromArgb(0, 76, 19, 255),    //----- 106
  System.Drawing.Color.FromArgb(38, 76, 47, 255),    //----- 107
  System.Drawing.Color.FromArgb(0, 38, 9, 255),        //----- 108
  System.Drawing.Color.FromArgb(19, 38, 23, 255),    //----- 109
  System.Drawing.Color.FromArgb(0, 255, 127, 255),    //----- 110
  System.Drawing.Color.FromArgb(127, 255, 191, 255),//----- 111
  System.Drawing.Color.FromArgb(0, 165, 82, 255),    //----- 112
  System.Drawing.Color.FromArgb(82, 165, 124, 255),    //----- 113
  System.Drawing.Color.FromArgb(0, 127, 63, 255),    //----- 114
  System.Drawing.Color.FromArgb(63, 127, 95, 255),    //----- 115
  System.Drawing.Color.FromArgb(0, 76, 38, 255),    //----- 116
  System.Drawing.Color.FromArgb(38, 76, 57, 255),    //----- 117
  System.Drawing.Color.FromArgb(0, 38, 19, 255),    //----- 118
  System.Drawing.Color.FromArgb(19, 38, 28, 255),    //----- 119
  System.Drawing.Color.FromArgb(0, 255, 191, 255),    //----- 120
  System.Drawing.Color.FromArgb(127, 255, 223, 255),//----- 121
  System.Drawing.Color.FromArgb(0, 165, 124, 255),    //----- 122
  System.Drawing.Color.FromArgb(82, 165, 145, 255),    //----- 123
  System.Drawing.Color.FromArgb(0, 127, 95, 255),    //----- 124
  System.Drawing.Color.FromArgb(63, 127, 111, 255),    //----- 125
  System.Drawing.Color.FromArgb(0, 76, 57, 255),    //----- 126
  System.Drawing.Color.FromArgb(38, 76, 66, 255),    //----- 127
  System.Drawing.Color.FromArgb(0, 38, 28, 255),    //----- 128
  System.Drawing.Color.FromArgb(19, 38, 33, 255),    //----- 129
  System.Drawing.Color.FromArgb(0, 255, 255, 255),    //----- 130
  System.Drawing.Color.FromArgb(127, 255, 255, 255),//----- 131
  System.Drawing.Color.FromArgb(0, 165, 165, 255),    //----- 132
  System.Drawing.Color.FromArgb(82, 165, 165, 255),    //----- 133
  System.Drawing.Color.FromArgb(0, 127, 127, 255),    //----- 134
  System.Drawing.Color.FromArgb(63, 127, 127, 255),    //----- 135
  System.Drawing.Color.FromArgb(0, 76, 76, 255),    //----- 136
  System.Drawing.Color.FromArgb(38, 76, 76, 255),    //----- 137
  System.Drawing.Color.FromArgb(0, 38, 38, 255),    //----- 138
  System.Drawing.Color.FromArgb(19, 38, 38, 255),    //----- 139
  System.Drawing.Color.FromArgb(0, 191, 255, 255),    //----- 140
  System.Drawing.Color.FromArgb(127, 223, 255, 255),//----- 141
  System.Drawing.Color.FromArgb(0, 124, 165, 255),    //----- 142
  System.Drawing.Color.FromArgb(82, 145, 165, 255),    //----- 143
  System.Drawing.Color.FromArgb(0, 95, 127, 255),    //----- 144
  System.Drawing.Color.FromArgb(63, 111, 127, 255),    //----- 145
  System.Drawing.Color.FromArgb(0, 57, 76, 255),    //----- 146
  System.Drawing.Color.FromArgb(38, 66, 76, 255),    //----- 147
  System.Drawing.Color.FromArgb(0, 28, 38, 255),    //----- 148
  System.Drawing.Color.FromArgb(19, 33, 38, 255),    //----- 149
  System.Drawing.Color.FromArgb(0, 127, 255, 255),    //----- 150
  System.Drawing.Color.FromArgb(127, 191, 255, 255),//----- 151
  System.Drawing.Color.FromArgb(0, 82, 165, 255),    //----- 152
  System.Drawing.Color.FromArgb(82, 124, 165, 255),    //----- 153
  System.Drawing.Color.FromArgb(0, 63, 127, 255),    //----- 154
  System.Drawing.Color.FromArgb(63, 95, 127, 255),    //----- 155
  System.Drawing.Color.FromArgb(0, 38, 76, 255),    //----- 156
  System.Drawing.Color.FromArgb(38, 57, 76, 255),    //----- 157
  System.Drawing.Color.FromArgb(0, 19, 38, 255),    //----- 158
  System.Drawing.Color.FromArgb(19, 28, 38, 255),    //----- 159
  System.Drawing.Color.FromArgb(0, 63, 255, 255),    //----- 160
  System.Drawing.Color.FromArgb(127, 159, 255, 255),//----- 161
  System.Drawing.Color.FromArgb(0, 41, 165, 255),    //----- 162
  System.Drawing.Color.FromArgb(82, 103, 165, 255),    //----- 163
  System.Drawing.Color.FromArgb(0, 31, 127, 255),    //----- 164
  System.Drawing.Color.FromArgb(63, 79, 127, 255),    //----- 165
  System.Drawing.Color.FromArgb(0, 19, 76, 255),    //----- 166
  System.Drawing.Color.FromArgb(38, 47, 76, 255),    //----- 167
  System.Drawing.Color.FromArgb(0, 9, 38, 255),        //----- 168
  System.Drawing.Color.FromArgb(19, 23, 38, 255),    //----- 169
  System.Drawing.Color.FromArgb(0, 0, 255, 255),    //----- 170
  System.Drawing.Color.FromArgb(127, 127, 255, 255),//----- 171
  System.Drawing.Color.FromArgb(0, 0, 165, 255),    //----- 172
  System.Drawing.Color.FromArgb(82, 82, 165, 255),    //----- 173
  System.Drawing.Color.FromArgb(0, 0, 127, 255),    //----- 174
  System.Drawing.Color.FromArgb(63, 63, 127, 255),    //----- 175
  System.Drawing.Color.FromArgb(0, 0, 76, 255),        //----- 176
  System.Drawing.Color.FromArgb(38, 38, 76, 255),    //----- 177
  System.Drawing.Color.FromArgb(0, 0, 38, 255),        //----- 178
  System.Drawing.Color.FromArgb(19, 19, 38, 255),    //----- 179
  System.Drawing.Color.FromArgb(63, 0, 255, 255),    //----- 180
  System.Drawing.Color.FromArgb(159, 127, 255, 255),//----- 181
  System.Drawing.Color.FromArgb(41, 0, 165, 255),    //----- 182
  System.Drawing.Color.FromArgb(103, 82, 165, 255),    //----- 183
  System.Drawing.Color.FromArgb(31, 0, 127, 255),    //----- 184
  System.Drawing.Color.FromArgb(79, 63, 127, 255),    //----- 185
  System.Drawing.Color.FromArgb(19, 0, 76, 255),    //----- 186
  System.Drawing.Color.FromArgb(47, 38, 76, 255),    //----- 187
  System.Drawing.Color.FromArgb(9, 0, 38, 255),        //----- 188
  System.Drawing.Color.FromArgb(23, 19, 38, 255),    //----- 189
  System.Drawing.Color.FromArgb(127, 0, 255, 255),    //----- 190
  System.Drawing.Color.FromArgb(191, 127, 255, 255),//----- 191
  System.Drawing.Color.FromArgb(82, 0, 165, 255),    //----- 192
  System.Drawing.Color.FromArgb(124, 82, 165, 255),    //----- 193
  System.Drawing.Color.FromArgb(63, 0, 127, 255),    //----- 194
  System.Drawing.Color.FromArgb(95, 63, 127, 255),    //----- 195
  System.Drawing.Color.FromArgb(38, 0, 76, 255),    //----- 196
  System.Drawing.Color.FromArgb(57, 38, 76, 255),    //----- 197
  System.Drawing.Color.FromArgb(19, 0, 38, 255),    //----- 198
  System.Drawing.Color.FromArgb(28, 19, 38, 255),    //----- 199
  System.Drawing.Color.FromArgb(191, 0, 255, 255),    //----- 200
  System.Drawing.Color.FromArgb(223, 127, 255, 255),//----- 201
  System.Drawing.Color.FromArgb(124, 0, 165, 255),    //----- 202
  System.Drawing.Color.FromArgb(145, 82, 165, 255),    //----- 203
  System.Drawing.Color.FromArgb(95, 0, 127, 255),    //----- 204
  System.Drawing.Color.FromArgb(111, 63, 127, 255),    //----- 205
  System.Drawing.Color.FromArgb(57, 0, 76, 255),    //----- 206
  System.Drawing.Color.FromArgb(66, 38, 76, 255),    //----- 207
  System.Drawing.Color.FromArgb(28, 0, 38, 255),    //----- 208
  System.Drawing.Color.FromArgb(33, 19, 38, 255),    //----- 209
  System.Drawing.Color.FromArgb(255, 0, 255, 255),    //----- 210
  System.Drawing.Color.FromArgb(255, 127, 255, 255),//----- 211
  System.Drawing.Color.FromArgb(165, 0, 165, 255),    //----- 212
  System.Drawing.Color.FromArgb(165, 82, 165, 255),    //----- 213
  System.Drawing.Color.FromArgb(127, 0, 127, 255),    //----- 214
  System.Drawing.Color.FromArgb(127, 63, 127, 255),    //----- 215
  System.Drawing.Color.FromArgb(76, 0, 76, 255),    //----- 216
  System.Drawing.Color.FromArgb(76, 38, 76, 255),    //----- 217
  System.Drawing.Color.FromArgb(38, 0, 38, 255),    //----- 218
  System.Drawing.Color.FromArgb(38, 19, 38, 255),    //----- 219
  System.Drawing.Color.FromArgb(255, 0, 191, 255),    //----- 220
  System.Drawing.Color.FromArgb(255, 127, 223, 255),//----- 221
  System.Drawing.Color.FromArgb(165, 0, 124, 255),    //----- 222
  System.Drawing.Color.FromArgb(165, 82, 145, 255),    //----- 223
  System.Drawing.Color.FromArgb(127, 0, 95, 255),    //----- 224
  System.Drawing.Color.FromArgb(127, 63, 111, 255),    //----- 225
  System.Drawing.Color.FromArgb(76, 0, 57, 255),    //----- 226
  System.Drawing.Color.FromArgb(76, 38, 66, 255),    //----- 227
  System.Drawing.Color.FromArgb(38, 0, 28, 255),    //----- 228
  System.Drawing.Color.FromArgb(38, 19, 33, 255),    //----- 229
  System.Drawing.Color.FromArgb(255, 0, 127, 255),    //----- 230
  System.Drawing.Color.FromArgb(255, 127, 191, 255),//----- 231
  System.Drawing.Color.FromArgb(165, 0, 82, 255),    //----- 232
  System.Drawing.Color.FromArgb(165, 82, 124, 255),    //----- 233
  System.Drawing.Color.FromArgb(127, 0, 63, 255),    //----- 234
  System.Drawing.Color.FromArgb(127, 63, 95, 255),    //----- 235
  System.Drawing.Color.FromArgb(76, 0, 38, 255),    //----- 236
  System.Drawing.Color.FromArgb(76, 38, 57, 255),    //----- 237
  System.Drawing.Color.FromArgb(38, 0, 19, 255),    //----- 238
  System.Drawing.Color.FromArgb(38, 19, 28, 255),    //----- 239
  System.Drawing.Color.FromArgb(255, 0, 63, 255),    //----- 240
  System.Drawing.Color.FromArgb(255, 127, 159, 255),//----- 241
  System.Drawing.Color.FromArgb(165, 0, 41, 255),    //----- 242
  System.Drawing.Color.FromArgb(165, 82, 103, 255),    //----- 243
  System.Drawing.Color.FromArgb(127, 0, 31, 255),    //----- 244
  System.Drawing.Color.FromArgb(127, 63, 79, 255),    //----- 245
  System.Drawing.Color.FromArgb(76, 0, 19, 255),    //----- 246
  System.Drawing.Color.FromArgb(76, 38, 47, 255),    //----- 247
  System.Drawing.Color.FromArgb(38, 0, 9, 255),        //----- 248
  System.Drawing.Color.FromArgb(38, 19, 23, 255),    //----- 249
  System.Drawing.Color.FromArgb(84, 84, 84, 255),    //----- 250
  System.Drawing.Color.FromArgb(118, 118, 118, 255),//----- 251
  System.Drawing.Color.FromArgb(152, 152, 152, 255),//----- 252
  System.Drawing.Color.FromArgb(186, 186, 186, 255),//----- 253
  System.Drawing.Color.FromArgb(220, 220, 220, 255),//----- 254
  System.Drawing.Color.FromArgb(255, 255, 255, 255),//----- 255
};

    public static bool GetActiveViewPortInfo(ref double height, ref double width, ref Point3d target, ref Vector3d viewDir, ref double viewTwist, bool getViewCenter)
    {
        // get the editor object
        Editor ed = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
        ed.UpdateTiledViewportsInDatabase();
        Database db = HostApplicationServices.WorkingDatabase;
        using (Transaction t = db.TransactionManager.StartTransaction())
        {
            ViewportTable vt = (ViewportTable)t.GetObject(db.ViewportTableId, OpenMode.ForRead);
            ViewportTableRecord btr = (ViewportTableRecord)t.GetObject(vt[GSUtil.strActive], OpenMode.ForRead);
            height = btr.Height;
            width = btr.Width;
            target = btr.Target;
            viewDir = btr.ViewDirection;
            viewTwist = btr.ViewTwist;
            t.Commit();
        }
        return true;
    }
    public static void mpManager_ViewToBeDestroyed(Object sender, ViewEventArgs e)
    {
        // get the editor object
        Editor ed = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
        ed.WriteMessage("BlockView: Event ViewToBeDestroyed fired");
    }
    public static void mpManager_ViewWasCreated(Object sender, ViewEventArgs e)
    {
        // get the editor object
        Editor ed = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
        ed.WriteMessage("BlockView: Event ViewWasCreated fired");
    }
    public static void mpManager_GsToBeUnloaded(Object sender, EventArgs e)
    {
        // get the editor object
        Editor ed = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
        ed.WriteMessage("BlockView: Event GsToBeUnloaded fired");
    }
    public static void mpManager_ConfigWasModified(Object sender, EventArgs e)
    {
        // get the editor object
        Editor ed = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
        ed.WriteMessage("BlockView: Event ConfigWasModified fired");
    }

    /// <summary>
    /// [TT]: Depreciated (using ControlPaint.DrawReversibleFrame() instead)
    /// </summary>

    public class RubberbandRectangle
    {
        public enum PenStyles
        {
            PS_SOLID = 0,
            PS_DASH = 1,
            PS_DOT = 2,
            PS_DASHDOT = 3,
            PS_DASHDOTDOT = 4
        }
        // These values come from the larger set of defines in WinGDI.h,
        // but are all that are needed for this application.  If this class
        // is expanded for more generic rectangle drawing, they should be
        // replaced by enums from those sets of defones.
        private int NULL_BRUSH = 5;
        private int R2_XORPEN = 7;
        private PenStyles penStyle;
        private int BLACK_PEN = 0;

        // Default contructor - sets member fields
        public RubberbandRectangle()
        {
            penStyle = PenStyles.PS_DOT;
        }

        // penStyles property get/set.
        public PenStyles PenStyle
        {
            get
            {
                return penStyle;
            }
            set
            {
                penStyle = value;
            }
        }

        public void DrawXORRectangle(Graphics grp, System.Drawing.Point startPt, System.Drawing.Point endPt)
        {
            int X1 = startPt.X;
            int Y1 = startPt.Y;
            int X2 = endPt.X;
            int Y2 = endPt.Y;
            // Extract the Win32 HDC from the Graphics object supplied.
            IntPtr hdc = grp.GetHdc();

            // Create a pen with a dotted style to draw the border of the
            // rectangle.
            IntPtr gdiPen = CreatePen(penStyle,
                              1, BLACK_PEN);

            // Set the ROP cdrawint mode to XOR.
            SetROP2(hdc, R2_XORPEN);

            // Select the pen into the device context.
            IntPtr oldPen = SelectObject(hdc, gdiPen);

            // Create a stock NULL_BRUSH brush and select it into the device
            // context so that the rectangle isn't filled.
            IntPtr oldBrush = SelectObject(hdc,
                                        GetStockObject(NULL_BRUSH));

            // Now XOR the hollow rectangle on the Graphics object with
            // a dotted outline.
            Rectangle(hdc, X1, Y1, X2, Y2);

            // Put the old stuff back where it was.
            SelectObject(hdc, oldBrush); // no need to delete a stock object
            SelectObject(hdc, oldPen);
            DeleteObject(gdiPen);       // but we do need to delete the pen

            // Return the device context to Windows.
            grp.ReleaseHdc(hdc);
        }

        // Use Interop to call the corresponding Win32 GDI functions
        [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
        private static extern int SetROP2(
                  IntPtr hdc,       // Handle to a Win32 device context
                  int enDrawMode    // Drawing mode
                  );
        [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
        private static extern IntPtr CreatePen(
                  PenStyles enPenStyle, // Pen style from enum PenStyles
                  int nWidth,               // Width of pen
                  int crColor               // Color of pen
                  );
        [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
        private static extern bool DeleteObject(
                  IntPtr hObject    // Win32 GDI handle to object to delete
                  );
        [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
        private static extern IntPtr SelectObject(
                  IntPtr hdc,       // Win32 GDI device context
                  IntPtr hObject    // Win32 GDI handle to object to select
                  );
        [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
        private static extern void Rectangle(
                  IntPtr hdc,           // Handle to a Win32 device context
                  int X1,               // x-coordinate of top left corner
                  int Y1,               // y-cordinate of top left corner
                  int X2,               // x-coordinate of bottom right corner
                  int Y2                // y-coordinate of bottm right corner
                  );
        [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
        private static extern IntPtr GetStockObject(
                  int brStyle   // Selected from the WinGDI.h BrushStyles enum
                  );

        // Csharp version of Win32 RGB macro
        private static int RGB(int R, int G, int B)
        {
            return (R | (G << 8) | (B << 16));
        }
    }
}

}

Text Only
`EnumToolStripMenuItem.cs`

​```csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//using GsRenderMode = Autodesk.AutoCAD.GraphicsSystem.RenderMode;
using System.ComponentModel;
using System.Reflection;

namespace BlockView.NET
{

    // A specialization of ToolStripMenuItem that can be used
    // to represent memberss of an enum type

    public class EnumToolStripMenuItem : ToolStripMenuItem
    {
        bool isFlag = false;
        long intval = 0L;

        EnumToolStripMenuItem( Enum value, EventHandler onClick )
            : base( GetItemText( value ) )
        {
            base.Tag = value;
            if( onClick != null )
                base.Click += onClick;
            isFlag = IsFlags( value.GetType() );
            intval = Convert.ToInt64( value );
        }

        public static EnumToolStripMenuItem[] CreateItems<T>() where T : struct 
        {
            return CreateItems( typeof(T), null );
        }

        public static EnumToolStripMenuItem[] CreateItems<T>( EventHandler onClick ) where T : struct
        {
            return CreateItems( typeof( T ), onClick );
        }

        public static EnumToolStripMenuItem[] CreateItems<T>( IEnumerable<T> items, EventHandler onClick ) where T : struct
        {
            return CreateItems( items.Cast<Enum>(), onClick );
        }

        public static EnumToolStripMenuItem[] CreateItems( Type enumType )
        {
            return CreateItems( enumType, null );
        }

        public static EnumToolStripMenuItem[] CreateItems( Type enumType, EventHandler onClick )
        {
            if( enumType == null )
                throw new ArgumentNullException( "enumType" );
            if( !enumType.IsEnum )
                throw new ArgumentException( "Requires an Enum type" );
            return CreateItems( Enum.GetValues( enumType ).Cast<Enum>().Distinct(), onClick );
        }

        // This override can be used to selectively add a specific set of members:
        public static EnumToolStripMenuItem[] CreateItems( IEnumerable<Enum> values, EventHandler onClick )
        {
            return values.Select( v => new EnumToolStripMenuItem( v, onClick ) ).ToArray();
        }

        public static void UpdateCheckedState( ToolStripItemCollection items, Enum value )
        {
            foreach( EnumToolStripMenuItem item in items.OfType<EnumToolStripMenuItem>() )
            {
                item.UpdateCheckedState( value );
            }
        }

        public void UpdateCheckedState( Enum value )
        {
            if( base.Tag != null && base.Tag.GetType() == value.GetType() )
            {
                Int64 flags = Convert.ToInt64( value );
                base.Checked = isFlag ? ( ( intval & flags ) == intval ) : intval == flags;
            }
        }

        static string GetItemText( Enum value )
        {
            FieldInfo fi = value.GetType().GetField( value.ToString() );
            if( fi != null )
            {
                DescriptionAttribute[] att = (DescriptionAttribute[])
                    fi.GetCustomAttributes( typeof( DescriptionAttribute ), false );
                if( att != null && att.Length > 0 )
                {
                    string desc = att[0].Description;
                    if( !string.IsNullOrEmpty( desc ) )
                        return desc;
                }
            }
            return value.ToString();
        }

        public Enum Value
        {
            get
            {
                return (Enum) base.Tag;
            }
        }

        public Int64 IntVal
        {
            get
            {
                return intval;
            }
        }

        static bool IsFlags( Type enumType )
        {
            var a = enumType.GetCustomAttributes( typeof( FlagsAttribute ), false );
            return a != null && a.Length > 0;
        }
    }

}

Helpers.cs

CSS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.IO;
using System.Diagnostics;
using System.Windows.Forms;

namespace BlockView.NET
{
    public static class BlockViewExtensionMethods
    {
        /// <summary>
        /// 
        /// This extension method can be called on any IEnumerable<T> 
        /// where the element type T implements the IDisposable interface.
        /// It's purpose is to guarantee the entire sequence is disposed
        /// even if an exception is thrown by the call to Dispose() on any
        /// element in the sequence.
        /// 
        /// </summary>

        public static void DisposeItems<T>( this IEnumerable<T> items ) where T : IDisposable
        {
            DisposeItems( items.GetEnumerator() );
        }

        static void DisposeItems( IEnumerator e ) 
        {
            while( e.MoveNext() )
            {
                try
                {
                    IDisposable disposable = e.Current as IDisposable;
                    if( disposable != null )
                        disposable.Dispose();
                }
                catch
                {
                    DisposeItems( e );
                    throw;
                }
            }

        }
    }

    /// <summary>
    ///
    /// [TT]: Detecting design-time execution:
    /// 
    /// The IsDesignMode method of this class should be used in preference
    /// to the DesignMode property of Control. The latter is only true when
    /// called on a control that is being designed. It is NOT true when it
    /// is called on an instance of a control that is a child of a control 
    /// that's being designed (e.g., the GsPreviewCtrl), or when called on 
    /// an instance of a base type of a control that is being designed.
    /// 
    /// For example, within the GsPreviewCtrl class, if the GsPreviewCtrl's
    /// DesignMode property is read when the BlockViewDialog is open in the 
    /// designer, it will return false because the GsPreviewCtrl is not what
    /// is being designed (the BlockViewDialog is what's being designed).
    /// 
    /// </summary>

    public static class Utils
    {
        static bool designMode = string.Equals(
            Path.GetFileNameWithoutExtension( Process.GetCurrentProcess().MainModule.FileName ),
            "devenv",
            StringComparison.OrdinalIgnoreCase );

# WPF中使用GsPreviewCtrl预览图块

## winform控件处理

`GsPreviewCtrl.cs`

​```csharp
using System;
using System.IO;
using System.Diagnostics;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using AcadApp = ZwSoft.ZwCAD.ApplicationServices.Application;
using ZwSoft.ZwCAD.ApplicationServices;
using ZwSoft.ZwCAD.DatabaseServices;
using ZwSoft.ZwCAD.Windows;
using ZwSoft.ZwCAD.EditorInput;
using ZwSoft.ZwCAD.Runtime;
using ZwSoft.ZwCAD.Geometry;
using ZwSoft.ZwCAD.GraphicsSystem;
namespace BlockView.NET
{
    public class GsPreviewCtrl : Control
    {
        public GsPreviewCtrl()
        {
        }



        // current dwg
        public Database mCurrentDwg = null;
        // Gs specific
        public ZwSoft.ZwCAD.GraphicsSystem.Manager mpManager = null;
        public ZwSoft.ZwCAD.GraphicsSystem.Device mpDevice = null;
        public ZwSoft.ZwCAD.GraphicsSystem.Model mpModel = null;
        public ZwSoft.ZwCAD.GraphicsSystem.View mpView = null;
        public bool mZooming = false;
        public bool mMouseDown = false;
        public bool mMouseMoving = false;
        public bool mbPanning = false;
        public bool mbOrbiting = false;
        public System.Drawing.Point mStartPoint;
        public System.Drawing.Point mEndPoint;

        public static bool IsDesignMode
        {
            get
            {
                return Utils.IsDesignMode(null);
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                // clear up the GS view gadgets
                if (!IsDesignMode)
                    ClearAll();
                if (mCurrentDwg != null)
                {
                    mCurrentDwg.Dispose();
                    mCurrentDwg = null;
                }
            }
            base.Dispose(disposing);

        }

        // called from InitDrawingControl, does GsPreviewCtrl specific initialization
        public void Init(Document doc, Database db)
        {
            mCurrentDwg = db;
            // check to see if the manager is already initalised
            if (null == mpManager)
            {
                // if not let's set it up
                mpManager = doc.GraphicsManager;
                // here's some test code to show the GS Events working
                mpManager.ViewToBeDestroyed += new ViewToBeDestroyedEventHandler(GSUtil.mpManager_ViewToBeDestroyed);
                mpManager.ViewWasCreated += new ViewWasCreatedEventHandler(GSUtil.mpManager_ViewWasCreated);
                mpManager.GsToBeUnloaded += new GsToBeUnloadedEventHandler(GSUtil.mpManager_GsToBeUnloaded);
                mpManager.ConfigWasModified += new ConfigWasModifiedEventHandler(GSUtil.mpManager_ConfigWasModified);

                KernelDescriptor descriptor = new KernelDescriptor();
                descriptor.addRequirement(ZwSoft.ZwCAD.UniqueString.Intern("3D Drawing"));
                GraphicsKernel kernal = Manager.AcquireGraphicsKernel(descriptor);
                // now create the Gs control, create the autocad device passing the handle to the Windows panel
                mpDevice = mpManager.CreateZWCADDevice(kernal, this.Handle);
                // resize the device to the panel size
                mpDevice.OnSize(this.Size);
                // now create a new gs view
                mpView = new ZwSoft.ZwCAD.GraphicsSystem.View();
                // and create the model
                mpModel = mpManager.CreateZWCADModel(kernal);

                // add the view to the device
                mpDevice.Add(mpView);
            }

            SetViewTo(mpView, mCurrentDwg);
            using (Transaction tr = mCurrentDwg.TransactionManager.StartTransaction())
            {
                BlockTableRecord curSpace = tr.GetObject(mCurrentDwg.CurrentSpaceId, OpenMode.ForRead, true) as BlockTableRecord;
                // 在这里进行你的操作
                mpView.Add(curSpace, mpModel);
                tr.Commit();
            }

            refreshView();
        }


        public void ClearAll()
        {
            if (!IsDesignMode)
            {
                if (!(mpDevice is null))
                {
                    bool b = mpDevice.Erase(mpView);
                }
                if (!(mpView is null))
                {
                    mpView.EraseAll();
                    mpView.Dispose();
                    mpView = null;
                }
                if (!(mpManager is null))
                {
                    if (!(mpModel is null))
                    {
                        mpModel.Dispose();
                        mpModel = null;
                    }

                    if (!(mpDevice is null))
                    {
                        mpDevice.Dispose();
                        mpDevice = null;
                    }
                    mpManager = null;
                }
            }
        }

        // [TT]: Refactored to exclude AutoCAD types from methods that run in the designer:

        public void ErasePreview()
        {
            if (!IsDesignMode)
                InternalErasePreview();
        }

        public void InternalErasePreview()
        {
            if (mpView != null)
                mpView.EraseAll();
            if (mpManager != null && mpModel != null)
            {
                mpModel.Dispose();
                mpModel = null;
            }
        }
        public static bool IsDesignMode( this Control control )
        {
            return designMode;
        }

        public static bool DesignMode
        {
            get
            {
                return designMode;
            }
        }
    }
}

image-20250415083021590

wpf相关处理

MainWindow.xaml

C#
<Window
    x:Class="WpfApp1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:WpfApp1"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:wf="clr-namespace:BlockView.NET;assembly=BlockView.NET"
    Title="MainWindow"
    Width="800"
    Height="450"
    mc:Ignorable="d">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="2*" />
        </Grid.ColumnDefinitions>
        <WindowsFormsHost
            Name="winFormsHost"
            Grid.RowSpan="2"
            Grid.Column="1">
            <wf:GsPreviewCtrl x:Name="blockView" />
        </WindowsFormsHost>
        <StackPanel Margin="10,20">
            <Button
                Name="btnLoad"
                Margin="0,5"
                Click="btnLoad_Click">
                Load
            </Button>
            <Button
                Name="btnSave"
                Margin="0,5"
                Click="BtnSave_Click">
                Save
            </Button>
            <Button
                Name="btnClear"
                Margin="0,5"
                Click="BtnClear_Click">
                Clear
            </Button>
        </StackPanel>
    </Grid>
</Window>

MainWindow.xaml.cs

C#
namespace WpfApp1
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        Document document;
        public MainWindow()
        {
            InitializeComponent();
            document = AcadApp.DocumentManager.MdiActiveDocument;
            blockView.Init(document, document.Database);
        }

        private void btnLoad_Click(object sender, RoutedEventArgs e)
        {
            //创建文件选择对话框选择dwg文件
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "dwg文件|*.dwg";
            if (openFileDialog.ShowDialog() == true)
            {
                //打开dwg文件
                Database dwg = new Database(false, true);
                // now read it in
                dwg.ReadDwgFile(openFileDialog.FileName, FileOpenMode.OpenForReadAndReadShare, true, "");
                // initialising the drawing control, pass the existing document still as the gs view still refers to it
                blockView.Init(document, dwg);
            }
        }
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {

        }

        private void BtnClear_Click(object sender, RoutedEventArgs e)
        {
            blockView.Init(document, document.Database);
        }
    }
}

image-20250415083557963

无法正常关闭CAD等后续再完善