Hi..
I have wrote a dll for revit 2013 that work correctly. Now I have to migrate to 2014 but I have any problem.
Dll load in to a form soe sheet parameters as title, scale etc.. and I can change value on form.
Yhe OK button update parameters with new value.
On 2013 I used this code, but non working on 2014, I receive an exception on trans.start...any idea?
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim strTitolo1 As String Dim strTitolo2 As String Dim strTitolo3 As String Dim strCod As String Dim strProg As String Dim strScala As String Dim strD1 As String Dim strD2 As String Dim strD3 As String Dim strD4 As String Dim strD5 As String Dim strD6 As String Dim strD7 As String Dim strD8 As String Dim strD9 As String Dim strD10 As String Dim strD11 As String Dim strD12 As String Dim strD13 As String Dim strD14 As String Dim strD15 As String Dim strD16 As String Dim strD17 As String Dim strD18 As String Dim strD19 As String Dim strD20 As String Dim strD21 As String Dim strRev As String
Dim strData_1 As String Dim strRed_1 As String Dim strVer_1 As String Dim strApp_1 As String Dim strRev_2 As String
Dim strData_2 As String Dim strRed_2 As String Dim strVer_2 As String Dim strApp_2 As String
Dim strData_3 As String Dim strRed_3 As String Dim strVer_3 As String Dim strApp_3 As String Dim strMot_3 As String Dim strMot_2 As String Dim strRev_3 As String 'Dim myEnt As DatabaseServices.ObjectId
strTitolo1 = UCase(TITOLO1.Text) strTitolo2 = UCase(TITOLO2.Text) strTitolo3 = UCase(TITOLO3.Text) strCod = UCase(Cod_Rif.Text) strProg = UCase(TIPO_PROG.Text)
strScala = UCase(SCALA.Text) strD1 = UCase(D1.Text) strD2 = UCase(D2.Text) strD3 = UCase(D3.Text) strD4 = UCase(D4.Text) strD5 = UCase(D5.Text) strD6 = UCase(D6.Text) strD7 = UCase(D7.Text) strD8 = UCase(D8.Text) strD9 = UCase(D9.Text) strD10 = UCase(D10.Text) strD11 = UCase(D11.Text) strD12 = UCase(D12.Text) strD13 = UCase(D13.Text) strD14 = UCase(D14.Text) strD15 = UCase(D15.Text) strD16 = UCase(D16.Text) strD17 = UCase(D17.Text) strD18 = UCase(D18.Text) strD19 = UCase(D19.Text) strD20 = UCase(D20.Text) strD21 = UCase(D21.Text)
strRev = UCase(REV.Text)
'DATA_1 = UCase(DATA_1.text) 'strData_1 = Format(UCase(CALEND_1.Text), "dd/MM/yyyy") strData_1 = CALEND_1.Text strRed_1 = UCase(RED_1.Text) strVer_1 = UCase(VER_1.Text) strApp_1 = UCase(APP_1.Text)
'DATA_2 = UCase(DATA_2.text) 'strData_2 = Format(UCase(CALEND_2.Text), "dd/MM/yyyy") If REV_2.Text <> Nothing Then strData_2 = CALEND_2.Text Else strData_2 = "" strRed_2 = UCase(RED_2.Text) strVer_2 = UCase(VER_2.Text) strApp_2 = UCase(APP_2.Text) strMot_2 = UCase(MOT_2.Text) strRev_2 = UCase(REV_2.Text)
'DATA_3 = UCase(DATA_3.text) 'strData_3 = Format(UCase(CALEND_3.Text), "dd/MM/yyyy") If REV_3.Text <> Nothing Then strData_3 = CALEND_3.Text Else strData_3 = "" strRed_3 = UCase(RED_3.Text) strVer_3 = UCase(VER_3.Text) strApp_3 = UCase(APP_3.Text) strMot_3 = UCase(MOT_3.Text) strRev_3 = UCase(REV_3.Text)
Dim tran As Autodesk.Revit.DB.Transaction = New Autodesk.Revit.DB.Transaction(command_data.Application.ActiveUIDocument.Document, "set param") tran.Start()
csheet.Parameter("Data").Set(strData_1) csheet.Parameter("DRW1").Set(strRed_1) csheet.Parameter("CHK1").Set(strVer_1) csheet.Parameter("APR1").Set(strApp_1)
csheet.Parameter("Data2").Set(strData_2) csheet.Parameter("DRW2").Set(strRed_2) csheet.Parameter("CHK2").Set(strVer_2) csheet.Parameter("APR2").Set(strApp_2) csheet.Parameter("MOT2").Set(strMot_2) csheet.Parameter("REV1").Set(strRev_2)
csheet.Parameter("Data3").Set(strData_3) csheet.Parameter("DRW3").Set(strRed_3) csheet.Parameter("CHK3").Set(strVer_3) csheet.Parameter("APR3").Set(strApp_3) csheet.Parameter("MOT3").Set(strMot_3) csheet.Parameter("REV2").Set(strRev_3)
csheet.Parameter("REV").Set(strRev)
csheet.Parameter("Tipo di Progetto").Set(strProg)
csheet.Parameter("Disciplina").Set(strTitolo1) csheet.Parameter("Zona di Intervento").Set(strTitolo2) csheet.Parameter(BuiltInParameter.SHEET_NAME).Set(strTitolo3)
Dim Namep As String
For Each Control In Me.Controls Debug.Print(Control.name) For I = 1 To num_digit Namep = "D" + Trim(Str(I)) If Control.Name = Namep Then
Dim STR_P As String = "D" & Trim(Str(I))
csheet.Parameter(STR_P).Set(Control.text)
End If Next I Next Control
Dim STR_NUM_TAV As String = ""
For Each Control In Me.Controls Debug.Print(Control.name) For I = 12 To num_digit Namep = "D" + Trim(Str(I)) If Control.Name = Namep Then
STR_NUM_TAV = STR_NUM_TAV & Control.text
End If Next I Next Control
Dim chk_Tav As Integer = 0
For z = 0 To List_SheetNum.Count - 1
If List_SheetNum(z) = STR_NUM_TAV And List_SheetID(z) <> csheet.Id.ToString Then
MsgBox("Esiste già una tavola numero: " & STR_NUM_TAV & " la nuova verrà rinominata in " & STR_NUM_TAV & "_2")
csheet.Parameter(BuiltInParameter.SHEET_NUMBER).Set(STR_NUM_TAV & "_2") chk_Tav = 1
End If
Next
If chk_Tav = 0 Then csheet.Parameter(BuiltInParameter.SHEET_NUMBER).Set(STR_NUM_TAV)
' tb.Parameter(BuiltInParameter.SHEET_NAME).Set(strTitolo1) tran.Commit()
'aWall.Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).Set("Modified by API")
' _doc.Regenerate()
Me.Close()
End Sub
Solved! Go to Solution.
Solved by arnostlobel. Go to Solution.
Hi,
Which exception are you receiving? There are no major changes on the Transaction mechanism...so it may be related to the structure/scenario.
Hello Scarta,
I have an idea. Just a hunch, really, but from how you describe your addin I think it could be the deal. It looks to me like you might be accessing the API from a modeless dialog that stayed open after your code finished an external command (or existed OnStartup). When you do that, if you try to start a transaction at practically any moment your user clicks something in the dialog, Revit 2014 will throw an exception. The fact is that it has never been supported for external threads or modeless dialogs to access Revit API (because it is dangerous and leads to crashes and document corruption), but only starting with version 2014 Revit throws an exception. (By the way, I believe the exception has rather self-explanatory message associated with it.)
Luckily, there is a solution for what you seem to need and the solution has been in Revit all along for at least 3 releases now. You can utilize either the Idling event or External Events. The latter in particular had been designed for API access from modeless dialogs. There are samples in the SDK. Look for “ModelessDialog”.
Thank you
Arnošt Löbel
Autodesk Revit R&D