标注属性比较
在涉及到标注相关开发的时候 部分情况下可能不清楚具体那个属性是由哪个参数控制的 有了下面的比较代码 问题迎刃而解 拷贝一个相同的标注,然后修改你需要控制的属性,然后比较一下,问题立马解决了。 //----------------------------------------------------------------------------- //----- acrxEntryPoint.h //----------------------------------------------------------------------------- #include "StdAfx.h" #include "resource.h" //----------------------------------------------------------------------------- #define szRDS _RXST("") // 功能:将选择集转换为实体ID数组 // 参数: ObjIds,实体ID数组 // ssName,选择集 // 返回: void SSToIds(AcDbObjectIdArray& ObjIds,ads_name ssName) { AcDbObjectId ObjId; ads_name EntName; long nLength=0; acedSSLength(ssName,&nLength); for(int nLen=0; nLen<nLength;nLen++) { acedSSName(ssName,nLen,EntName); acdbGetObjectId(ObjId,EntName); ObjIds.append(ObjId); } } // 把AcDb::lineWeight类型的值转换成字符串 CString LnWeightToString(AcDb::LineWeight type) { if (type == AcDb::kLnWt000) return _T("kLnWt000"); else if (type == AcDb::kLnWt005) return _T("kLnWt005"); else if (type == AcDb::kLnWt009) return _T("kLnWt009"); else if (type == AcDb::kLnWt013) return _T("kLnWt013"); else if (type == AcDb::kLnWt015) return _T("kLnWt015"); else if (type == AcDb::kLnWt018) return _T("kLnWt018"); else if (type == AcDb::kLnWt020) return _T("kLnWt020"); else if (type == AcDb::kLnWt025) return _T("kLnWt025"); else if (type == AcDb::kLnWt030) return _T("kLnWt030"); else if (type == AcDb::kLnWt035) return _T("kLnWt035"); else if (type == AcDb::kLnWt040) return _T("kLnWt040"); else if (type == AcDb::kLnWt050) return _T("kLnWt050"); else if (type == AcDb::kLnWt053) return _T("kLnWt053"); else if (type == AcDb::kLnWt060) return _T("kLnWt060"); else if (type == AcDb::kLnWt070) return _T("kLnWt070"); else if (type == AcDb::kLnWt080) return _T("kLnWt080"); else if (type == AcDb::kLnWt090) return _T("kLnWt090"); else if (type == AcDb::kLnWt100) return _T("kLnWt100"); else if (type == AcDb::kLnWt106) return _T("kLnWt106"); else if (type == AcDb::kLnWt120) return _T("kLnWt120"); else if (type == AcDb::kLnWt140) return _T("kLnWt140"); else if (type == AcDb::kLnWt158) return _T("kLnWt158"); else if (type == AcDb::kLnWt200) return _T("kLnWt200"); else if (type == AcDb::kLnWt211) return _T("kLnWt211"); else if (type == AcDb::kLnWtByLayer) return _T("kLnWtByLayer"); else if (type == AcDb::kLnWtByBlock) return _T("kLnWtByBlock"); else if (type == AcDb::kLnWtByLwDefault) return _T("kLnWtByLwDefault"); else return _T("kUnknown"); } //属性 struct GProperty { CString strName; CString strValue; GProperty() { } ~GProperty() { } GProperty(const GProperty& prop) { strName=prop.strName; strValue=prop.strValue; } GProperty& operator=(const GProperty& prop) { if(this==&prop) return *this; strName=prop.strName; strValue=prop.strValue; return *this; } GProperty(CString name,CString value) { strName=name; strValue=_T("string:")+value; } GProperty(CString name,bool value) { strName=name; strValue=value?_T("bool:true"):_T("bool:false"); } GProperty(CString name,int value) { strName=name; strValue.Format(_T("int:%d"),value); } GProperty(CString name,double value) { strName=name; strValue.Format(_T("double:%f"),value); } GProperty(CString name,TCHAR value) { strName=name; strValue.Format(_T("char:%c"),value); } GProperty(CString name,AcCmColor value) { strName=name; strValue.Format(_T("COLOR:RGB(%d,%d,%d)"),value.red(),value.green(),value.blue()); } GProperty(CString name,AcDbObjectId value) { strName=name; if(!value.isValid()) { strValue=_T("AcDbObjectId:kNull"); } else { TCHAR tmpStr[256]={0}; value.handle().getIntoAsciiBuffer(tmpStr); strValue=_T("AcDbObjectId:"); strValue+=tmpStr; } } GProperty(CString name,AcDb::LineWeight value) { strName=name; strValue=_T("LineWeight:"); strValue+=LnWeightToString(value); } }; struct GPropertyList { CArray<GProperty> m_propList; GPropertyList() { } GPropertyList(const GPropertyList& src) { m_propList.RemoveAll(); m_propList.Append(src.m_propList); } GPropertyList& operator=(const GPropertyList& src) { if(this==&src) { return *this; } m_propList.RemoveAll(); m_propList.Append(src.m_propList); return *this; } int Add(GProperty prop) { for(int i=0;i<m_propList.GetCount();i++) { GProperty& tmp=m_propList.GetAt(i); if(tmp.strName.CompareNoCase(prop.strName)==0) { m_propList.SetAt(i,prop); return i; } } return m_propList.Add(prop); } void Diff(GPropertyList& diff) { for(int i=0;i<m_propList.GetCount();i++) { bool bFind=false; for(int j=0;j<diff.m_propList.GetCount();j++) { if(m_propList.GetAt(i).strName.CompareNoCase(diff.m_propList.GetAt(j).strName)==0) { bFind=true; if(m_propList.GetAt(i).strValue.CompareNoCase(diff.m_propList.GetAt(j).strValue)!=0) { acutPrintf(_T("\n 修改属性[%s]值[%s]为新值[%s]"),m_propList.GetAt(i).strName,m_propList.GetAt(i).strValue,diff.m_propList.GetAt(j).strValue); } break; } } if(bFind) { continue; } acutPrintf(_T("\n 删除属性[%s]值[%s]"),m_propList.GetAt(i).strName,m_propList.GetAt(i).strValue); } for(int i=0;i<diff.m_propList.GetCount();i++) { bool bFind=false; for(int j=0;j<m_propList.GetCount();j++) { if(diff.m_propList.GetAt(i).strName.CompareNoCase(m_propList.GetAt(j).strName)==0) { bFind=true; break; } } if(bFind) { continue; } acutPrintf(_T("\n 新增属性[%s]值[%s]"),diff.m_propList.GetAt(i).strName,diff.m_propList.GetAt(i).strValue); } } }; GPropertyList Glb_LastPropertyList; //读取标注的属性 void ReadDimAttr(GPropertyList& list,AcDbDimension* pDim) { list.Add(GProperty(_T("dimadec"),pDim->dimadec())); list.Add(GProperty(_T("dimalt"),pDim->dimalt())); list.Add(GProperty(_T("dimaltd"),pDim->dimaltd())); list.Add(GProperty(_T("dimaltf"),pDim->dimaltf())); list.Add(GProperty(_T("dimaltrnd"),pDim->dimaltrnd())); list.Add(GProperty(_T("dimalttd"),pDim->dimalttd())); list.Add(GProperty(_T("dimalttz"),pDim->dimalttz())); list.Add(GProperty(_T("dimaltu"),pDim->dimaltu())); list.Add(GProperty(_T("dimaltz"),pDim->dimaltz())); list.Add(GProperty(_T("dimapost"),pDim->dimapost())); list.Add(GProperty(_T("dimarcsym"),pDim->dimarcsym())); list.Add(GProperty(_T("dimasz"),pDim->dimasz())); list.Add(GProperty(_T("dimatfit"),pDim->dimatfit())); list.Add(GProperty(_T("dimaunit"),pDim->dimaunit())); list.Add(GProperty(_T("dimazin"),pDim->dimazin())); list.Add(GProperty(_T("dimblk"),pDim->dimblk())); list.Add(GProperty(_T("dimblk1"),pDim->dimblk1())); list.Add(GProperty(_T("dimblk2"),pDim->dimblk2())); list.Add(GProperty(_T("dimcen"),pDim->dimcen())); list.Add(GProperty(_T("dimclrd"),pDim->dimclrd())); list.Add(GProperty(_T("dimclre"),pDim->dimclre())); list.Add(GProperty(_T("dimclrt"),pDim->dimclrt())); list.Add(GProperty(_T("dimdec"),pDim->dimdec())); list.Add(GProperty(_T("dimdle"),pDim->dimdle())); list.Add(GProperty(_T("dimdli"),pDim->dimdli())); list.Add(GProperty(_T("dimdsep"),pDim->dimdsep())); list.Add(GProperty(_T("dimexe"),pDim->dimexe())); list.Add(GProperty(_T("dimexo"),pDim->dimexo())); list.Add(GProperty(_T("dimfrac"),pDim->dimfrac())); list.Add(GProperty(_T("dimgap"),pDim->dimgap())); list.Add(GProperty(_T("dimjogang"),pDim->dimjogang())); list.Add(GProperty(_T("dimjust"),pDim->dimjust())); list.Add(GProperty(_T("dimldrblk"),pDim->dimldrblk())); list.Add(GProperty(_T("dimlfac"),pDim->dimlfac())); list.Add(GProperty(_T("dimlim"),pDim->dimlim())); list.Add(GProperty(_T("dimltex1"),pDim->dimltex1())); list.Add(GProperty(_T("dimltex2"),pDim->dimltex2())); list.Add(GProperty(_T("dimltype"),pDim->dimltype())); list.Add(GProperty(_T("dimlunit"),pDim->dimlunit())); list.Add(GProperty(_T("dimlwd"),pDim->dimlwd())); list.Add(GProperty(_T("dimlwe"),pDim->dimlwe())); list.Add(GProperty(_T("dimpost"),pDim->dimpost())); list.Add(GProperty(_T("dimrnd"),pDim->dimrnd())); list.Add(GProperty(_T("dimsah"),pDim->dimsah())); list.Add(GProperty(_T("dimscale"),pDim->dimscale())); list.Add(GProperty(_T("dimsd1"),pDim->dimsd1())); list.Add(GProperty(_T("dimsd2"),pDim->dimsd2())); list.Add(GProperty(_T("dimse1"),pDim->dimse1())); list.Add(GProperty(_T("dimse2"),pDim->dimse2())); list.Add(GProperty(_T("dimsoxd"),pDim->dimsoxd())); list.Add(GProperty(_T("dimtad"),pDim->dimtad())); list.Add(GProperty(_T("dimtdec"),pDim->dimtdec())); list.Add(GProperty(_T("dimtfac"),pDim->dimtfac())); list.Add(GProperty(_T("dimtfill"),pDim->dimtfill())); list.Add(GProperty(_T("dimtfillclr"),pDim->dimtfillclr())); list.Add(GProperty(_T("dimtih"),pDim->dimtih())); list.Add(GProperty(_T("dimtix"),pDim->dimtix())); list.Add(GProperty(_T("dimtm"),pDim->dimtm())); list.Add(GProperty(_T("dimtmove"),pDim->dimtmove())); list.Add(GProperty(_T("dimtofl"),pDim->dimtofl())); list.Add(GProperty(_T("dimtoh"),pDim->dimtoh())); list.Add(GProperty(_T("dimtol"),pDim->dimtol())); list.Add(GProperty(_T("dimtolj"),pDim->dimtolj())); list.Add(GProperty(_T("dimtp"),pDim->dimtp())); list.Add(GProperty(_T("dimtsz"),pDim->dimtsz())); list.Add(GProperty(_T("dimtvp"),pDim->dimtvp())); list.Add(GProperty(_T("dimtxsty"),pDim->dimtxsty())); list.Add(GProperty(_T("dimtxt"),pDim->dimtxt())); list.Add(GProperty(_T("dimtzin"),pDim->dimtzin())); list.Add(GProperty(_T("dimupt"),pDim->dimupt())); list.Add(GProperty(_T("dimzin"),pDim->dimzin())); list.Add(GProperty(_T("dimfxlenOn"),pDim->dimfxlenOn())); list.Add(GProperty(_T("dimfxlen"),pDim->dimfxlen())); } void DimAttr() { AcDbObjectIdArray ids; ads_name ssName; resbuf* rb = acutBuildList(RTDXF0, _T("DIMENSION"), 0); TCHAR* promptPtrs[2]={_T("\n选择原始标注:"),_T("\n移除原始标注:")}; int rc=acedSSGet(_T(":S:$"), promptPtrs,NULL,rb,ssName); if(rc!=RTNORM) { acutRelRb(rb); return; } acutRelRb(rb); SSToIds(ids,ssName); acedSSFree(ssName); if(ids.logicalLength()!=1) { return; } AcDbEntityPointer spEnt(ids.at(0),AcDb::kForRead); if(spEnt.openStatus()!=Acad::eOk) { return; } if(!spEnt->isKindOf(AcDbDimension::desc())) { return; } AcDbDimension* pDim=AcDbDimension::cast(spEnt.object()); GPropertyList list; ReadDimAttr(list,pDim); AcDbObjectIdArray ids1; ads_name ssName1; resbuf* rb1 = acutBuildList(RTDXF0, _T("DIMENSION"), 0); TCHAR* promptPtrs1[2]={_T("\n选择修改后的标注:"),_T("\n移除修改后的标注:")}; int rc1=acedSSGet(_T(":S:$"), promptPtrs1,NULL,rb1,ssName1); if(rc1!=RTNORM) { acutRelRb(rb1); return; } acutRelRb(rb1); SSToIds(ids1,ssName1); acedSSFree(ssName1); if(ids1.logicalLength()!=1) { return; } AcDbEntityPointer spEnt1(ids1.at(0),AcDb::kForRead); if(spEnt1.openStatus()!=Acad::eOk) { return; } if(!spEnt1->isKindOf(AcDbDimension::desc())) { return; } AcDbDimension* pDim1=AcDbDimension::cast(spEnt1.object()); GPropertyList list1; ReadDimAttr(list1,pDim1); list.Diff(list1); } //----------------------------------------------------------------------------- //----- ObjectARX EntryPoint class CDimAttrApp : public AcRxArxApp { public: CDimAttrApp () : 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) ; acedRegCmds->addCommand(_T("DimAttrApp"), _T("DimAttr"), _T("DimAttr"), 0, DimAttr); // 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 acedRegCmds->removeGroup(_T("DimAttrApp")); return (retCode) ; } virtual void RegisterServerComponents () { } } ; //----------------------------------------------------------------------------- IMPLEMENT_ARX_ENTRYPOINT(CDimAttrApp)查看完整版本: 标注属性比较
Tags: