Using the .NET API to Create an Alignment, if you pass it arguments that result in the Alignment being unable to be created and an Exception is thrown, an Alignment is still created but without a name. This results in being greeted with the "Cannot save with objects in this state" (paraphrased) warning message. An Audit fixes that and then you can see these unnamed alignments in Prospector so they can be deleted. However, this is really undesireable behavior. Instead, the API shouldn't create that Alignment in the first place.
To test this, create 2 empty alignments using the same values
Alignment.Create(document, alignmentName,siteName,layerName,styleName,labelSetName) Alignment.Create(document, alignmentName,siteName,layerName,styleName,labelSetName)
The second one will throw an exception "Duplicate name". Try to save the drawing, you can't. Audit and watch as the Prospector has an unnamed alignment added to the site.
I've now modified my code so it checks for a duplicate name first and adjusts the name just like C3D does (adds a "(1)" to the name). I was doing this previously but was relying on the Create method throwing the Duplicate name exception to do so in a Try/Catch block.
Hi Jeff,
This is documented in the Civil 3D API Ref. doc
Exception : System.ArgumentException Thrown when:
Please check this link -
Yes, we need to check if the Alignment name already exists, before we try to add a new one. This seems to be as designed behavior.
Thanks,
Partha
Thanks, Partha, but...
Isn't the purpose of providing an Exception is to keep 'bad things' from occurring? As I mentioned, I was catching that Exception, but the Alignment gets created anyway without a name. To me, that should NOT be the designed behavior. When an Exception is hit then no Alignment should be created and the Exception thrown. Using the same Create method, if an invalid ObjectId is passed for the Alignment Style, an exception is thrown, as expected, but no alignment is created and the drawing stability is not affected. This is how it should behave when it gets a name passed that it cannot use (such as a duplicate name).
Jeff, thanks for the feedback. I will log a change request to investigate this further and possibly stop creating the alignment.
Thanks,
Partha
Hi Jeff,
FYI - I have logged this in our internal system with a change request to stop the Alignment creation using API if the duplicate name exists.
Thanks,