Guest User

Untitled

a guest
Feb 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. /**
  2. *
  3. * @param {MSDocument} doc - Reference to the open document
  4. * @description Finds and returns all pages in the document
  5. * @returns {Array} A flatten array with all the pages
  6. */
  7. const getAllPages = (doc) => {
  8. return doc.pages();
  9. }
  10.  
  11. /**
  12. *
  13. * @param {MSLayer} layer - Parent layer to search
  14. * @param {Bool} [includeContainers= true] includeContainers - If it should include groups/containers or only objects
  15. * @description Finds and returns all objects in a layer
  16. * @returns {Array} A flatten array with all the layers
  17. */
  18. const getAllLayersIn = (layer, includeContainers = true) => {
  19. let layers = [];
  20. switch(layer.class()) {
  21. case MSDocument:
  22. const pages = getAllPages(layer);
  23. pages.forEach(page => {
  24. layers = layers.concat(getAllLayersIn(page, includeContainers));
  25. });
  26. break;
  27. default:
  28. if (layer.layers) {
  29. layer.layers().forEach(sublayer => {
  30. layers = layers.concat(getAllLayersIn(sublayer, includeContainers));
  31. });
  32. if (includeContainers) {
  33. layers.push(layer);
  34. }
  35. } else {
  36. layers.push(layer);
  37. }
  38. break;
  39. }
  40. return layers;
  41. }
  42.  
  43. /**
  44. *
  45. * @param {MSLayer} layer - Parent layer to search
  46. * @description Checks if the object is visible by searching upwards to the closest parent with a visibility property
  47. * @returns {Bool} True if the object is not visible
  48. */
  49. const isHidden = (layer) => {
  50. if (layer.layers) {
  51. return layer.isVisible();
  52. } else {
  53. return isHidden(layer.parentGroup());
  54. }
  55. }
Add Comment
Please, Sign In to add comment