Skip to content

Commit

Permalink
一些细节修改
Browse files Browse the repository at this point in the history
  • Loading branch information
xk6338062 committed Apr 14, 2023
1 parent c547cb4 commit 777c804
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
6 changes: 3 additions & 3 deletions ChatRevit/AppLoad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ public class AppLoad : ApplicationBase
{
public override void RegisterTypes()
{
Services.AddScoped<IDockablePaneService, ChatRevitService>();
Services.AddSingleton<IDockablePaneService, ChatRevitService>();
Services.AddSingleton<IApplicationUI, AppUIManager>();
Services.AddScoped(typeof(ChatRevitPanel));
Services.AddScoped(typeof(ChatRevitViewModel));
Services.AddSingleton(typeof(ChatRevitPanel));
Services.AddSingleton(typeof(ChatRevitViewModel));
Ioc.Default.ConfigureServices(
Services
.BuildServiceProvider());
Expand Down
3 changes: 3 additions & 0 deletions ChatRevit/AppUIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public Result Initial()
var provider = Ioc.Default.GetService<IDockablePaneService>();
var paneId = provider.GetDockablePaneId();
application.RegisterDockablePane(paneId, "ChatRevit", provider);
//var pane = application.GetDockablePane(paneId);
//if (!pane.IsShown())
// pane.Show();
return Result.Succeeded;

}
Expand Down
3 changes: 2 additions & 1 deletion ChatRevit/ChatRevitService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace ChatRevit
{
public class ChatRevitService : IDockablePaneService
{
public static string PageGuid = "3C3F2CCB-CA0B-4427-AACE-2694B685A4B2";
public static string PageGuid = "A811F969-2114-4AC8-A289-F5A8982946CE";

public ChatRevitService()
{
Expand All @@ -21,6 +21,7 @@ public ChatRevitService()
public FrameworkElement GetDockablePane()
{
var mainPage = Ioc.Default.GetService<ChatRevitPanel>();
mainPage.DataContext = Ioc.Default.GetService<ChatRevitViewModel>();
return mainPage;
}

Expand Down
11 changes: 6 additions & 5 deletions ChatRevit/ChatRevitViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Windows;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Autodesk.Revit.UI;

namespace ChatRevit
{
Expand Down Expand Up @@ -81,7 +82,7 @@ private async void Enter()
{
using var tran = new Transaction(document, "chat");
tran.Start();
execute(document, response);
execute(document, app.ActiveUIDocument, response);
tran.Commit();
}
catch (Exception e)
Expand Down Expand Up @@ -111,8 +112,8 @@ private string GetPureCode(string response)

string systemPersonality => "I want you to act as a Revit Developer. Now Write a Revit C# script of a method.\n" +
" - This method provides its functionality as a public function named 'RevitFunction'.\n " +
" - This method has only one parameter called 'document' which is passed in from the previous code " +
"and the type of parameter 'document' is Document.\n " +
" - This method has only two parameter called 'document' and 'uiDocument' which is passed in from the previous code " +
"and the type of parameter 'document' is Document, the type of parameter 'uiDocument' is UIDocument.\n " +
" - This method only contains methods available in RevitAPI.\n" +
" - This method does not need Transaction.\n" +
" - This method immediately does the task when the function is invoked.\n" +
Expand All @@ -123,7 +124,7 @@ string WrapPrompt(string input)
=>
"The task is described as follows:\n" + input;

private void execute(Document doc, string codeOutput)
private void execute(Document doc, UIDocument uiDoc, string codeOutput)
{
var codeString = "using System;\n " +
"using System.IO;\n " +
Expand Down Expand Up @@ -173,7 +174,7 @@ private void execute(Document doc, string codeOutput)
object obj = assembly.CreateInstance("Chat.ChatWithRevit");

// 执行方法
obj.GetType().GetMethod("RevitFunction").Invoke(obj, new object[] { doc });
obj.GetType().GetMethod("RevitFunction").Invoke(obj, new object[] { doc, uiDoc });
}
}
}

0 comments on commit 777c804

Please sign in to comment.