Table of Contents

Method MergeDocument

Namespace
vdWebLibrary
Assembly
JsPropertiesExtractor.dll

MergeDocument(string, MergeDocumentFinshedDelegate, int, string)

Merge the model entities of the passed document to this selected document The function is running asynchronously, so you need to wait for the passed finishCallback event/delegate to be fired before you can get/manage the method results

public void MergeDocument(string filename, MergeDocumentFinshedDelegate finishCallback, int mergeFlags, string blobstr)

Parameters

filename string

Required. A filename url

finishCallback MergeDocumentFinshedDelegate

Optional. If present and not is null represents a user function callback to be fired when merge finished

mergeFlags int

Optional. If present must be one of MERGEFLAGS_DEFAULT , MERGEFLAGS_REPLACE_EXISITING , MERGEFLAGS_KEEP_EXISITING , MERGEFLAGS_KEEP_BOTH, MERGEFLAGS_USEDESTEXISTINGTABLES.

Represents FLags that control how the merge is done.

If not present MERGEFLAGS_DEFAULT is used.

blobstr string

Optional.If present and not is null represents the contents of filename that used to be loaded instead of downlonding the paseed filename.

Examples

User add a new layer and a new line and we will merge them later on a basic drawing.

You can open the drawing 'basic.vds' (The layer 'user' is empty)

Add some entities to layer 'user'

Partial save only the entities from layer 'user' (using entity.excludeFromSave = true; to all other entities) as 'user.vds'

Then

Open the drawing 'basic.vds' (The layer 'user' is empty)

Call the vdcanvas.MergeDocument('user.vds',mergedocumentfinished, vdConst.MERGEFLAGS_DEFAULT, partialSavedFileData);

The entities of Model of the 'user.vds' will be added to existing document Model entities.

This method will only work for entities that come from a Document A and are going to be loaded to Document A again.

It will not work for entities from a Different drawing.

Suppose that in the HTML page we have five buttons.

Button 1.OpenBasic -> Load a basic.vds file which contains a circle,an ellipse,a text,a rectangle and a spline.

Button 2.Line -> Creates a new layer and a new line.

Button 3.Save -> Save the new layer and line in a virtual user.vds which is actually not exists

Button 4.reOpenBasic -> Reopens the basic.vds without the new layer and new line.

Button 5.Merge -> Merge the basic.vds with the user.vds where we previous added some new entities.

var vdcanvas;        
function _onprompt(sender, msg) {
   printInfo('info', msg);
}
this.printInfo = function (infoId, text) {

   if (text === undefined || text === null) return;
   var info = document.getElementById(infoId);
   if (info == undefined) return;
   info.innerHTML = ":" + text;
}       
function printInfo(text) { 
   document.getElementById("info").innerHTML = ":" + text;
}       

var partialSavedFileData;
function vdrawInitPageLoad() {

   vdcanvas = vdmanager.AttachCanvas("canvas");	
   vdcanvas.vdAfterOpenDocument = _vdAfterOpenDocument; //defines the function that will be fire when a web control document loaded.
   vdcanvas.vdAfterSaveDocument = _vdAfterSaveDocument; //defines the function that will be fire when a web control document data saved completed.

}

function OpenBasic() { // Here we open the main document
   setTimeout(vdcanvas.SelectDocument("basic.vds"));
   vdcanvas.vdPrompt = _onprompt;
}
function _vdAfterOpenDocument() {}//fire when basic.vds document loaded.

 function line() { // We add a new layer and a new line 
   vdcanvas.SetActiveLayer( vdcanvas.AddLayer('user'));
   vdcanvas.scriptCommand.line();
}

function save() { //We save the layer and the line that we previous added
    vdcanvas.SaveDocument();
}
function _vdAfterSaveDocument(saveData) {
 // Developer can also save the datastream in a server url
    partialSavedFileData = saveData.dataStream;
}

function reOpenBasic(){ //We reopen the basic drawing
   vdcanvas.SelectDocument("basic.vds");
}

function merge(){ //We merge the user.vds with the basic.vds
  // Merge the documents
   vdcanvas.vdAfterOpenDocument = _vdAfterOpenDocumentForMerge;
   vdcanvas.SelectDocument("basic.vds");
}
function _vdAfterOpenDocumentForMerge() {

   vdcanvas.MergeDocument('user.vds',mergedocumentfinished, vdConst.MERGEFLAGS_DEFAULT, partialSavedFileData);
   vdcanvas.vdAfterOpenDocument =_vdAfterOpenDocument;
}
function mergedocumentfinished(mergeargs){
  //you can get the following properties from passed mergeargs
  var canvasreference = mergeargs.vdcanvas;
  var mergeFlags = mergeargs.mergeFlags;
  var mergedocument = mergeargs.mergedoc;
  //for example get the number of model entities of merged document
  var nents = mergedocument.Model.Entities.Items.length;
}

Remarks

if the mergeFlags is defined with MERGEFLAGS_KEEP_BOTH all the passed model drawing entities are added to the vdcanvas active document model entities with all their table dependecies(Layers Blocks TextStyles LineTypes etc)

In that case the adding of passed tables is depend on if mergeFlags contains the MERGEFLAGS_USEDESTEXISTINGTABLES or not.

if the mergeFlags is not defined with MERGEFLAGS_KEEP_BOTH , the passed document must have been saved using the parsial save using excludeFromSave add the currently selected document must be the same as the document when partial save of passed document done.

This is useful to use a main drawing as background. Let the user add some 'annotation' entities on specific layer, then partial save only entities of that layer.

Later you can open the background drawing and use the MergeDocument with previous partial saved document to show the user annotation entities over the background drawing.