I'm very late to join, but I may drop my 2 cents too.
There are two aspects to this post. The exact answer to OP's question and the elaboration on his real needs.
Getting just a unique number as Vojo suggests would work to answer the question. But this is not how PFDs work. (1) It's the whole tag, that needs to be unique and (2) you don't want to have weird numbers completely separated from any sorting order.
The tag can be something short, like V-xxx for valves or P-xxx for pumps.
But more often you - actually the electricians and the programmers - will want to subdivide the drawing into functional groups. So you'll add a code in front the "part type" and "number" to get something like 815-V-13.
And if the equipment gets bigger (several machines = several electrical cabinets) and bigger (several lines) you can end up with:
location code / line code / machine or cabinet code / function code / part code / number.
The PESolution that Paul suggested does already answer OP's question. It has a "renumbering" function that will eliminate duplicates.
It includes also some features to change the tagging category, etc.
Unfortunately it lacks the long tagging option. This long prefix could be written as "dumb" text in a corner of the drawing to allocate all the shapes to this one group.
My advice would be:
- if you draw PFDs only occasionaly stick with PESolution.
- if you want to get serious with tagging write your own code! I can provide some support if needed.
Resources - You may want to have a look at the following norms
- EN 81346
- EN 62424
- ISA 5.1 (
https://vdocuments.net/isa-51.html)
Some additional thoughts about a custom implementation.
- When renumbering, collect first all the prefixes - every thing that's in front of the number, then do the actual renumbering for each prefix.
- Think of improving the readability for instance by sorting the shapes by columns (ranges of x coordinates) and rows (y coordinates). So knowing your number you can visually find the shape much faster.
- When preparing the prefixes, think about grouping some. eg: say you have different valve types with different drives VP (pneumatical v.), VE (electrical), VM (manual). But to avoid renumbering when you want to change a drive, you would better number over all Vx - regardless of the drive type. Or in other words, don't number of sub-groups.
- The actual tagging - assigning values to different grouping fields - is only indirectly connected to the displayed text. When the tags get too long (over 7-8 characters), you'll want to de-clutter the drawing by surrounding shapes of a same group by a frame displaying the group's text. The shapes themselves would only display the last part of the tag. Thus the setting of the text displayed needs to be easily adjustable.
- When adding new numbers, consider if you want to use the gaps the numbering or only append to current numbering.
- You may also consider a differentiation between standard parts and project specific ones. e.g.: new parts start from 100.
- When renumbering you may think about preserving already existing sorting orders. Think about changes made in project in progress. Don't modify already allocated tags, unless there is very important reason for it and you documented it properly!!!
You see the list of considerations is quite big and it's only the ones I put up in 10 minutes.