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: 

Ambient Settings Update

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
RodWing
601 Views, 7 Replies

Ambient Settings Update

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

7 REPLIES 7
Message 2 of 8
Jeff_M
in reply to: RodWing

Precision values are not Doubles, but Integers. Although I would think it would just throw an exception, not exit C3D.

I used your code, edited the Double to Integer and it worked fine. May need to check for the case where the value is at the max.
Jeff_M, also a frequent Swamper
EESignature
Message 3 of 8
RodWing
in reply to: Jeff_M

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.

Message 4 of 8
Jeff_M
in reply to: RodWing

Yep, I ran it a number of times, all the way until it throws an exception (caught by the Try/Catch) when trying to set the precision to 9.
Jeff_M, also a frequent Swamper
EESignature
Message 5 of 8
Jeff_M
in reply to: Jeff_M

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

 

 

Jeff_M, also a frequent Swamper
EESignature
Message 6 of 8
RodWing
in reply to: Jeff_M

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.

Message 7 of 8
Jeff_M
in reply to: RodWing


@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.

Jeff_M, also a frequent Swamper
EESignature
Message 8 of 8
RodWing
in reply to: Jeff_M

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

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

Post to forums  

Rail Community


Autodesk Design & Make Report