How to duplicate a project with hierarchical sheets getting new file names?

What is the recommended workflow to create a new project based on a snapshot of an existing project (that has hierarchical sheets)? Conceptually, copying all the existing project’s files and then renaming them to suit the name of the new project?

What I didn’t find:

… so tell me if I missed it!

  • “Rename project” command
  • “Rename subsidiary sheet” command

What I’ve tried:

Alternative 1. Save As. This creates a duplicate project, where only the project file and top-level schematic are renamed. The subsidiary schematic files retain their original names. That’s maybe unsurprising, but how to rename those subsidiary files? (In topic “How to duplicate a project?”, the advice to Save As didn’t touch on the subsidiary sheet file names.)

Alternative 2. Copy and rename “manually”: Copying the existing project (say using Windows Explorer, or the Save As function). Then rename the files individually (again using Windows Explorer). This breaks the file links in the top-level sch sheet’s hierarachical sheet components, so next, edit these to “relink” them to the newly-renamed subsidiary sheet files.

This used to work in Kicad 5. However, in Kicad 6, this sequence of operations causes the components on the subsidiary sheets to forget their Value and Footprint data. That in turn is because, in K6, that field data is stored in the top-level sheet, and cross-referenced to the component id in the subsidiary sheet. Following the rename and relink the subsheet component data is still present in the top-level sheet file, just the “GUID path” that links it to the subsheet components is broken.

Alternative 3. Copy and paste contents: Create a brand new project, along with top sheet and (empty) subsidiary sheet files, of course named according to the new project’s needs. Then visit each page in the original project and copy-paste its contents to the corresponding page in the new project. (Possible in K6, not in K5). Normal paste will cause all component id numbers to change to X?. However there’s a Paste Special function that retains component id numbers.

So, this method succeeds, but is painfully tedious and error prone for any but small projects.

Did I miss a better way to do this?

AFAIK that’s missing

In a schematic, select the sheet you want to rename, press ‘E’ and change the ‘Sheet File’ filename.

This is meant also for duplicating a project. This has been discussed before, some users would like to rename the hierarchical sheet files. However, the KiCad’s functionality should work safely for all situations, and blindly renaming the hierarchical files would clash with that requirement. KiCad can share hierarchical files between projects and its possible to use a sheet file of another project.

The obvious solution is to not use the name of the project in the hierarchical files. This suggestion raised some heat at least once, but I haven’t changed my mind: you just don’t need to repeat the project’s name in the hierarchical sheets. You know they belong to the project anyway. And if they are located outside the project directory, there’s even less reason to have the project name there.

1 Like

Thanks for your reply, but…

That action doesn’t rename the subsidiary sheet file. Instead, it changes the subsidiary sheet component (symbol) so that it points to a different file. I pointed out the problem with using that approach in Alternative 2.

I was not precise enough: selecting a file by browser in Sheet File links another file. EDITING the filename creates a new file with this filename and the content of the previous file.
At least KiCad did that 2 minutes ago on version 6.99.


Edit: I decided to delete what was an extended answer to eelik, since it’s largely a red herring to any other readers, given the solution pointed to by @straubm. Sorry to eelik for the impatient tone. Apparently we have a solution, so no point discussing whether the solution is unnecessary.]

That said, I will leave in place the note that the semantics of using sub sheets in multiple projects may not work quite right:

I don’t know how the semantics of this are intended to work, but they don’t seem to work properly. This could better be a separate topic, but: If I create project A with a single sub sheet A1, then in a second project B I use subsheet A1, then open and edit it, odd things happen when I edit the field values on the components (and save). The field values get changed in the subsheet file, and appear changed while open in project B. However, returning to project A, the field values remained as they were before ( presumably because overridden by the values stored in the top sheet), except for new fields I had added (to the original sheet opened as A-A1) where the value edited when opened as B-A1 now appear when opened as A-A1.

Hahaha, well hot-diggity, that actually seems to work (in 6.0.7).

Thanks mightily for that note!

OK, so the workflow for duplicating a project with hierarchical sheets getting new names is… (drumroll)

  1. Use Save As to duplicate the project while applying a new name to the project (and its project files and top level sheet file sch).

  2. Open the new project, and in the top level sheet file, open the properties of each Sheet component and edit the Sheet file name. If necessary, edit the Sheet name field at the same time, if that has any project-specific text in it.

1 Like

Actually the project file name (ending with .kicad_pro) is which gives the name to the project, and the containing folder can be named anything. But the main schematic file and the PCB file must have the same base name than the project file. That’s how KiCad works as of now, good or bad.

I don’t really understand your reasoning about 100’s of files all named PSU etc. It wouldn’t add anything useful to have 100 files named “my_project1_PSU” instead. If the files are in the same folder or a subfolder of the project folder – i.e. in the folder where the project file is – you know they belong to that same project.

You can’t place confidence in that, but the user decides whether or not they create project structures which are error prone. For normal cases it’s easy: you just create a project by normal means, create subsheets etc. That way the structure is safe. If you try to do tricks with file names etc., whatever the tricks would be, it’s not necessarily safe anymore.

I’m not saying KiCad couldn’t have better means for keeping project structures and versions etc., but I don’t see why you rant about the suggestion which said you don’t need to have the project name in the subsheet file names.

I appreciate you again taking the time to answer. I suspect I’m not going to convince you that even if you find no merit in hierarchical naming of sheets and subsheets, others do, which precipitates a desire to be able to rename subsheet files when a project is duplicated. Is there redundancy in that naming? Sure… until you need it.

The rationale does indeed hinge on the degree to which you can be certain that files belonging to a project stay in that project directory, never find themselves somewhere else or dealt with individually, and never does a file from a different project get into the directory and overwrite one that was there, and never does a file get messed up by a power glitch (or software crash) and need to be recovered from backup. Dealing with hundreds of legacy projects from a timespan of ten years or more, with personnel of different levels of vigilance, through server crashes and backup accidents, all I can say is, stuff happens.

And this is only one rationale for wanting to rename subsheet files.

But fortunately, the discussion is moot, because as @straubm has contributed, there is indeed a pretty convenient way to rename subsheet files.

Related discussion and workaround:

@ferdymercury I appreciate you jumping in and linking to that previous discussion. However, a pretty good solution was already presented in this thread by @straubm, and summarized by me, which relies only on Kicad steps, and no workarounds.

While your method is quite educational about what detailed file-fiddling might be needed to achieve the result outside of Kicad (and given file system tools and editing tools such as those you list), I think we should not lure future readers in that direction when a Kicad 6 procedure exists for accomplishing the goal.

The method I pointed could be a workaround if by chance your 10 subsheets contain the old project name and you fo not want to press E one by one on them in the GUI to rename them. Of course, if there were a batch rename plugin in Kicad for that, it would be much better than hacky external tools.