| Article | 70002416 |
| Type | Wish |
| Product | Engine |
| Date Added | 9/27/2023 12:00:00 AM |
| Fixed | 10.1005.0.1 (9/27/2023 12:00:00 AM) |
| Submitted by | JK |
Summary
Save Open to from stream and data buffer
Solution
In version 1005.0.1 following methods was added to vdDocument object
System.IO.MemoryStream SaveToMemoryStream(string fileTypeExtension)
Exports the document to a memory stream using the file format defined by the passed fileTypeExtension.
"fileTypeExtension": It can be one of the following strings ".vdml",".vdcl",".vds",".vdf",".dxf",".dwg",".dgn",".pdf"
returns: A System.IO.MemoryStream object if success else null
bool LoadFromStream(System.IO.Stream stream, string fileTypeExtension)
Load the drawing from the passed stream
"stream": A System.IO.MemoryStream object
"fileTypeExtension": The type of the data that the passed stream is created. It can be one of the following strings ".vdml",".vdcl",".vds",".vdf",".dxf",".dwg",".dgn",".pdf"
byte[] SaveToDataBuffer(string fileTypeExtension)
Exports the document to a byte array using the file format defined by the passed fileTypeExtension.
"fileTypeExtension": It can be one of the following strings ".vdml",".vdcl",".vds",".vdf",".dxf",".dwg",".dgn",".pdf"
returns: An array of bytes if success else null
bool LoadFromDataBuffer(ref byte []bytes, int offset, int count, string fileTypeExtension)
Load the drawing from the passed bytes array data
"bytes": An array of bytes contains the contents of a drawing file
"offset": The offset of the first byte to read from buffer which is the start of the file buffer.
"count": The number of bytes to read from buffer which is the end of the file buffer.
"fileTypeExtension": The type of file that the data is created. It can be one of the following strings ".vdml",".vdcl",".vds",".vdf",".dxf",".dwg",".dgn",".pdf"
Managed C# Code Sample:
doc.Open(@"C:\someFolder\someFile.vdml");
System.IO.MemoryStream MS = doc.SaveToMemoryStream(".dxf");
doc.New();
doc.LoadFromStream(MS, ".dxf");
doc.Redraw(true);
and
doc.Open(@"C:\someFolder\someFile.vdml");
Byte[] arBytes = doc.SaveToDataBuffer(".dxf");
doc.New();
doc.LoadFromDataBuffer(ref arBytes, 0, arBytes.Length, ".dxf");
doc.Redraw(true);
Only the SaveToDataBuffer and LoadFromDataBuffer are exported to the VDF Wrapper so these two methods can be used in VB6 and Delphi and similar ActiveX-enabled IDEs
Code Examples:
In Delphi it can be used like:
uses
.....,
VectorDraw_Professional_tlb,vdrawi5_tlb,vdrawlib5_tlb, Activex ;
......
var
Form1: TForm1;
doc : VectorDraw_Professional_tlb.vdDocument;
arrfile: Activex.PSafeArray;
procedure TForm1.Button1Click(Sender: TObject);
var
viHigh, i: integer;
begin // press 1st
vdraw1.ActiveDocument.New();
vdraw1.CommandAction.cmdCircle(vararrayof([1,1,0]),1);
vdraw1.DisplayFrames:=63;
doc:=vdraw1.ActiveDocument.WrapperObject as VectorDraw_Professional_tlb.vdDocument;
arrfile:= doc.SaveToDataBuffer('.dxf');
vdraw1.ActiveDocument.New();
vdraw1.CommandAction.Zoom('e',0,0);
SafeArrayGetUBound(arrfile,1,vihigh) ;
doc.LoadFromDataBuffer(arrfile,0,vihigh,'.dxf');
doc.redraw(true);
end;
In VB6 it can be used like:
VDraw1.ActiveDocument.New
VDraw1.CommandAction.cmdCircle array(1,1,0), 1
Dim BArray() As Byte
BArray = doc.SaveToDataBuffer("*.dxf")
VDraw1.ActiveDocument.New
VDraw1.Redraw
Dim bal As Long
Dim res As Boolean
bal = UBound(BArray)
res = doc.LoadFromDataBufferBArray , 0, bal, "*.dxf")
doc.Redraw True
