Starting transaction from external application - VB.net

Starting transaction from external application - VB.net

JCMaia
Explorer Explorer
354 Views
3 Replies
Message 1 of 4

Starting transaction from external application - VB.net

JCMaia
Explorer
Explorer

I know this is an old question, I browsed through the solution but I am still having a lot of trouble trying to commit changes to a global parameter from an external application. 

 Can someone help me figure it out what code should i place in this module,  to be able to make this transaction ?

 

below is my code.. I simplified it to make it more easy to focus on a solution 🙂 

 

Module Module1
    
Public Sub Set_global_param()

        Dim GPlist As ISet(Of ElementId) = GlobalParametersManager.GetAllGlobalParameters(Revit_doc)

        For Each item As ElementId In GPlist

            Dim gpParam As GlobalParameter = TryCast(Revit_doc.GetElement(item), GlobalParameter)
            Dim gpName As String = gpParam.Name

            If gpName = "Param1" Then

                gpParam.SetValue(New DoubleParameterValue(111))

            End If
        Next
    End Sub
End Module

 

 

0 Likes
Accepted solutions (3)
355 Views
3 Replies
Replies (3)
Message 2 of 4

jeremy_tammik
Alumni
Alumni
Accepted solution

You need to use an external event to obtain access to a valid Revit API context within the external event handler when driving Revit from a modeless context:

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 4

JCMaia
Explorer
Explorer
Accepted solution

@jeremy_tammik  thank you very much for your reply.

 

I tried to implement  the solution, but in the end wasn't able to make it work. I recognize that this is probably due to my inexperience in the Revit API and programming. 

 

I tried to implement the classe's ExternalEventExample, ExternalEventExampleApp and ExternalEventExampleDialog, after translate them from c# to vb .. but i was not successful

 

I attached my project to this reply and a Revit model, if you could take a look I would be extremely grateful.     

I simplified the solution to the bare basic so its easier to analyse.  I am using VS 2022 and Revit 2023

 

For context, the main use of the app will be to read parameters from several excel files and our ERP system (This part is working) , and use them to updated a Revit model.  

 

0 Likes
Message 4 of 4

JCMaia
Explorer
Explorer
Accepted solution

I have figure it out a solution to my problem, check the attached file.

hope it helps someone 😊.

0 Likes