/// <summary> /// Рисуем слой /// </summary> /// <param name="wl"> слой </param> public void DrawLayer(Data.DataLayer wl) { //List<Entity> wEntlist = new List<Entity>(); Autodesk.Gis.Map.ObjectData.Table wTbl = null; if (wl.HasAttributes()) { wTbl = CreateODTable(wl._Rule); } ObjectId wid; Entity wEnt; Geometry.TGeometry g; foreach (Data.MyRecord wr in wl.Table) { g = wr.GetGeometry(); if (g != null) { wEnt = MakeGeometry(g); wid = DrawEntity(wEnt); if (wl.HasAttributes()) { AddAttr(wid, wr, wTbl); } } //wEntlist.Add(wEnt); } //DrawEntity(wEntlist); }
/// <summary>Добавляем ObjectData-атрибуты к примитиву чертежа</summary> /// <param name="wid"> ObjectId примитива </param> /// <param name="wr"> Данные атрибутов </param> /// <param name="wTbl"> Таблица ObjectData </param> public void AddAttr(ObjectId wid, Data.MyRecord wr, Autodesk.Gis.Map.ObjectData.Table wTbl) { if (wTbl == null) { return; } var acDoc = Application.DocumentManager.MdiActiveDocument; using (acDoc.LockDocument()) { using (var acTrans = acDoc.Database.TransactionManager.StartTransaction()) { using (var odRecord = Record.Create()) { wTbl.InitRecord(odRecord); for (var i = 0; i < wTbl.FieldDefinitions.Count; i++) { var fdef = wTbl.FieldDefinitions[i]; var fval = wr.SearchField(fdef.Name); if (fval != null) { if (!fval.IsGeom) { odRecord[i].Assign(fval.GetString()); } } } wTbl.AddRecord(odRecord, wid); acTrans.Commit(); } } } }
/// <summary> /// Добавляем ObjectData-атрибуты к примитиву чертежа /// </summary> /// <param name="wid"> ObjectId примитива </param> /// <param name="wr"> Данные атрибутов </param> /// <param name="wTbl"> Таблица ObjectData </param> public void AddAttr(ObjectId wid, Data.MyRecord wr, Autodesk.Gis.Map.ObjectData.Table wTbl) { AppServ.Document acDoc = AppServ.Application.DocumentManager.MdiActiveDocument; using (AppServ.DocumentLock acLckDoc = acDoc.LockDocument()) { using (Transaction acTrans = acDoc.Database.TransactionManager.StartTransaction()) { using (Record odRecord = Record.Create()) { wTbl.InitRecord(odRecord); FieldDefinition fdef; Data.FieldValue fval; for (int i = 0; i < wTbl.FieldDefinitions.Count; i++) { fdef = wTbl.FieldDefinitions[i]; fval = wr.SearchField(fdef.Name); if (fval != null) { if (!fval.IsGeom) { odRecord[i].Assign(fval.GetString()); } } } wTbl.AddRecord(odRecord, wid); acTrans.Commit(); } } } }
/// <summary>Рисуем слой</summary> /// <param name="wl"> слой </param> public void DrawLayer(Data.DataLayer wl) { if (!wl.HasGeometry()) { return; } Autodesk.Gis.Map.ObjectData.Table wTbl = null; if (wl.HasAttributes()) { wTbl = CreateOdTable(wl._Rule); } foreach (var wr in wl.Table) { var g = wr.GetGeometry(); if (g == null || g.IsEmpty() || !g.IsValid()) { continue; } if (wl.HasAttributes()) { AddAttr(DrawEntity(MakeGeometry(g)), wr, wTbl); } } }
private void AnnotationDlg_Load(object sender, System.EventArgs e) { try { m_mapApp = Autodesk.Gis.Map.HostMapApplicationServices.Application; m_annotations = m_mapApp.ActiveProject.Annotations; m_idTemplate = ObjectId.Null; m_templateName = ""; m_colODtblList = null; m_ODTableName = ""; m_ODTables = null; m_ODTable = null; m_selectedTemplateName = ""; m_fieldNameCheckBoxStatus = 0; m_annoOverrides = new AnnotationOverrides(); m_annoOverrides.Clear(); this.textbTemplateName.Text = ""; this.listbColumnName.Items.Clear(); this.listbODTable.SelectedIndex = -1; AnnoTemplateNameListBoxUpdate(); InitODTableList(); btnCreateNew.Enabled = false; InitButtons(); checkbFieldName.Checked = false; } catch(System.Exception err) { MessageBox.Show(err.Message); } }
//-------------------------------------------------------------------------- // // ���ܣ���ȡ�������ݵ��ֶ� // // ���ߣ� // // ���ڣ�200708 // // ��ʷ�� //-------------------------------------------------------------------------- private void listbODTable_SelectedIndexChanged(Object sender, EventArgs e) { try { m_ODTableName = ""; listbColumnName.Items.Clear(); int curSel = listbODTable.SelectedIndex; if (LB_ERR != curSel) { m_ODTableName = listbODTable.SelectedItem.ToString(); m_ODTable = m_ODTables[m_ODTableName]; FieldDefinitions fieldDefs = m_ODTable.FieldDefinitions; listbColumnName.BeginUpdate(); for (int index = 0; index < fieldDefs.Count; index++) { FieldDefinition fieldDef = fieldDefs[index]; string colName = fieldDef.Name; if (listbColumnName.FindStringExact(colName) == -1) { listbColumnName.Items.Add(colName); } } listbColumnName.EndUpdate(); } } catch (System.Exception err) { MessageBox.Show(err.Message); } }
//Loops through all ODTables in document and creates corresponding PropertySetDefinitions public static void oddatacreatepropertysetsdefs() { DocumentCollection docCol = Application.DocumentManager; Database localDb = docCol.MdiActiveDocument.Database; Editor ed = docCol.MdiActiveDocument.Editor; Document doc = docCol.MdiActiveDocument; CivilDocument civilDoc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument; //Reference ODTables Tables tables = HostMapApplicationServices.Application.ActiveProject.ODTables; StringCollection tableNames = tables.GetTableNames(); foreach (string name in tableNames) { Table curTable = tables[name]; try { // (1) create prop set def PropertySetDefinition propSetDef = new PropertySetDefinition(); propSetDef.SetToStandard(localDb); propSetDef.SubSetDatabaseDefaults(localDb); // alternatively, you can use dictionary's NewEntry // Dim dictPropSetDef = New DictionaryPropertySetDefinitions(db) // Dim propSetDef As PropertySetDefinition = // dictPropSetDef.NewEntry() // General tab propSetDef.Description = name; // Applies To tab // apply to objects or styles. True if style, False if objects bool isStyle = false; var appliedTo = new StringCollection(); appliedTo.Add("AcDbLine"); appliedTo.Add("AcDbSpline"); appliedTo.Add("AcDbPolyline"); appliedTo.Add("AcDb3dPolyline"); appliedTo.Add(RXClass.GetClass(typeof(BlockReference)).Name); appliedTo.Add(RXClass.GetClass(typeof(DBPoint)).Name); propSetDef.SetAppliesToFilter(appliedTo, isStyle); FieldDefinitions defs = curTable.FieldDefinitions; int defsCount = defs.Count; for (int i = 0; i < defsCount; i++) { FieldDefinition curFd = defs[i]; string fieldDefName = curFd.Name; string fieldDefDescription = curFd.Description; DataType fieldType = curFd.Type; // Definition tab // (2) we can add a set of property definitions. // We first make a container to hold them. // This is the main part. A property set definition can contain // a set of property definition. // (2.1) let's first add manual property. // Here we use text type var propDefManual = new PropertyDefinition(); propDefManual.SetToStandard(localDb); propDefManual.SubSetDatabaseDefaults(localDb); propDefManual.Name = fieldDefName; propDefManual.Description = fieldDefDescription; propDefManual.DataType = GetCorrespondingPropertyDataType(fieldType); propDefManual.DefaultData = ConvertDefaultValue(curFd); // add to the prop set def propSetDef.Definitions.Add(propDefManual); } using (Transaction tx = localDb.TransactionManager.StartTransaction()) { //check if prop set already exists var dictPropSetDef = new DictionaryPropertySetDefinitions(localDb); if (dictPropSetDef.Has(name, tx)) { ed.WriteMessage("\nError - the property set defintion already exists: " + name); tx.Abort(); continue; } dictPropSetDef.AddNewRecord(name, propSetDef); tx.AddNewlyCreatedDBObject(propSetDef, true); tx.Commit(); } } catch (System.Exception ex) { ed.WriteMessage("\nError while creating Property Set definitions: " + ex.ToString()); return; } } ed.WriteMessage("\nFinished!"); }
public static void populatepropertysetswithoddata() { DocumentCollection docCol = Application.DocumentManager; Database localDb = docCol.MdiActiveDocument.Database; Editor ed = docCol.MdiActiveDocument.Editor; Document doc = docCol.MdiActiveDocument; CivilDocument civilDoc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument; //Reference ODTables Tables tables = HostMapApplicationServices.Application.ActiveProject.ODTables; DictionaryPropertySetDefinitions dictPropSetDef = new DictionaryPropertySetDefinitions(localDb); using (Transaction tx = localDb.TransactionManager.StartTransaction()) { try { //I need to work with 3d polylines //Change here to add other types of objects HashSet <Entity> ents = new HashSet <Entity>(); ents.UnionWith(localDb.HashSetOfType <Line>(tx)); ents.UnionWith(localDb.HashSetOfType <Spline>(tx)); ents.UnionWith(localDb.HashSetOfType <DBPoint>(tx)); ents.UnionWith(localDb.HashSetOfType <Polyline>(tx)); ents.UnionWith(localDb.HashSetOfType <Polyline3d>(tx)); ents.UnionWith(localDb.HashSetOfType <BlockReference>(tx)); //ents = ents.Where(x => x.Layer == "0-FJV_fremtid").ToHashSet(); foreach (Entity ent in ents) { ObjectIdCollection psIds = PropertyDataServices.GetPropertySets(ent); List <PropertySet> pss = new List <PropertySet>(); foreach (Oid oid in psIds) { pss.Add(oid.Go <PropertySet>(tx, OpenMode.ForWrite)); } using (Records records = tables.GetObjectRecords(0, ent.Id, Autodesk.Gis.Map.Constants.OpenMode.OpenForRead, false)) { int recordsCount = records.Count; for (int i = 0; i < recordsCount; i++) { Record record = records[i]; string tableName = record.TableName; //Specific to my implementation if (tableName == "IdRecord") { continue; } PropertySet propertySet = pss.Find(x => x.PropertySetDefinitionName == tableName); if (propertySet == null) { tx.Abort(); ed.WriteMessage($"\nPropertySet with the name {tableName} could not be found!"); return; } Table table = tables[tableName]; FieldDefinitions fDefs = table.FieldDefinitions; int fieldsCount = fDefs.Count; for (int j = 0; j < fieldsCount; j++) { FieldDefinition fDef = fDefs[j]; string fieldName = fDef.Name; int columnIndex = fDefs.GetColumnIndex(fieldName); MapValue value = record[columnIndex]; int psIdCurrent = propertySet.PropertyNameToId(fieldName); propertySet.SetAt(psIdCurrent, GetMapValueData(value)); } } } } } catch (System.Exception ex) { tx.Abort(); ed.WriteMessage(ex.ToString()); return; } tx.Commit(); prdDbg("Finished!"); } }