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); }
public bool VisualizeData() { bool result = false; try { string viewIdValue = RegistryKeyManager.GetRegistryKeyValue("RevitOutgoingViewId"); ElementId viewId = new ElementId(int.Parse(viewIdValue)); Autodesk.Revit.DB.View view = m_doc.GetElement(viewId) as Autodesk.Revit.DB.View; if (null != view) { SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(view); if (null == sfm) { sfm = SpatialFieldManager.CreateSpatialFieldManager(view, 1); } AnalysisResultSchema resultSchema = new AnalysisResultSchema(analysisType.ToString(), "Imported from DIVA"); int resultIndex = -1; //check order DataContainer tempContainer = dataDictionary[0]; XYZ node = new XYZ(tempContainer.Node.XValue, tempContainer.Node.YValue, tempContainer.Node.ZValue); IntersectionResult intersection = displayingFaces[0].Project(node); if (null == intersection) { displayingFaces.Reverse(); } //reverse the order of faces foreach (int keyIndex in dataDictionary.Keys) { DataContainer container = dataDictionary[keyIndex]; Face face = displayingFaces[keyIndex]; List <double> dblList = new List <double>(); dblList.Add(container.ResultValue); XYZ vectorZ = new XYZ(0, 0, -1); Transform transform = Transform.CreateTranslation(vectorZ); int index = sfm.AddSpatialFieldPrimitive(face, transform); IList <UV> uvPts = new List <UV>(); IList <ValueAtPoint> valList = new List <ValueAtPoint>(); XYZ nodePoint = new XYZ(container.Node.XValue, container.Node.YValue, container.Node.ZValue); IntersectionResult intersect = face.Project(nodePoint); if (null != intersect) { UV nodeUV = intersect.UVPoint; uvPts.Add(nodeUV); valList.Add(new ValueAtPoint(dblList)); FieldDomainPointsByUV domainPoints = new FieldDomainPointsByUV(uvPts); FieldValues values = new FieldValues(valList); FieldValues vals = new FieldValues(valList); if (resultIndex == -1) { resultIndex = sfm.RegisterResult(resultSchema); } else { sfm.SetResultSchema(resultIndex, resultSchema); } sfm.UpdateSpatialFieldPrimitive(index, domainPoints, values, resultIndex); } result = true; } } } catch (Exception ex) { MessageBox.Show("Failed to visualize the result data.\n" + ex.Message, "Analysis Data Manager - Visualize Data", MessageBoxButtons.OK, MessageBoxIcon.Warning); result = false; } return(result); }