Is there a way to use system.tag.configure
or system.tag.addTag
to create a reference tag?
Yes, with system.tag.configure
, by including the valueSource
property.
I have not had any luck trying that. I also tried system.tag.addTag
but a reference tag is not listed in the documentation.
# Define the path for the new reference tag
targetFolderPath = "[default]Dev_DeLuca"
# Define the name of the new reference tag
newTagName = "ReferenceToTest"
# Define the source tag path to reference
sourceTagPath = "[default]Dev_DeLuca/Test"
# Complete the full path of the new reference tag
targetTagFullPath = "{}/{}".format(targetFolderPath, newTagName) # Using .format() instead of f-string
print targetTagFullPath
# Check if the reference tag already exists
if not system.tag.exists(targetTagFullPath):
# Configure the reference tag
tagConfig = {
"name": newTagName,
"tagType": "Reference",
"valueSource": "Reference",
"sourceTagPath": sourceTagPath
}
# Use system.tag.configure to create the new reference tag
result = system.tag.configure(targetFolderPath, [tagConfig], "o") # "o" = overwrite if it doesn't exist
print("Reference tag created:", result)
else:
print("Reference tag already exists at:", targetTagFullPath)
The tag type should be AtomicTag not Reference. I also believe you can just not include it as the valueSource property is enough to identify it as a reference tag.
If you're ever in doubt, you can create a reference tag using the UI, and then use system.tag.getConfiguration()
it will show you these kinds of things.
Thank you for the feedback, I got the below to work. I had to add some additional properties.
system.tag.getConfiguration("[default]Dev_DeLuca/Test 1")
# Define the path for the new reference tag
targetFolderPath = "[default]Dev_DeLuca"
# Define the name of the new reference tag
newTagName = "ReferenceToTest"
# Define the source tag path to reference
sourceTagPath = "[.]Test"
# Complete the full path of the new reference tag
targetTagFullPath = "{}/{}".format(targetFolderPath, newTagName) # Using .format() instead of f-string
# Check if the reference tag already exists
if not system.tag.exists(targetTagFullPath):
# Configure the reference tag
tagConfig = {
"name": newTagName,
"tagType": "AtomicTag",
"dataType": "String",
"valueSource": "reference",
"sourceTagPath": sourceTagPath
}
# Use system.tag.configure to create the new reference tag
result = system.tag.configure(targetFolderPath, [tagConfig], "o") # "o" = overwrite if it doesn't exist
print("Reference tag created:", result)
else:
print("Reference tag already exists at:", targetTagFullPath)
print sourceTagPath
1 Like