public Result OnStartup(UIControlledApplication application) { RibbonPanel panel = application.CreateRibbonPanel("RevitBIMToVec"); string assemblyPath = Assembly.GetExecutingAssembly().Location; PushButtonData btnData = new PushButtonData("Inference", "Run Inference", assemblyPath, "RevitBIMToVec.RunInference"); PushButton btn = panel.AddItem(btnData) as PushButton; btn.ToolTip = "Get Inference from the python server"; BitmapImage image = new BitmapImage(new Uri(Path.Combine(BaseDirectory, "RevitBIMToVecLogo.png"))); btn.LargeImage = image; RunInference.LoadIfcNameMapping(); try { RevitClient.StartPythonServer(); } catch (Exception e) { TaskDialog box = new TaskDialog("Python Server"); box.MainInstruction = "Error!"; box.MainContent = "Failed to start the Python server:\n" + e.Message; box.Show(); return(Result.Failed); } return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiApp = commandData.Application; Document doc = uiApp.ActiveUIDocument.Document; Selection sel = uiApp.ActiveUIDocument.Selection; List <Reference> picked = sel.PickObjects(ObjectType.Element, "Select the objects that you want to group").ToList(); List <List <string> > words = new List <List <string> >(); foreach (var objRef in picked) { Element elem = doc.GetElement(objRef); string className; List <string> elemWords = new List <string>(); if (_ifcNameMap.TryGetValue(elem.Category.Name, out className) && !elemWords.Contains(className)) { elemWords.Add(className); } List <ElementId> matIds = elem.GetMaterialIds(true).ToList(); matIds.AddRange(elem.GetMaterialIds(false).ToList()); foreach (var id in matIds) { string word = ProcessString(doc.GetElement(id).Name); if (word == "") { continue; } if (!elemWords.Contains(word)) { elemWords.Add(word); } } words.Add(elemWords); } string msg = String.Join("\n", words.Select((l) => String.Join(" ", l.ToArray())).ToArray()); RevitClient.SendData(msg); string response = RevitClient.ListenAndReturnData(); if (IncomingToken.MatchAndExecuteToken(response)) { return(Result.Succeeded); } TaskDialog box = new TaskDialog("Python Server"); box.MainInstruction = "Odd one out: "; box.MainContent = response; box.Show(); //RevitClient.SendData(msg); //ask user to select a bunch of items //get their material names, and ifc names //serialize the data into a string //send the data //receive the inference back from the server //deserialize the received inference appropriately //display a message window to show the user that inference. //incomplete return(Result.Succeeded); }
public Result OnShutdown(UIControlledApplication application) { RevitClient.StopPythonServer(); return(Result.Succeeded); }