本文主要是介绍ObjectArx调用cad内部命令,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
PhdArxCadCmd.h
#pragma once
#include <memory>
#include <mutex>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;}//得到圆弧idads_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;
}
这篇关于ObjectArx调用cad内部命令的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!