Select to view content in your preferred language

Export Assetpackage with UNtools - Problem with duplicate class names (StructureJunction_1)

837
0
07-15-2021 02:03 AM
Labels (1)
Maulingo
Emerging Contributor

Hi all. I'm trying to use the "Export Assetpackage" function with UNtools (2.6.2) but I'm running into a rather annoying error, and I'm hoping someone might be able to help me correct it. 

Due to me testing out some other functions regarding dataloading workbooks I have created more than one Utility network in the same local geodatabase. This has resulted in me having class names ending with "_1" in the second Utility network I created. This goes for all the different names in that utility network model. Example of name problemExample of name problem

When I try to export this UN to an assetpackage, I get the following error:

"line 623, in parse_un_class
raise ValueError("'{}' did not satisfy regex".format(name))
ValueError: 'StructureBoundary_1' did not satisfy regex"

 

If I take a look at line 623 in the "common.py" file the error refers to it to be part of the following function:

@lru_cache()
def parse_un_class(class_name: str, structure_as_none: bool = False) -> Tuple:
"""Parses class_name to extract the domain name and class type

Args:
class_name (str): The path to the UN class.
structure_as_none (bool): Return Structure Network as ``None``; defaults to ``False``.

Returns:
tuple: (Domain name, class type)

Examples:
>>> parse_un_class("Naper.un.ElectricLine")
("Electric", "Line")
>>> parse_un_class("C:/con.sde/Naper.un.Electric/Naper.un.StructureBoundary")
("Structure", "StructureBoundary")
>>> parse_un_class("C:/con.sde/Naper.un.Electric/Naper.un.StructureBoundary", structure_as_none=True)
(None, "StructureBoundary")

Raises:
ValueError: If ``class_name`` is not a valid UN class.
"""
if class_name is None:
return None, None

# TODO: rewrite this to handle duplicate class names (eg StructureJunction_2)
name = os.path.split(class_name)[-1].rpartition('.')[-1]
# Using lazy quantifier so Subnet is included with Line and not the domain name
res = re.findall('(.+?)(Assembly|Device|Junction|Line|SubnetLine|Boundary|EdgeObject|JunctionObject)$',
name, re.IGNORECASE)
if not res:
raise ValueError("'{}' did not satisfy regex".format(name))
else:
domain, class_type = res[0]
# Structure domain class types are 'Structure(Junction|Line|Boundary)'
if domain.upper() == 'STRUCTURE':
class_type = "Structure" + class_type
if structure_as_none:
domain = None

return domain, class_type

Now I can see the creator has put in a "TODO" for him/her/it self to rewrite the function so it can support duplicate class names.

Does anyone have any ideas about how I would go about editing part of the "parse_un_class(class_name: str, structure_as_none: bool = Fals) -> Tuple:" function so it would accept my "_1" UN elements?

 

I tried to edit:

 res = re.findall('(.+?)(Assembly|Device|Junction|Line|SubnetLine|Boundary|EdgeObject|JunctionObject)$',
name, re.IGNORECASE) 

to have "_1" at the end like so:

res = re.findall('(.+?)(Assembly_1|Device_1|Junction_1|Line|SubnetLine_1|Boundary_1|EdgeObject_1|JunctionObject_1)$',
name, re.IGNORECASE)

But it throws the same error as before. I don't want to edit too much around in places I have no business editing, but I spend WAY too much time setting up the model to just throw it away and do it again.

Any tips, thoughts or ideas are most welcome!

PS. I can't upgrade to a higher untools version, since I'm forced to stick to the version of our enterprise server where the UNM will eventually end up.

0 Kudos
0 Replies