Esempio n. 1
0
        /// <summary>
        /// //STILL NEEDS TO BE CHECKED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        /// should make it easier to change the data inside
        /// of any External Reference
        /// </summary>
        /// <param name="obj">External Reference whose information should be changed</param>
        /// <param name="field_name">Name of the Property which should be changed</param>
        /// <param name="field_value_new">The actual Value user wants the Property to have</param>
        public static void Xref_FieldChanger(BlockTableRecord obj, string field_name, Field field_value_new)
        {
            Document doc = global::Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                if (!obj.HasFields)
                {
                    ed.WriteMessage("\n{0} does not contain fields.", obj.Name);
                    return;
                }

                // Gets all the properties in the object
                // and allows to user to place them in an array
                ObjectId id        = obj.GetField();
                Field    fieldhldr = tr.GetObject(id, OpenMode.ForRead) as Field;
                Field[]  fields    = fieldhldr.GetChildren();

                // Finds the parameter whose name matches
                //"field_name" and allows the user to change its value
                var childField = from field in fields
                                 where field.Equals(field_name)
                                 select field;
                foreach (var field in childField)
                {
                    if (field.Equals(field_name))
                    {
                        string fldCode =
                            field.GetFieldCode(
                                FieldCodeFlags.AddMarkers |
                                FieldCodeFlags.FieldCode);
                        obj.SetField(fldCode, field_value_new);
                        break;
                    }
                }
                tr.Commit();
            }
        }
Esempio n. 2
0
        private static bool ModifyBlockTableRecordField(BlockTableRecord obj, string fieldName, string fieldValue)
        {
            using (var tr = CurrentDatabase.TransactionManager.StartTransaction())
            {
                if (!obj.HasFields)
                {
                    return(false);
                }

                var fields = ((Field)tr.GetObject(obj.GetField(), OpenMode.ForRead)).GetChildren();

                var requestedField = fields.FirstOrDefault(f => f.Equals(fieldName));

                var fieldCode = requestedField.GetFieldCode(FieldCodeFlags.AddMarkers | FieldCodeFlags.FieldCode);

                var newField = new Field(fieldValue);

                obj.SetField(fieldCode, newField);

                tr.Commit();
            }

            return(obj.FieldValueEquals(fieldName, fieldValue));
        }