// Função para gravar os dados no Extension Dictionary do objeto dado. public void RecOnXDict(DBObject dbObj, string location, DxfCode dxfC, dynamic data, Transaction tr) { // Pega o Id do XDic do objeto. ObjectId extId = dbObj.ExtensionDictionary; // Se não existe um XDic, cria-o if (extId == ObjectId.Null) { dbObj.CreateExtensionDictionary(); extId = dbObj.ExtensionDictionary; } // Pega o XDic a partir do seu Id. DBDictionary dbExt = (DBDictionary)tr.GetObject(extId, OpenMode.ForWrite); // Cria um XRecord, que guardará a informação Xrecord xRec = new Xrecord(); ResultBuffer rb = new ResultBuffer(); rb.Add(new TypedValue((int)dxfC, data)); xRec.Data = rb; // Adiciona a informação no XDic do objeto. dbExt.SetAt(location, xRec); tr.AddNewlyCreatedDBObject(xRec, true); }
/// <summary> /// Set "XData" on an Entity w/o directly manipulating a ResultBuffer. /// </summary> /// <param name="transactionToBeCommitted">An open transaction that will be Commit()ted</param> public static void SetXData(this DBObject dbObject, string data, DxfCode code, Transaction transactionToBeCommitted) { if (String.IsNullOrEmpty(data)) { throw new ArgumentNullException(/*MSG0*/ "data"); } dbObject.SetXData(rb => rb.AddValue(data, code), transactionToBeCommitted); }
/// <summary> /// Add the proper TypedValue to the ResultBuffer; this saves of the trouble of creating a TypedValue and casting DxfCode. /// /// This is called AddValue() rather than Add() to avoid confusion with ResultBuffer.Add(object) /// </summary> public static void AddValue(this ResultBuffer resultBuffer, string value, DxfCode code) { if (resultBuffer == null) { throw new ArgumentNullException(/*MSG0*/ "resultBuffer"); } switch (code) { case DxfCode.Text: case DxfCode.ExtendedDataRegAppName: case DxfCode.ExtendedDataAsciiString: break; default: throw new ArgumentOutOfRangeException(/*MSG0*/ "code"); } resultBuffer.Add(new TypedValue((int)code, value)); }
/// <summary> /// 修改扩展数据 /// </summary> /// <param name="id">对象的Id</param> /// <param name="regAppName">注册应用程序名</param> /// <param name="code">扩展数据的类型</param> /// <param name="oldValue">原来的扩展数据值</param> /// <param name="newValue">新的扩展数据值</param> public static void ModXData(this ObjectId id, string regAppName, DxfCode code, object oldValue, object newValue) { // 以写的方式打开对象 DBObject obj=id.GetObject(OpenMode.ForWrite); // 获取regAppName注册应用程序下的扩展数据列表 TypedValueList xdata=obj.GetXDataForApplication(regAppName); for (int i = 0; i < xdata.Count; i++)// 遍历扩展数据列表 { TypedValue tv=xdata[i]; //扩展数据 //判断扩展数据的类型和值是否满足条件 if (tv.TypeCode == (short)code && tv.Value.Equals(oldValue)) { // 设置新的扩展数据值 xdata[i] = new TypedValue(tv.TypeCode, newValue); break; //要修改的数据已找到,跳出循环 } } obj.XData = xdata; // 覆盖原来的扩展数据,达到修改的目的 obj.DowngradeOpen();// 为了安全,切换对象为读的状态 }
public static void Set(ObjectId id, string key, object value) { try { if (id.IsErased == false & id.IsEffectivelyErased == false) { using (World.Docu.LockDocument()) { using (Database db = World.Docu.Database) { using (Transaction tr = db.TransactionManager.StartTransaction()) { using (BlockReference br = (BlockReference)tr.GetObject(id, OpenMode.ForWrite)) { if (br.ExtensionDictionary == ObjectId.Null) { br.CreateExtensionDictionary(); } using (DBDictionary dict = (DBDictionary)tr.GetObject(br.ExtensionDictionary, OpenMode.ForWrite, false)) { DxfCode code = AcadIO.DxfHelper.GetFromObject(value); if (dict.Contains(key)) { Xrecord xRec = (Xrecord)tr.GetObject(dict.GetAt(key), OpenMode.ForWrite); ResultBuffer resBuf = new ResultBuffer(new TypedValue(Convert.ToInt32(code), value)); xRec.Data = resBuf; } else { Xrecord xRec = new Xrecord(); ResultBuffer resBuf = new ResultBuffer(new TypedValue(Convert.ToInt32(code), value)); xRec.Data = resBuf; dict.SetAt(key, xRec); tr.AddNewlyCreatedDBObject(xRec, true); } } } tr.Commit(); } } } } } catch (System.Exception ex) { Err.Log(ex); } }
public static void Set(string key, object value) { try { if (World.Docu != null) { if (World.Docu.IsActive == true && World.Docu.IsDisposed == false) { using (World.Docu.LockDocument()) { using (Database db = World.Docu.Database) { using (Transaction tr = db.TransactionManager.StartTransaction()) { using (DBDictionary dict = (DBDictionary)tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite, false)) { DxfCode code = AcadIO.DxfHelper.GetFromObject(value); if (dict.Contains(key)) { Xrecord xRec = (Xrecord)tr.GetObject(dict.GetAt(key), OpenMode.ForWrite); ResultBuffer resBuf = new ResultBuffer(new TypedValue(Convert.ToInt32(code), value)); xRec.Data = resBuf; } else { Xrecord xRec = new Xrecord(); ResultBuffer resBuf = new ResultBuffer(new TypedValue(Convert.ToInt32(code), value)); xRec.Data = resBuf; dict.SetAt(key, xRec); tr.AddNewlyCreatedDBObject(xRec, true); } } tr.Commit(); } } } } } } catch (System.Exception ex) { Err.Log(ex); } }
/// <summary> /// 添加DXF组码 /// </summary> /// <param name="typecode">DXF组码</param> public void Add(DxfCode typecode) { base.Add(new TypedValue((int)typecode)); }
public ExtendedDataRecord(DxfCode dxfCode, object value) { //TODO: finish the dxf code throw exception for wrong values }
public static TypedValue GetTypedValue(DxfCode code, object value) { return(new TypedValue((int)code, value)); }
public ResultTree Add(DxfCode type, object obj) { return(Add(new ResultTree(type, obj))); }
public void Set(DxfCode type) { _typedValue = new TypedValue((int)type); }
public void Set(DxfCode type, object obj) { _typedValue = new TypedValue((int)type, obj); }
public ResultTree(DxfCode type, object obj) : this(new TypedValue((int)type, obj)) { }
public void Add(DxfCode type, object obj) { base.Add(new TypedValue((int)type, obj)); }
/// <summary> /// Create a new System.Exception that indicates that the value with the given DXF type code cannot be converted to the given target type. /// </summary> /// <param name="typeCode">The DXF code.</param> /// <param name="targetTypeName">The target type.</param> /// <returns></returns> public static Exception InvalidConversion(DxfCode typeCode, string targetTypeName) { return(new Exception("DxfCode." + typeCode + " cannot be converted to type " + targetTypeName)); }
private object readValue(DxfCode code) { string strVal = ReadLine(); switch (code) { case DxfCode.XDictionary: case DxfCode.PReactors: case DxfCode.Operator: case DxfCode.XDataStart: case DxfCode.HeaderId: case DxfCode.End: return(null); case DxfCode.Start: case DxfCode.Text: case DxfCode.ShapeName: case DxfCode.AttributePrompt: case DxfCode.TextBigFontFile: case DxfCode.Handle: case DxfCode.DimBlk1: case DxfCode.DimBlk2: case DxfCode.LayerName: case DxfCode.CLShapeText: return(ReadLine()); case DxfCode.XCoordinate: case DxfCode.YCoordinate: case DxfCode.ZCoordinate: case DxfCode.Elevation: case DxfCode.Thickness: return(lineAsDouble(strVal)); case DxfCode.Real: case DxfCode.TxtStyleXScale: case DxfCode.TxtStylePSize: case DxfCode.ViewFrontClip: case DxfCode.ViewBackClip: case DxfCode.ShapeYOffset: case DxfCode.ShapeScale: case DxfCode.PixelScale: case DxfCode.LinetypeScale: case DxfCode.DashLength: case DxfCode.Angle: case DxfCode.ViewportTwist: return(lineAsDouble(strVal)); //float ?? case DxfCode.Visibility: case DxfCode.LayerLinetype: case DxfCode.Color: case DxfCode.HasSubentities: case DxfCode.ViewportVisibility: case DxfCode.ViewportActive: case DxfCode.ViewportNumber: case DxfCode.Int16: case DxfCode.ViewMode: case DxfCode.CircleSides: case DxfCode.ViewportZoom: case DxfCode.ViewportIcon: case DxfCode.ViewportSnap: case DxfCode.ViewportGrid: case DxfCode.ViewportSnapStyle: case DxfCode.ViewportSnapPair: return(lineAsShort(strVal)); case DxfCode.Int32: return(lineAsInt(strVal)); case DxfCode.Subclass: case DxfCode.EmbeddedObjectStart: case DxfCode.ControlString: return(LastValueAsString); case DxfCode.DimVarHandle: return(lineAsHandle(strVal)); case DxfCode.UcsOrg: case DxfCode.UcsOrientationX: case DxfCode.UcsOrientationY: case DxfCode.XReal: case DxfCode.ViewBrightness: case DxfCode.ViewContrast: return(lineAsDouble(strVal)); case DxfCode.Int64: return(lineAsLong(strVal)); case DxfCode.XInt16: return(lineAsShort(strVal)); case DxfCode.NormalX: case DxfCode.NormalY: case DxfCode.NormalZ: return(lineAsDouble(strVal)); case DxfCode.XXInt16: case DxfCode.Int8: case DxfCode.RenderMode: return(lineAsShort(strVal)); case DxfCode.Bool: return(lineAsBool(strVal)); case DxfCode.XTextString: return(ReadLine()); case DxfCode.BinaryChunk: return(lineAsBinaryChunk(strVal)); case DxfCode.ArbitraryHandle: case DxfCode.SoftPointerId: case DxfCode.HardPointerId: case DxfCode.MaterialHandleId: case DxfCode.SoftOwnershipId: case DxfCode.HardOwnershipId: return(lineAsHandle(strVal)); case DxfCode.LineWeight: case DxfCode.PlotStyleNameType: return(lineAsShort(strVal)); case DxfCode.PlotStyleNameId: return(lineAsHandle(strVal)); case DxfCode.ExtendedInt16: return(lineAsShort(strVal)); case DxfCode.LayoutName: return(ReadLine()); case DxfCode.ColorRgb: return(lineAsInt(strVal)); case DxfCode.ColorName: return(ReadLine()); case DxfCode.Alpha: case DxfCode.GradientObjType: case DxfCode.GradientPatType: case DxfCode.GradientTintType: case DxfCode.GradientColCount: return(lineAsInt(strVal)); case DxfCode.GradientAngle: case DxfCode.GradientShift: case DxfCode.GradientTintVal: case DxfCode.GradientColVal: return(lineAsDouble(strVal)); case DxfCode.GradientName: return(ReadLine()); case DxfCode.HardPointHandle: case DxfCode.HardPointHandle1: return(lineAsHandle(strVal)); case DxfCode.Comment: return(ReadLine()); case DxfCode.ExtendedDataAsciiString: case DxfCode.ExtendedDataRegAppName: case DxfCode.ExtendedDataControlString: case DxfCode.ExtendedDataLayerName: return(ReadLine()); case DxfCode.ExtendedDataBinaryChunk: return(lineAsBinaryChunk(strVal)); case DxfCode.ExtendedDataHandle: return(ReadLine()); case DxfCode.ExtendedDataXCoordinate: case DxfCode.ExtendedDataWorldXCoordinate: case DxfCode.ExtendedDataWorldXDisp: case DxfCode.ExtendedDataWorldXDir: case DxfCode.ExtendedDataYCoordinate: case DxfCode.ExtendedDataWorldYCoordinate: case DxfCode.ExtendedDataWorldYDisp: case DxfCode.ExtendedDataWorldYDir: case DxfCode.ExtendedDataZCoordinate: case DxfCode.ExtendedDataWorldZCoordinate: case DxfCode.ExtendedDataWorldZDisp: case DxfCode.ExtendedDataWorldZDir: case DxfCode.ExtendedDataReal: case DxfCode.ExtendedDataDist: case DxfCode.ExtendedDataScale: return(lineAsDouble(strVal)); case DxfCode.ExtendedDataInteger16: return(lineAsShort(strVal)); case DxfCode.ExtendedDataInteger32: return(lineAsInt(strVal)); case DxfCode.Invalid: default: throw new DxfException((int)code, this.Line); } }