Skip to content

Commit

Permalink
add more function document
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Aug 29, 2023
1 parent 7f2d0aa commit 97bc240
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 4 deletions.
166 changes: 163 additions & 3 deletions OpenMEPRevit/Document/Document.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Autodesk.DesignScript.Runtime;
using Autodesk.Revit.DB;
using Dynamo.Graph.Nodes;
using OpenMEPRevit.Helpers;
using RevitServices.Persistence;

Expand All @@ -14,8 +16,8 @@ public class Document
{
private Document()
{

}

/// <summary>
/// Get Document Current
/// </summary>
Expand All @@ -25,8 +27,8 @@ private Document()
/// <example>
/// ![](../OpenMEPPage/document/dyn/pic/Document.Current.png)
/// </example>
[MultiReturn("RevitDocument","DynamoDocument")]
public static Dictionary<string,object?> Current(bool toggle = true)
[MultiReturn("RevitDocument", "DynamoDocument")]
public static Dictionary<string, object?> Current(bool toggle = true)
{
Autodesk.Revit.DB.Document? RevitDocument = null;
Revit.Application.Document? DynamoDocument = null;
Expand All @@ -42,4 +44,162 @@ private Document()
{nameof(DynamoDocument), DynamoDocument}
};
}

/// <summary>
/// Get Document Title
/// </summary>
/// <param name="revitDocument">Autodesk.Revit.DB.Document</param>
/// <returns name="str">Title of Document</returns>
public static string Title(Autodesk.Revit.DB.Document revitDocument)
{
return revitDocument.Title;
}

/// <summary>
/// Identifies if a document is a linked RVT
/// </summary>
/// <param name="revitDocument">Autodesk.Revit.DB.Document</param>
/// <returns name="bool">true if document is linked RVT</returns>
[NodeCategory("Query")]
public static bool IsLinked(Autodesk.Revit.DB.Document revitDocument)
{
return revitDocument.IsLinked;
}

/// <summary>
/// Provides access to display unit type with in the document.
/// </summary>
/// <param name="revitDocument">Autodesk.Revit.DB.Document</param>
/// <returns name="DisplayUnitSystem">Return the display unit type, metric or imperial.</returns>
public static string DisplayUnitSystem(Autodesk.Revit.DB.Document revitDocument)
{
return revitDocument.DisplayUnitSystem.ToString();
}
/// <summary>
/// Identifies if the current document is a family document.
/// </summary>
/// <param name="revitDocument">Autodesk.Revit.DB.Document</param>
/// <returns name="bool">true if document is family document</returns>
[NodeCategory("Query")]
public static bool IsFamilyDocument(Autodesk.Revit.DB.Document revitDocument)
{
return revitDocument.IsFamilyDocument;
}
/// <summary>
/// Identifies if a work-shared document is detached.
/// Also, see <see cref="P:Autodesk.Revit.DB.Document.IsWorkshared" /></summary>
/// <remarks>
/// Note that <see cref="P:Autodesk.Revit.DB.Document.Title" /> and <see cref="P:Autodesk.Revit.DB.Document.PathName" /> will be empty strings if a document is detached.
/// </remarks>
/// <para name="revitDocument">Autodesk.Revit.DB.Document</para>
/// <returns name="bool">true if work-shared document is detached</returns>
/// <since>2015</since>
[NodeCategory("Query")]
public static bool IsDetached(Autodesk.Revit.DB.Document revitDocument)
{
return revitDocument.IsDetached;
}

/// <summary>Gets ForgeDM folder id where the model locates.</summary>
/// <remarks>
/// It is empty for non-cloud model;
/// It is cached in Revit model opened session after getting it if forceRefresh is false;
/// ForgeDM folder id can be changed during Revit model opened session, set forceRefresh as 'true' to get new value.
/// </remarks>
/// <param name="revitDocument">Autodesk.Revit.DB.Document</param>
/// <param name="forceRefresh">
/// Cached value will be refreshed by sending a service call when forceRefresh is true.
/// </param>
/// <exception cref="T:Autodesk.Revit.Exceptions.RevitServerUnauthorizedException">
/// Thrown when cannot get data from ForgeDM for Revit cloud model.
/// </exception>
/// <since>2022</since>
public static string GetCloudFolderId(Autodesk.Revit.DB.Document revitDocument,bool forceRefresh =false)
{
return revitDocument.GetCloudFolderId(forceRefresh);
}

/// <summary>Gets the cloud model path of the cloud model.</summary>
/// <returns>The cloud model path</returns>
/// <exception cref="T:Autodesk.Revit.Exceptions.InvalidOperationException">
/// This Document is a not cloud model, cannot execute this operation.
/// </exception>
/// <para name="CentralServerPath">The path to the location of the central Revit server or cloud.</para>
/// <para name="CloudPath">Whether this path represents a path on an Autodesk server such as BIM360.</para>
/// <para name="Region">The region of the BIM 360 Docs or Autodesk Docs account and project which contains this model.</para>
/// <para name="ServerPath">Whether this path is a server path (as opposed to a file path or cloud path).</para>
/// <para name="ModelGUID">A GUID identifying the Revit cloud model.</para>
/// <para name="ProjectGUID">A GUID identifying the BIM 360 Docs or Autodesk Docs project to which the model is associated.</para>
/// <since>2019.1</since>
[MultiReturn("CentralServerPath", "CloudPath", "Region", "ServerPath", "ModelGUID", "ProjectGUID")]
public static Dictionary<string,object> GetCloudModelPath(Autodesk.Revit.DB.Document revitDocument)
{
ModelPath? modelPath = revitDocument.GetCloudModelPath();
if (modelPath == null)
{
return new Dictionary<string, object>()
{
{"CentralServerPath", ""},
{"CloudPath",""},
{"Region",""},
{"ServerPath",""},
{"ModelGUID",""},
{"ProjectGUID",""}
};
}
return new Dictionary<string, object>()
{
{"CentralServerPath", modelPath.CentralServerPath},
{"CloudPath",modelPath.CloudPath},
{"Region",modelPath.Region},
{"ServerPath",modelPath.ServerPath},
{"ModelGUID",modelPath.GetModelGUID()},
{"ProjectGUID",modelPath.GetProjectGUID()}
};
}
/// <summary>A ForgeDM Urn identifying the model.</summary>
/// <param name="revitDocument">Autodesk.Revit.DB.Document</param>
/// <remarks>
/// It is empty for non-cloud model;
/// It is cached in Revit model opened session after getting it;
/// </remarks>
/// <exception cref="T:Autodesk.Revit.Exceptions.RevitServerUnauthorizedException">
/// Thrown when cannot get data from ForgeDM.
/// </exception>
/// <since>2022</since>
public static string GetCloudModelUrn(Autodesk.Revit.DB.Document revitDocument)
{
return revitDocument.GetCloudModelUrn();
}
/// <summary>
/// Convert Revit Document to Dynamo Document
/// </summary>
/// <param name="revitDocument">Autodesk.Revit.DB.Document</param>
/// <returns name="Document">Revit.Application.Document</returns>
public static Revit.Application.Document? ToDynamoDocument(Autodesk.Revit.DB.Document? revitDocument)
{
if (revitDocument == null) return null;
return revitDocument.ToDynamoType();
}

/// <summary>
/// Convert Dynamo Document to Revit Document
/// </summary>
/// <param name="dynamoDocument">Revit.Application.Document</param>
/// <returns name="revitDocument">Autodesk.Revit.DB.Document</returns>
public static Autodesk.Revit.DB.Document? ToRevitDocument(Revit.Application.Document? dynamoDocument)
{
if (dynamoDocument == null) return null;
return dynamoDocument.ToRevitType();
}
/// <summary>
/// Get Application From Revit Document
/// </summary>
/// <param name="revitDocument">Autodesk.Revit.DB.Document</param>
/// <returns name="Application">Autodesk.Revit.ApplicationServices.Application</returns>
public static Autodesk.Revit.ApplicationServices.Application Application(
Autodesk.Revit.DB.Document revitDocument)
{
return revitDocument.Application;
}
}
2 changes: 1 addition & 1 deletion OpenMEPRevit/Helpers/Convert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal static class Convert
/// <param name="item"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
internal static dynDocument? ToDynamoType(this rvtDocument item)
internal static dynDocument? ToDynamoType(this rvtDocument? item)
{
if (item == null) throw new ArgumentNullException(nameof(item));
var constructor = typeof(dynDocument).GetConstructors(
Expand Down

0 comments on commit 97bc240

Please sign in to comment.