• 1 reply
  • Latest Post - ‏2019-07-15T17:34:57Z by Mike.Scharnow
Christopher Cote
Christopher Cote
67 Posts

Pinned topic How to perform same code on either Project or Folder

‏2019-07-15T15:55:52Z |

I originally wrote a function to perform on a project, but now the user wants to have the option to perform this function on either a project or a folder.  I have about 200 lines of code that I want to perform in a loop on either the entire parent project or the individual parent folder.  Is there an easy way to create a for loop that can use either type?  I've tried to set a folder variable to the current Project, thinking that a project is simply a special type of folder.  However, I get an error if I try to do this (incorrect arguments for (=) ).  Do I need to put the 200 lines of code into a separate function just so I don't have to repeat the same code for current Project and current folder?



Updated on 2019-07-15T15:59:18Z at 2019-07-15T15:59:18Z by Christopher Cote
  • Mike.Scharnow
    585 Posts

    Re: How to perform same code on either Project or Folder


    On the one hand you can ask for the type of an item

    if (type (i) == "Project" / "Folder") {...

    , on the other hand you can get the corresponding folder of a project with the perm

    Folder folder(string folderName)

    So you can convert your code to work with folders only and call your function e.g. with the parameter

    doSomething (string fName) {
        Folder f = folder (fName)
    Project myP = ...
    Folder myF = ...
    doSomething(fullName myP)
    doSomething(fullName myF)