get global parameter when closing project

get global parameter when closing project

ccalvo12
Enthusiast Enthusiast
529 Views
1 Reply
Message 1 of 2

get global parameter when closing project

ccalvo12
Enthusiast
Enthusiast

Hi, I'm trying to get a global parameter when closing the project (in the DocumentClosingEventArgs event). At the time of opening the project the function (in the DocumentOpenedEventArgs event) works fine, but when the project is closed the function does not yield anything.

 

    Public Function GetGlobalParametersValues(ByVal document As Document, ByVal parametro As String) As String
        Dim nChangedValues As String = ""

        Using trans As Transaction = New Transaction(document, "Change global parameters values")
            trans.Start()

            Dim paramId As ElementId = GlobalParametersManager.FindByName(document, parametro)
            Dim param As GlobalParameter = TryCast(document.GetElement(paramId), GlobalParameter)

            Dim valParam As ParameterValue = param.GetValue()
            Dim dvalue As StringParameterValue = TryCast(valParam, StringParameterValue)
            nChangedValues = dvalue.Value

            trans.Commit()
        End Using

        Return nChangedValues
    End Function

Will the "DOCUMENT" of DocumentOpenedEventArgs be different from the "DOCUMENT" of DocumentClosingEventArgs?

 

0 Likes
Accepted solutions (1)
530 Views
1 Reply
Reply (1)
Message 2 of 2

ccalvo12
Enthusiast
Enthusiast
Accepted solution

Hello, by testing I could see what it was when you started the transaction, in the end the solution is not to start the transaction in the "DocumentClosingEventArgs" event. Although I can continue working with this change, not starting the transaction in this event could cause me errors?

 

 

 

    Public Function GetGlobalParametersValues(ByVal document As Document, ByVal parametro As String) As S
tring
        Dim nChangedValues As String = ""


        Dim paramId As ElementId = GlobalParametersManager.FindByName(document, parametro)
            Dim param As GlobalParameter = TryCast(document.GetElement(paramId), GlobalParameter)

            Dim valParam As ParameterValue = param.GetValue()
            Dim dvalue As StringParameterValue = TryCast(valParam, StringParameterValue)
            nChangedValues = dvalue.Value


            Return nChangedValues
    End Function
0 Likes