我新建一个ECSchema,并新建一个ECClass,添加两个属性,然后我用ImportSchema导入到dgn出错,
dgnOpenStatus值是DGNOPEN_STATUS_UnrecognizedFormat,为什么呢,老师们能帮我解答下吗?
代码如下:
DgnFilePtr openForWrite(WString filename, DgnFileOpenMode mode){ DgnDocumentPtr dgnDoc = DgnDocument::CreateForLocalFile(filename.c_str()); RefCountedPtr<DgnFile> dgnFile = DgnFile::Create(*dgnDoc, mode); StatusInt openForWriteStatus; DgnPlatform::DgnFileStatus dgnOpenStatus = dgnFile->LoadDgnFile(&openForWriteStatus); if (DGNFILE_STATUS_Success != dgnOpenStatus) return NULL; dgnFile->FillDictionaryModel(); return dgnFile;}
void newECClass(WCharCP unused){ WCharCP stringP = L"新建ECClass测试!"; mdlDialog_openInfoBox(stringP);
//新建一个ECClass DgnFilePtr dgnFile = openForWrite(gOptions.fileName, DgnFileOpenMode::ReadWrite); if (dgnFile.IsValid()) { DgnECManagerR dgnECManager = DgnECManager::GetManager(); ECN::ECSchemaPtr pSchema; WCharCP schemaName = L"schema_zqh"; dgnECManager.CreateSchema(pSchema, schemaName, 1, 0, dgnFile.get());
ECN::ECSchema *schemaP = pSchema.get(); WString name = schemaP->GetName(); ECN::SchemaKey ss = schemaP->GetSchemaKey(); ECClassP zqhClass; WString className = L"zqhClassName"; schemaP->CreateClass(zqhClass, className);
//ECProperty StructECProperty PrimitiveECProperty PrimitiveECPropertyP ecpProperty; WString priProName = L"priProName"; StructECPropertyP ecsProperty; WString struProName = L"struProName"; zqhClass->CreatePrimitiveProperty(ecpProperty, priProName); zqhClass->CreateStructProperty(ecsProperty, struProName); dgnECManager.UpdateSchema(*pSchema, *dgnFile, false); dgnECManager.ImportSchema(*pSchema, *dgnFile, false, true); }}
Answer Verified By: qh zh
PrimitiveECPropertyP binaryProperty; PrimitiveECPropertyP booleanProperty; PrimitiveECPropertyP dateTimeProperty; PrimitiveECPropertyP doubleProperty; PrimitiveECPropertyP integerProperty; PrimitiveECPropertyP longProperty; PrimitiveECPropertyP point2DProperty; PrimitiveECPropertyP point3DProperty; class1->CreatePrimitiveProperty(binaryProperty, L"BinaryProp"); class1->CreatePrimitiveProperty(booleanProperty, L"BooleanProp"); class1->CreatePrimitiveProperty(dateTimeProperty, L"DateTimeProp"); class1->CreatePrimitiveProperty(doubleProperty, L"DoubleProp"); class1->CreatePrimitiveProperty(integerProperty, L"IntProp"); class1->CreatePrimitiveProperty(longProperty, L"LongProp"); class1->CreatePrimitiveProperty(point2DProperty, L"Point2DProp"); class1->CreatePrimitiveProperty(point3DProperty, L"Point3DProp"); binaryProperty->SetTypeName (L"binary"); booleanProperty->SetTypeName (L"boolean"); dateTimeProperty->SetTypeName (L"dateTime"); doubleProperty->SetTypeName (L"double"); integerProperty->SetTypeName (L"int"); longProperty->SetTypeName (L"long"); point2DProperty->SetTypeName (L"point2d"); point3DProperty->SetTypeName (L"point3d");