cart: empty [ Login ]

DxfXRecord how to?

1 
Earthbound
4/26/2008 1:13 AM
Wout could you complete/correct the following psuedocode for me?
C# Code:
private void ConvertTxtInDXF( out byte[] dxfFile) { MemoryStream dxfStream = new MemoryStream(dxfFile); DxfModel model = new DxfModel(DxfVersion.Dxf18); DxfXRecord xr = new DxfXRecord(); model = DxfReader.ReadDxf(dxfStream); foreach (DxfEntity ent in model.Entities) {              if (ent.EntityType.ToString() == 'TEXT') {    string txt = ((DxfText)ent).Text.ToString().Trim();    //put this tag into an XRecord    if (txt.IndexOf('xxTAGxx') > -1) {      //What does the (int) code represent in the DxfXRecord?      //Are they related to the group codes in the DXF Spec?      xr.Values.Add(new DxfXRecordValue(5, txt));      //how do I now add it to the model?      model.____________.Add(xr);      //clear the tag from the dxf      ((DxfText)ent).Text = string.Empty;      break;    }   } } DxfWriter dw = new DxfWriter(dxfStream, model, false); dw.AutoCloseStream = false; dw.Write(true); dxfFile = dxfStream.ToArray(); }
Have a great weekend! Johan.
Wout
4/27/2008 12:29 PM
Hi Johan, Objects are part of the object dictionary tree, as opposed to entities that go into the DxfModel.Entities collection. The dictionary tree is rooted in DxfModel.DictionaryRoot. So you can add the XRECORD directly to the root dictionary, or organize it in your own child dictionary. Let me know if that gets you going. Wout PS 1: Those ToString() calls you do are not necessary. PS 2: You can also do (bit more efficient):   DxfText textEntity = entity as DxfText;   if (textEntity != null) {     xrecord.Values.Add(new DxfXRecordValue(5, textEntity.Text));   }
1