public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { m_app = commandData.Application; m_doc = m_app.ActiveUIDocument.Document; if (AppCommand.Instance.ReceiverActivated == false) //to be activated { RegistryKeyManager.SetRegistryKeyValue("RevitDocName", m_doc.PathName); } AppCommand.Instance.Toggle(); return(Result.Succeeded); }
public void OnIdling(object sender, IdlingEventArgs e) { if (receiverActivated) { UIApplication uiapp = sender as UIApplication; Document doc = uiapp.ActiveUIDocument.Document; e.SetRaiseWithoutDelay(); string value = RegistryKeyManager.GetRegistryKeyValue("RhinoOutgoing"); if (!string.IsNullOrEmpty(value)) { if (value.ToLower() == "true") { TaskDialog dialog = new TaskDialog("Rhino Receiver"); dialog.MainInstruction = "Rhino Data"; dialog.MainContent = "Analysis data from Rhino is being sent to Revit."; dialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, "Visualize Analysis Results"); dialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink2, "Cancel"); TaskDialogResult result = dialog.Show(); if (result == TaskDialogResult.CommandLink1) { //AVF string tempDirectory = RegistryKeyManager.GetRegistryKeyValue("DivaTempDirectory"); string[] gridFiles = Directory.GetFiles(tempDirectory, "*-AnalysisGrid.obj"); if (gridFiles.Length > 0) { List <ObjMesh> objMeshes = new List <ObjMesh>(); bool objImported = ObjImporter.ReadObjFile(gridFiles[0], out objMeshes); string dataPath = RegistryKeyManager.GetRegistryKeyValue("RhinoOutgoingPath"); AnalysisDataManager avf = new AnalysisDataManager(uiapp, objMeshes, dataPath); if (avf.ReadResults()) { if (avf.CreateGeometry()) { if (avf.VisualizeData()) { MessageBox.Show("Result data from Rhino was successfully visualized."); } } } } } RegistryKeyManager.SetRegistryKeyValue("RhinoOutgoing", "False"); } } } }
public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { try { m_app = commandData.Application; m_doc = m_app.ActiveUIDocument.Document; DialogResult dr = MessageBox.Show("Would you like to export the active view as DWG and open the file in Rhino?", "Export to DWG", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { Autodesk.Revit.DB.View activeView = m_doc.ActiveView; string revitPath = m_doc.PathName; if (!string.IsNullOrEmpty(revitPath)) { string directory = Path.GetDirectoryName(revitPath); if (Directory.Exists(directory)) { string fileName = Path.GetFileNameWithoutExtension(revitPath); DWGExportOptions options = new DWGExportOptions(); options.ExportOfSolids = SolidGeometry.ACIS; options.TargetUnit = ExportUnit.Foot; ICollection <ElementId> views = new List <ElementId>(); views.Add(activeView.Id); bool exported = false; Guid transId = new Guid(); using (Transaction trans = new Transaction(m_doc)) { try { transId = Guid.NewGuid(); trans.Start(transId.ToString()); exported = m_doc.Export(directory, fileName, views, options); trans.Commit(); } catch (Exception ex) { trans.RollBack(); MessageBox.Show("DWG Export was failed.\n" + ex.Message, "DWG Export", MessageBoxButtons.OK, MessageBoxIcon.Information); } } if (exported) { string dwgFileName = Path.Combine(directory, fileName + ".dwg"); if (File.Exists(dwgFileName)) { RegistryKeyManager.SetRegistryKeyValue("RevitOutgoing", exported.ToString()); RegistryKeyManager.SetRegistryKeyValue("RevitOutgoingViewId", activeView.Id.IntegerValue.ToString()); RegistryKeyManager.SetRegistryKeyValue("RevitOutgoingPath", dwgFileName); RegistryKeyManager.SetRegistryKeyValue("RevitOutgoingId", transId.ToString()); //Run Rhino Script dynamic rhino = AppCommand.Instance.RhinoInstance; if (File.Exists(dwgFileName)) { string script = string.Format("-DocumentProperties Enter U Enter U Enter F Enter Enter Enter Enter"); //document units to foot rhino.RunScript(script, false); script = string.Format("-Import \"{0}\" Enter o Enter F Enter y Enter F Enter", dwgFileName); //model and layout unit to foot rhino.RunScript(script, false); string rhinoFileName = dwgFileName.Replace(".dwg", ".3dm"); if (File.Exists(rhinoFileName)) { File.Delete(rhinoFileName); } script = string.Format("-SaveAs \"{0}\" Enter", rhinoFileName); rhino.RunScript(script, false); string weatherFile = @"C:\DIVA\WeatherData\USA_AK_Anchorage.Intl.AP.702730_TMY3.epw"; script = string.Format("-ProjectInfo \"{0}\" Enter", weatherFile); if (File.Exists(rhinoFileName)) { RegistryKeyManager.SetRegistryKeyValue("RhinoIncoming", true.ToString()); RegistryKeyManager.SetRegistryKeyValue("RhinoIncomingPath", rhinoFileName); RegistryKeyManager.SetRegistryKeyValue("RhinoIncoming", transId.ToString()); rhino.Visible = 1; } } } } } } } else if (dr == DialogResult.No) { MessageBox.Show("Please open a view to be exported as DWG format.", "Active View", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show("Failed to send data to Rhino.\n" + ex.Message, "Send to Rhino", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(Result.Succeeded); }