⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 acrxentrypoint.cpp

📁 这是我用ARX做的一段画多段线的程序,并能实现图形消隐.
💻 CPP
字号:
// (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 "WidthSetup.h"

//-----------------------------------------------------------------------------
#define szRDS _RXST("MSL")

double thick_width(0), thin_width(0);


//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CToPline6App : public AcRxArxApp {
private:

public:
	CToPline6App () : 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 () {
	}


	// ----- MSLToPline6.widthsetup command
	static void MSLToPline6widthsetup(void)
	{
		// Add your code for command MSLToPline6.topline here
		CWidthSetup setupdialog;
		setupdialog.DoModal();
		thick_width = setupdialog.thick_width;
		thin_width = setupdialog.thin_width;

		acutPrintf("%f,%f\n",thick_width,thin_width);

		//检查每个实体的线型,对于实线,用粗线; 点画线,虚线等用细线
		
		AcDbBlockTable *pBlockTable;
		acdbHostApplicationServices() -> workingDatabase() -> getSymbolTable(pBlockTable,AcDb::kForRead);
		AcDbBlockTableRecord *pBlockTableRecord;
		pBlockTable -> getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForRead);
		pBlockTable -> close();

		AcDbBlockTableRecordIterator *pBlockIterator;
		pBlockTableRecord -> newIterator(pBlockIterator);

		char *LayerName;
		AcDbLayerTable * pLayerTbl;//定义层表指针
		AcDbLayerTableRecord * pLayerTblRcd; //定义层表记录指针 
		AcDbLinetypeTable *pLinetypeTbl;  //定义线型表指针
		AcDbObjectId ContinuousId;

        //以读方式打开层表,获得层表指针
        acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTbl,AcDb::kForRead); 
		//以读方式打开线型表,获得线型指针
        acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLinetypeTbl,AcDb::kForRead); 
		pLinetypeTbl -> getAt("CONTINUOUS",ContinuousId); //获得实线的Id
		pLinetypeTbl -> close();

		for(; !pBlockIterator -> done(); pBlockIterator -> step()) {
			//AcDbPolyline *pEntity;
			AcDbEntity *pEntity;
			AcDbPolyline *pPolyline = NULL;
			AcDbObject *pObj;
			pBlockIterator -> getEntity(pEntity, AcDb::kForRead);
			const char *linetype = pEntity -> linetype();
			if(strcmp(linetype,"ByLayer")==0) { //若某实体的线型为ByLayer
				//1.获得该实体所在层的层名
				LayerName = pEntity -> layer();	
				//2.利用层名获得层表记录指针pLayerTblRcd
				if (pLayerTbl->getAt(LayerName,pLayerTblRcd,AcDb::kForRead)==Acad::eOk)
				{ 
					AcDbObjectId linetypeId = pLayerTblRcd -> linetypeObjectId();
					if(linetypeId == ContinuousId) { //若该层为实线,即continuous,该实体为粗线
						ads_name ent;

						if(Acad::eOk  != acdbGetAdsName(ent,pEntity->objectId())) return;
						pEntity ->close();
						acedCommand(RTSTR,"PEDIT",RTENAME,ent,RTSTR,"W",RTREAL,thick_width,RTSTR,"",0);
					}
					else {
						ads_name ent;

						if(Acad::eOk  != acdbGetAdsName(ent,pEntity->objectId())) return;
						pEntity ->close();
						acedCommand(RTSTR,"PEDIT",RTENAME,ent,RTSTR,"W",RTREAL,thin_width,RTSTR,"",0);
					}

				}

			}
			else if(strcmp(linetype,"ByBlock")==0) { //若某实体的线型为ByBlock
			}
			else if(strcmp(linetype,"Continuous")==0) {
						ads_name ent;

						if(Acad::eOk  != acdbGetAdsName(ent,pEntity->objectId())) return;
						pEntity ->close();
						acedCommand(RTSTR,"PEDIT",RTENAME,ent,RTSTR,"W",RTREAL,thick_width,RTSTR,"",0);
			}
			else {
						ads_name ent;

						if(Acad::eOk  != acdbGetAdsName(ent,pEntity->objectId())) return;
						pEntity ->close();
						acedCommand(RTSTR,"PEDIT",RTENAME,ent,RTSTR,"W",RTREAL,thin_width,RTSTR,"",0);
			}

			AcDb::LineWeight lineweight = pEntity -> lineWeight();
			acutPrintf("linetype %s.\n", linetype);
			acutPrintf("Line Weight %d\n",lineweight);
			pEntity -> close();
			pLayerTbl ->close();
		}
		delete pBlockIterator;
		pBlockTableRecord -> close();
		acutPrintf("\n");



	}

	// - MSLToPline6.topline command (do not rename)
	static void MSLToPline6topline(void)
	{
		// Add your code for command MSLToPline6.topline here
			//首先获取当前图形中的所有实体
		struct resbuf rb1,rb2;
		ads_point LeftDownPts,RightUpPts;
		ads_name ssname;
		int	rt;

		acedCommand(RTSTR,"ZOOM",RTSTR,"ALL",0);
		acedGetVar("EXTMAX",&rb1); //获取当前图形右上角点坐标
		acedGetVar("EXTMIN",&rb2); //获取当前图形左下角点坐标
		ads_point_set(rb1.resval.rpoint,RightUpPts);
		ads_point_set(rb2.resval.rpoint,LeftDownPts);

		double deltax = (RightUpPts[X] - LeftDownPts[X]) / 10;
		double deltay = (RightUpPts[Y] - LeftDownPts[Y]) / 10;

		RightUpPts[X] += deltax;
		RightUpPts[Y] += deltay;
		LeftDownPts[X] -= deltax;
		LeftDownPts[Y] -= deltay;


		rt=acedSSGet("C",RightUpPts,LeftDownPts,NULL,ssname);
		if(rt!=RTNORM) {
			acdbFail("实体选择集构造失败");
			return;
		}

		//为了利用boundary命令获取外边界轮廓,构造一包围盒
		ads_point pts;
		pts[X] = LeftDownPts[X] + 1;
		pts[Y] = LeftDownPts[Y] + 1;
		acedCommand(RTSTR,"_RECTANG",RT3DPOINT,LeftDownPts,RT3DPOINT,RightUpPts,0);
		//获取图形中的最后一个实体
		ads_name LastName;
		if(acdbEntLast(LastName) != RTNORM) {
			acdbFail("No entities in drawing\n");
			return ;
		}
		acedCommand(RTSTR,"-BOUNDARY",RTSTR,"A",RTSTR,"I",RTSTR,"Y",RTSTR,"O",RTSTR,"P",RTSTR,"",RT3DPOINT,pts,RTSTR,"",0);
		acedCommand(RTSTR,"ERASE",RTENAME,LastName,RTSTR,"",0); //删除包围盒


		if(acdbEntLast(LastName) != RTNORM) {
			acdbFail("No entities in drawing\n");
			return ;
		}
		acedCommand(RTSTR,"ERASE",RTENAME,LastName,RTSTR,"",0); //删除沿包围盒生成的多段线

		//将其他剩余实体生成不合并的多段线
		acedCommand(RTSTR,"PEDIT",RTSTR,"M",RTSTR,"C",RT3DPOINT,RightUpPts,RT3DPOINT,LeftDownPts,RTSTR,"",RTSTR,"Y",RTSTR,"",0);
		//将指定内孔生成合并的多段线
		/*acutPrintf("用鼠标点选内孔:");
		acedCommand(RTSTR,"-BOUNDARY",RTSTR,"A",RTSTR,"O",RTSTR,"P",RTSTR,"",0);*/

	}
} ;


//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CToPline6App)

ACED_ARXCOMMAND_ENTRY_AUTO(CToPline6App, MSLToPline6, widthsetup, widthsetup, ACRX_CMD_TRANSPARENT, NULL)
ACED_ARXCOMMAND_ENTRY_AUTO(CToPline6App, MSLToPline6, topline, topline, ACRX_CMD_TRANSPARENT, NULL)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -