LayerChooser --- an arx 4 AutoCAD2007

//  very easy an simple 
//  code by s91
//  s91.ctgu.cn@gmail.com
//
//  (C) Copyright 2002-2005 by Autodesk, Inc. 
//
//  Permission to use, copy, modify, and distribute this software in
//  object code form for any purpose and without fee is hereby granted, 
//  provided that the above copyright notice appears in all copies and 
//  that both that copyright notice and the limited warranty and
//  restricted rights notice below appear in all supporting 
//  documentation.
//
//  AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. 
//  AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
//  MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC. 
//  DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
//  UNINTERRUPTED OR ERROR FREE.
//
//  Use, duplication, or disclosure by the U.S. Government is subject to 
//  restrictions set forth in FAR 52.227-19 (Commercial Computer
//  Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
//  (Rights in Technical Data and Computer Software), as applicable.
//

// -----------------------------------------------------------------------------
// ----- acrxEntryPoint.h
// -----------------------------------------------------------------------------
#include  " StdAfx.h "
#include 
" resource.h "
#include 
< dbsymtb.h >
// -----------------------------------------------------------------------------
#define  szRDS _RXST("")

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

public:
        CLayerChooserApp () : AcRxArxApp () 
{}

        
virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
                
// TODO: Load dependencies here

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

                
// TODO: Add your initialization code here

                
return (retCode) ;
        }


        
virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {
                
// TODO: Add your code here

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

                
// TODO: Unload dependencies here

                
return (retCode) ;
        }


        
virtual void RegisterServerComponents () {
        }


public:

        
// - LayerChooser._LayerChooser command (do not rename)
        static void LayerChooser_LayerChooser(void)
        
{
                
// Add your code for command LayerChooser._LayerChooser here
                ACHAR result[16];
                ACHAR t1[
1],t2[1];//存储图层名及输入的字符用与比较
                
//ACHAR *LayerName = NULL;
                acedGetString(0,_T("Please Input the Layer Name: "),result);
                
//acutPrintf(result);
                t1[0= result[0];
                
int n = 0;//判断是否找到图层
                AcDbLayerTable *pLayerTbl;
                acdbHostApplicationServices()
->workingDatabase()
                        
->getSymbolTable(pLayerTbl, AcDb::kForRead);

                
// Create a new iterator that starts at table
                
// beginning and skips deleted.
                
//
                
//code by s91
               
// s91.ctgu.cn@gmail.com
                AcDbLayerTableIterator *pLayerIterator;
                pLayerTbl
->newIterator(pLayerIterator);

                
// Walk the table, getting every table record and
                
// printing the linetype name.
                
//
                AcDbLayerTableRecord *pLayerTableRcd;
                ACHAR 
*pLtName;
                
for (; !pLayerIterator->done(); pLayerIterator->step()) 
                
{
                        pLayerIterator
->getRecord(pLayerTableRcd, AcDb::kForRead);
                        pLayerTableRcd
->getName(pLtName);
                        pLayerTableRcd
->close();
                        
//acutPrintf(_T(" Linetype name is:  %s"), pLtName);
                        t2[0= pLtName[0];
                        
//n = _tcscmp(t1,t2);
                        if (t1[0== t2[0])
                        
{
                                
// LayerName = pLtName;
                                struct resbuf pResult;
                                ::acedGetVar(_T(
"CLAYER"),&pResult);//取得当前图层
                                pResult.resval.rstring = pLtName;
                                ::acedSetVar(_T(
"CLAYER"), &pResult);//将输入的图层设为当前层
                                                                     
//相当于命令 CLAYER LAYERNAME
                                
//acutPrintf(_T(" Linetype name is:  %s"), pResult.resval.rstring);
                                free(pLtName);
                                n 
= 1;//如果图层找到,则将n赋值为1
                        }

                        
else
                        
{
                                free(pLtName);
                        }

                }

                
if (n == 0)
                
{
                        acutPrintf(_T(
" The layer was not found!"));
                }

                delete pLayerIterator;
                pLayerTbl
->close();
                
// acutPrintf(_T(" Linetype name"));

                
// acutPrintf(_T(" Linetype name is:  %s"), pResult.resval.rstring);


        }

}
 ;

// -----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CLayerChooserApp)

ACED_ARXCOMMAND_ENTRY_AUTO(CLayerChooserApp, LayerChooser, _LayerChooser, LayerChooser, ACRX_CMD_TRANSPARENT, NULL)
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值