ObjectArx调用cad内部命令

PhdArxCadCmd.h

#pragma once
#include <memory>
#include <mutex>

/***********************************************
   >   Class Name: PhdArxCadCmd
   >     Describe: Arx调用cad命令(单例类)
   >       Author: peihaodong
   > Created Time: 2021年7月22日
   >         Blog: https://blog.csdn.net/phd17621680432
   >           QQ: 841382590
**********************************************/

class PhdArxCadCmd final
{
public:
	static PhdArxCadCmd* Instance();

private:
	PhdArxCadCmd() = default;

	static std::unique_ptr<PhdArxCadCmd> m_self;	//声明静态对象

public:
	//关闭命令回显
	void EchoOff() const;

	//刷新图纸
	bool CallRegen() const;

	//设置标注线性比例
	bool SetDimLineScale(double dValue) const;

	//设置标注全局比例
	bool SetDimScale(double dValue) const;

	//设置区域覆盖是否显示边框
	bool SetWipeoutShow(bool bShow = false) const;

	//设置倒圆角半径
	bool SetFilletRadius(double dRadius) const;
	//调用cad命令倒圆角
	bool FilletByCommand(AcDbObjectId& idArc,const AcDbObjectId& idLine1, const AcDbObjectId& idLine2) const;

	//定位实体
	bool OrientationEnt(const AcDbObjectId& idEnt) const;

	//zoom显示全部实体
	bool ZoomAllEnt() const;

	//zoom窗口
	bool ZoomWindow(const AcGePoint3d& ptMin,const AcGePoint3d& ptMax) const;

};

//宏定义
#define g_ArxCadCmd PhdArxCadCmd::Instance()

PhdArxCadCmd.cpp

#include "stdafx.h"
#include "../stdafx.h"
#include "PhdArxCadCmd.h"
#include <acedCmdNF.h>

//初始化静态成员变量
std::unique_ptr<PhdArxCadCmd> PhdArxCadCmd::m_self;

PhdArxCadCmd* PhdArxCadCmd::Instance()
{
	//判断智能指针对象是否为空
	if (m_self.get() == nullptr)	//双重检查
	{
		//定义互斥量对象
		static std::mutex mutex;
		//定义智能锁对象
		std::lock_guard<std::mutex> alock(mutex);
		//判断智能指针对象对否为空
		if (m_self.get() == nullptr)
		{
			//创建实例,并绑定智能指针
			m_self.reset(new PhdArxCadCmd);
		}
	}

	return m_self.get();
}

void PhdArxCadCmd::EchoOff() const
{
	resbuf var;
	int nRs = acedGetVar(_T("CMDECHO"), &var);
	if (var.resval.rint)//打开了命令回显
	{
		//ObjectARX已经将acedCommand函数升级为acedCommandS函数, 使用该函数需要添加头文件”acedCmdNF.h”。
		acedCommandS(RTSTR, _T("CMDECHO"), RTSHORT, 0, RTNONE);
	}
}

bool PhdArxCadCmd::CallRegen() const
{
	int nRet = acedCommandS(RTSTR, _T("REGEN"), RTNONE);
	return nRet == RTNORM;
}

bool PhdArxCadCmd::SetDimLineScale(double dValue) const
{
	//int nRet = acedCommand(RTSTR, _T("DIMLFAC"), RTREAL, dValue, RTNONE);
	int nRet = acedCommandS(RTSTR, _T("DIMLFAC"), RTREAL, dValue, RTNONE);
	return nRet == RTNORM;
}

bool PhdArxCadCmd::SetDimScale(double dValue) const
{
	//int nRet = acedCommand(RTSTR, _T("DIMSCALE"), RTREAL, dValue, RTNONE);
	int nRet = acedCommandS(RTSTR, _T("DIMSCALE"), RTREAL, dValue, RTNONE);
	return nRet == RTNORM;
}

bool PhdArxCadCmd::SetWipeoutShow(bool bShow /*= false*/) const
{
	int nRet;
	if (bShow)
	{
		//nRet = acedCommand(RTSTR, _T("wipeout"), RTSTR, _T("f"), RTSTR, _T("on"), RTNONE);
		nRet = acedCommandS(RTSTR, _T("wipeout"), RTSTR, _T("f"), RTSTR, _T("on"), RTNONE);
	}
		
	else
	{
		//nRet = acedCommand(RTSTR, _T("wipeout"), RTSTR, _T("f"), RTSTR, _T("off"), RTNONE);
		nRet = acedCommandS(RTSTR, _T("wipeout"), RTSTR, _T("f"), RTSTR, _T("off"), RTNONE);
	}
		
	return nRet == RTNORM;
}

bool PhdArxCadCmd::SetFilletRadius(double dRadius) const
{
	//int nRet = acedCommand(RTSTR, _T("_fillet"), RTSTR, _T("r"), RTREAL, dRadius, RTNONE);
	int nRet = acedCommandS(RTSTR, _T("_fillet"), RTSTR, _T("r"), RTREAL, dRadius, RTNONE);
	return nRet == RTNORM;
}

bool PhdArxCadCmd::FilletByCommand(AcDbObjectId& idArc, const AcDbObjectId& idLine1, const AcDbObjectId& idLine2) const
{
	AcDbPoint* pt = new AcDbPoint(AcGePoint3d::kOrigin);
	AcDbObjectId ptId = g_ArxUtility->PostToModelSpace(pt);

	ads_name name1, name2;
	acdbGetAdsName(name1, idLine1);
	acdbGetAdsName(name2, idLine2);
	//int nRet = acedCommand(RTSTR, _T("_fillet"), RTENAME, name1, RTENAME, name2, RTNONE);
	int nRet = acedCommandS(RTSTR, _T("_fillet"), RTENAME, name1, RTENAME, name2, RTNONE);
	if (nRet != RTNORM)
	{
		g_ArxCommand->DeleteEnt(ptId);
		return false;
	}
		
	//得到圆弧id
	ads_name lastEnt;
	acdbEntLast(lastEnt);
	acdbGetObjectId(idArc, lastEnt);
	if (idArc == ptId)
	{
		g_ArxCommand->DeleteEnt(ptId);
		return false;
	}
	else
	{
		g_ArxCommand->DeleteEnt(ptId);
		return true;
	}
}

bool PhdArxCadCmd::OrientationEnt(const AcDbObjectId& idEnt) const
{
	AcDbEntityPointer pEnt(idEnt, AcDb::kForWrite);
	if (Acad::eOk != pEnt.openStatus())
		return false;
	AcDbExtents extent;
	pEnt->getGeomExtents(extent);
	pEnt->highlight();	//设置实体为高亮状态
	AcGePoint3d ptMin = extent.minPoint();
	AcGePoint3d ptMax = extent.maxPoint();
	double dWidth = fabs(ptMax.x - ptMin.x);
	double dHeight = fabs(ptMax.y - ptMin.y);
	AcGePoint3d CenterPt;
	CenterPt.x = (ptMax.x + ptMin.x) / 2;
	CenterPt.y = (ptMax.y + ptMin.y) / 2;
	ptMax.x = CenterPt.x + (dWidth / 2) * 2;
	ptMax.y = CenterPt.y + (dHeight / 2) * 2;
	ptMin.x = CenterPt.x - (dWidth / 2) * 2;
	ptMin.y = CenterPt.y - (dHeight / 2) * 2;

	CString strCommand;
	strCommand.Format(_T("ZOOM\nw\n%lf,%lf,%lf\n%lf,%lf,%lf\n"), ptMin.x, ptMin.y, ptMin.z, ptMax.x, ptMax.y, ptMax.z);
	acDocManager->sendStringToExecute(acDocManager->curDocument(), strCommand, true, false, false);
	return true;
}

bool PhdArxCadCmd::ZoomAllEnt() const
{
	//int nRet = acedCommand(RTSTR, _T("zoom"), RTSTR, _T("a"), RTNONE);
	int nRet = acedCommandS(RTSTR, _T("zoom"), RTSTR, _T("a"), RTNONE);
	return nRet == RTNORM;
}

bool PhdArxCadCmd::ZoomWindow(const AcGePoint3d& ptMin, const AcGePoint3d& ptMax) const
{
	int nRet = acedCommandS(RTSTR, _T("zoom"), RTSTR, _T("w"), RT3DPOINT, asDblArray(ptMin),
		RT3DPOINT, asDblArray(ptMax), RTNONE);
	return nRet == RTNORM;
}
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值