Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Something to be aware of....

4 REPLIES 4
Reply
Message 1 of 5
Jeff_M
365 Views, 4 Replies

Something to be aware of....

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.

Jeff_M, also a frequent Swamper
EESignature
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Jeff_M

Hi Jeff,

 

This is documented in the Civil 3D API Ref. doc

 

Exception  : System.ArgumentException  Thrown when:

 

  1. The the name of drawing or the objectId of the polyline, layer, style, labelSet or site are invalid.
  2. The name of the alignment already exists.

 

Please check this link -

 

http://docs.autodesk.com/CIV3D/2014/ENU/API_Reference_Guide/html/01132a5f-8329-50b8-8959-94bb5f1207b...

 

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

Message 3 of 5
Jeff_M
in reply to: Anonymous

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_M, also a frequent Swamper
EESignature
Message 4 of 5
Anonymous
in reply to: Jeff_M

Jeff, thanks for the feedback. I will log a change request to investigate this further and possibly stop creating the alignment.

 

Thanks,

Partha

Message 5 of 5
Anonymous
in reply to: Anonymous

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,

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report