| Article | 70001079 |
| Type | Wish |
| Product | WebJS |
| Date Added | 5/10/2017 12:00:00 AM |
| Fixed | 7.7011.0.5 (5/16/2017 12:00:00 AM) |
| Submitted by | Brendan Fry |
Summary
I would like to have the ability to merge several documents into one
Solution
In version 70011.0.5 MergeDocument() method has been added.
Using vdcanvas.MergeDocument you will be able to merge several documents which are made by the same main 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);
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.
}
// Here we open the main document
function OpenBasic() {
setTimeout(vdcanvas.SelectDocument("basic.vds"));
vdcanvas.vdPrompt = _onprompt;
}
function _vdAfterOpenDocument() {}//fire when basic.vds document loaded.
// We add a new layer and a new line
function 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;
}
