I'm running into a strange problem updating the Ambient Settings in Civil 3D 2014. Running in Debug mode attempting to update an Ambient setting will kill the macro and close Civil 3D without any execption or error dialogs. If I start with a new drawing using the standard Autodesk templates it works fine. Running it a second time on the same drawing is when the problem occurrs. This also happens anytime I run it on a client drawing created from their template.
The function below isolates the problem.
Private Function UpdateAmbientSetting(ByRef civDoc As Autodesk.Civil.ApplicationServices.CivilDocument) As Boolean Dim dValue As Double UpdateAmbientSetting = False Try dValue = civDoc.Settings.DrawingSettings.AmbientSettings.Acceleration.Precision.Value + 1 ' Program and Civil 3D exits here civDoc.Settings.DrawingSettings.AmbientSettings.Acceleration.Precision.Value = dValue UpdateAmbientSetting = True Catch ex As Exception End Try End Function
Any help is appreciated.
Thanks.
Rod
Solved! Go to Solution.
Solved by RodWing. Go to Solution.
Thank you Jeff.
I thought for sure the VS intellisense displayed double as the return type, must have been looking at something else.
Did you run it a second time on the same drawing? During my testing I save the drawing and run it a second time. That's when it errors out on me. Using client supplied drawings it errors out the first time.
Did you figure this out yet, Rod? I used a very basic command test, have you tested with something simple like this?
<CommandMethod("TestAmbientSettings")> _ Public Sub TestAmbientSettings() Dim civdoc As CivilDocument = CivilApplication.ActiveDocument UpdateAmbientSetting(civdoc) End Sub Private Function UpdateAmbientSetting(ByRef civDoc As Autodesk.Civil.ApplicationServices.CivilDocument) As Boolean Dim dValue As Integer UpdateAmbientSetting = False Try dValue = civDoc.Settings.DrawingSettings.AmbientSettings.Acceleration.Precision.Value + 1 ' Program and Civil 3D exits here civDoc.Settings.DrawingSettings.AmbientSettings.Acceleration.Precision.Value = dValue UpdateAmbientSetting = True Catch ex As SystemException End Try End Function
I found that setting CommandFlags.Session in the CommandMethod causes the Exception. If I remove it the function runs fine. That bings up another issue in that I need to execute this on multiple documents. Something else I will have to deal with.
Thank you for your assistance Jeff.
@Anonymous wrote:
I found that setting CommandFlags.Session in the CommandMethod causes the Exception. If I remove it the function runs fine. That bings up another issue in that I need to execute this on multiple documents. Something else I will have to deal with.
Thank you for your assistance Jeff.
How are you working with multiple documents? I'm guessing, since you were using the Session flag, that you are opening each drawing in the editor? If so, have you tried the "new in 2013" GetCivilDocument(db) method which allows editing without it being the ActiveDocument? I just tested this and it works, even with saving in between successive runs.
<CommandMethod("TestAbbrevations")> _ Public Sub TestAbbrev() ''This assumes that there are at least 2 drawings open, with the first one opened current and editing the second ''For actual usage should get the Document or Database in a more traditional fashion Dim doc As Document = Application.DocumentManager(1) Dim civdoc As CivilDocument = CivilDocument.GetCivilDocument(doc.Database) UpdateAbbreviationSettings(civdoc) End Sub
Note that since the GetCivilDocument() requires an Autocad Database, the drawing need not be opened in the Autocad Editor, just open the database alone.
Thanks for that information. I have encountered another problem in that my main application displays a Windows Form to collect user inputs prior to updating the settings. There is something about the display of the form that causes the same errors in the Setting Update.
As a work around here is what I am doing...
1. I have a main CommandMethod that sets CommandFlags.Session. This one displays the form, collects the user inputs and manages the opening and closing of the different drawings. The user inputs are saved to the registry.
<CommandMethod("ShowForm", CommandFlags.Session)> _ Public Sub ShowForm() myForm.Show() End Sub
2. After a drawing is opened I use the SendStringToExecute method to call another command method
doc.SendStringToExecute("UpdateSettings ", True, False, False)
3. In the same code project I have a second CommandMethod just to do the update. This one does not set CommandFlags.Session. It reads the user inputs from the registry and performs the settings update.
<CommandMethod("UpdateSettings")> _ Public Sub UpdateSettings() UpdateAbbreviationSettings(civdoc) End Sub
It's not the most elegant solution, but it appears to be working
Rod