copied Revit 2024 SDK

This commit is contained in:
Jeremy Tammik
2023-04-26 14:47:47 +02:00
parent 2ca39e38fd
commit 4d69f3eea5
425 changed files with 344414 additions and 2296 deletions
@@ -14,8 +14,6 @@ namespace ContextualAnalyticalModel
/// <summary>
/// Implements the Revit add-in interface IExternalCommand
/// Adds new relation between physical and analytical elements using AnalyticalToPhysicalAssociationManager
/// The relation can be between multiple physical and analytical elements
/// AnalyticalToPhysicalAssociationManager can work with Revit linked files also
/// </summary>
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI.Selection;
namespace ContextualAnalyticalModel
{
/// <summary>
/// Implements the Revit add-in interface IExternalCommand
/// Adds new relation between physical and analytical elements using AnalyticalToPhysicalAssociationManager
/// The relation can be between multiple physical and analytical elements
/// </summary>
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class AddCustomAssociation : IExternalCommand
{
/// <summary>
/// Implement this method as an external command for Revit.
/// </summary>
/// <param name="commandData">An object that is passed to the external application
/// which contains data related to the command,
/// such as the application object and active view.</param>
/// <param name="message">A message that can be set by the external application
/// which will be displayed if a failure or cancellation is returned by
/// the external command.</param>
/// <param name="elements">A set of elements to which the external application
/// can add elements that are to be highlighted in case of failure or cancellation.</param>
/// <returns>Return the status of the external command.
/// A result of Succeeded means that the API external method functioned as expected.
/// Cancelled can be used to signify that the user cancelled the external operation
/// at some point. Failure should be returned if the application is unable to proceed with
/// the operation.</returns>
public virtual Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument activeDoc = commandData.Application.ActiveUIDocument;
Autodesk.Revit.DB.Document doc = activeDoc.Document;
if (null == doc)
{
return Result.Failed;
}
using (Transaction trans = new Transaction(doc, "Revit.SDK.Samples.AddRelationBetweenPhysicalAndAnalyticalElements"))
{
trans.Start();
ISet<ElementId> analyticalElementIds = ContextualAnalyticalModel.Utilities.GetSelectedObjects(activeDoc, "Please select analytical elements");
ISet<ElementId> physicalElementIds = ContextualAnalyticalModel.Utilities.GetSelectedObjects(activeDoc, "Please select physical elements");
//gets the AnalyticalToPhysicalAssociationManager for the current document
AnalyticalToPhysicalAssociationManager analyticalToPhysicalmanager = AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager(doc);
if (analyticalToPhysicalmanager == null)
return Result.Failed;
//creates a new relation between physical and analytical selected elements
analyticalToPhysicalmanager.AddAssociation(analyticalElementIds, physicalElementIds);
trans.Commit();
}
return Result.Succeeded;
}
}
}
@@ -160,4 +160,14 @@
<LanguageType>Unknown</LanguageType>
<VendorId>ADSK</VendorId>
</AddIn>
<AddIn Type="Command">
<Assembly>ContextualAnalyticalModel.dll</Assembly>
<ClientId>68B4E24B-DBFF-423B-B218-240A155142FD</ClientId>
<FullClassName>ContextualAnalyticalModel.CreateAnalyticalCurvedPanel</FullClassName>
<Text>Create Analytical Curved Panel</Text>
<Description>Create Analytical Curved Panel</Description>
<VisibilityMode>AlwaysVisible</VisibilityMode>
<LanguageType>Unknown</LanguageType>
<VendorId>ADSK</VendorId>
</AddIn>
</RevitAddIns>
@@ -62,18 +62,6 @@
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
<Reference Include="RevitAddInUtility">
<HintPath>..\..\..\..\..\..\Debugx64\RevitAddInUtility.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RevitAPI">
<HintPath>..\..\..\..\..\..\Debugx64\RevitAPI.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RevitAPIUI">
<HintPath>..\..\..\..\..\..\Debugx64\RevitAPIUI.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
@@ -85,9 +73,14 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AddCustomAssociation.cs" />
<Compile Include="AddAssociation.cs" />
<Compile Include="AnalyticalNodeConnStatus.cs" />
<Compile Include="CreateAreaLoadWithRefPoint.cs" />
<Compile Include="CreateAnalyticalCurvedPanel.cs" />
<Compile Include="CustomAreaLoad.cs" />
<Compile Include="CustomLineLoad.cs" />
<Compile Include="CustomPointLoad.cs" />
<Compile Include="RemoveAssociation.cs" />
<Compile Include="CreateAnalytcalPanel.cs" />
<Compile Include="CreateAnalyticalMember.cs" />
@@ -113,7 +106,7 @@
</Target>
-->
<PropertyGroup>
<PostBuildEvent>set FILEFORSAMPLEREG="$(SolutionDir)..\..\..\..\Regression\API\SDKSamples\UpdateSampleDllForRegression.pl"
if exist %25FILEFORSAMPLEREG%25 perl %25FILEFORSAMPLEREG%25 $(ProjectExt) "$(ProjectPath)" "$(TargetPath)" "$(SolutionDir)"</PostBuildEvent>
<PostBuildEvent>set FILEFORSAMPLEREG="$(SolutionDir)..\..\..\..\Regression\API\SDKSamples\UpdateSampleDllForRegression.py"
if exist %25FILEFORSAMPLEREG%25 py -3 %25FILEFORSAMPLEREG%25 "$(ProjectPath)" "$(TargetPath)" "$(SolutionDir)"</PostBuildEvent>
</PropertyGroup>
</Project>
@@ -0,0 +1,116 @@
//
// (C) Copyright 2003-2021 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Windows.Forms;
using System.Collections;
using System.Collections.Generic;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI.Selection;
namespace ContextualAnalyticalModel
{
/// <summary>
/// Implements the Revit add-in interface IExternalCommand
/// </summary>
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class CreateAreaLoadWithRefPoint : IExternalCommand
{
/// <summary>
/// Implement this method as an external command for Revit.
/// </summary>
/// <param name="commandData">An object that is passed to the external application
/// which contains data related to the command,
/// such as the application object and active view.</param>
/// <param name="message">A message that can be set by the external application
/// which will be displayed if a failure or cancellation is returned by
/// the external command.</param>
/// <param name="elements">A set of elements to which the external application
/// can add elements that are to be highlighted in case of failure or cancellation.</param>
/// <returns>Return the status of the external command.
/// A result of Succeeded means that the API external method functioned as expected.
/// Cancelled can be used to signify that the user cancelled the external operation
/// at some point. Failure should be returned if the application is unable to proceed with
/// the operation.</returns>
public virtual Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
try
{
Document document = commandData.Application.ActiveUIDocument.Document;
UIDocument activeDoc = commandData.Application.ActiveUIDocument;
//select object for adding a line load
Reference eRef = activeDoc.Selection.PickObject(ObjectType.Element, "Please select the analytical element");
ElementId selectedElementId = null;
if (eRef != null && eRef.ElementId != ElementId.InvalidElementId)
selectedElementId = eRef.ElementId;
XYZ start = activeDoc.Selection.PickPoint("start");
XYZ end = activeDoc.Selection.PickPoint("end");
//create curveloop which will be assigned to the analytical panel
CurveLoop profileloop = new CurveLoop();
profileloop.Append(Line.CreateBound(
start, new XYZ(end.X, start.Y, 0)));
profileloop.Append(Line.CreateBound(
new XYZ(end.X, start.Y, 0), end));
profileloop.Append(Line.CreateBound(
end, new XYZ(start.X, end.Y, 0)));
profileloop.Append(Line.CreateBound(
new XYZ(start.X, end.Y, 0), start));
List<CurveLoop> loops = new List<CurveLoop>();
loops.Add(profileloop);
using (Transaction transaction = new Transaction(document, "Create custom AreaLoad"))
{
transaction.Start();
IList<int> refPointsIndexes = new List<int>() { 0, 2, 2};
IList<int> refPointsCurveEnds = new List<int>() { 0, 1, 0};
IList<XYZ> forceVector = new List<XYZ>() { new XYZ(0, 0, -10000), new XYZ(0, 0, 0), new XYZ(0, 0, 0) };
AreaLoad areaLoad = null;
if (AreaLoad.IsCurveLoopsInsideHostBoundaries(document, selectedElementId, loops))
areaLoad = AreaLoad.Create(document, selectedElementId, loops, forceVector, refPointsIndexes, refPointsCurveEnds, null);
transaction.Commit();
}
}
catch (Exception ex)
{
message = ex.Message;
return Result.Failed;
}
return Result.Succeeded;
}
}
}
@@ -0,0 +1,111 @@
//
// (C) Copyright 2003-2021 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Windows.Forms;
using System.Collections;
using System.Collections.Generic;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI.Selection;
namespace ContextualAnalyticalModel
{
/// <summary>
/// Implements the Revit add-in interface IExternalCommand
/// </summary>
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class CreateCustomAreaLoad : IExternalCommand
{
/// <summary>
/// Implement this method as an external command for Revit.
/// </summary>
/// <param name="commandData">An object that is passed to the external application
/// which contains data related to the command,
/// such as the application object and active view.</param>
/// <param name="message">A message that can be set by the external application
/// which will be displayed if a failure or cancellation is returned by
/// the external command.</param>
/// <param name="elements">A set of elements to which the external application
/// can add elements that are to be highlighted in case of failure or cancellation.</param>
/// <returns>Return the status of the external command.
/// A result of Succeeded means that the API external method functioned as expected.
/// Cancelled can be used to signify that the user cancelled the external operation
/// at some point. Failure should be returned if the application is unable to proceed with
/// the operation.</returns>
public virtual Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
try
{
Document document = commandData.Application.ActiveUIDocument.Document;
UIDocument activeDoc = commandData.Application.ActiveUIDocument;
//select object for adding a line load
Reference eRef = activeDoc.Selection.PickObject(ObjectType.Element, "Please select the analytical element");
ElementId selectedElementId = null;
if (eRef != null && eRef.ElementId != ElementId.InvalidElementId)
selectedElementId = eRef.ElementId;
XYZ start = activeDoc.Selection.PickPoint("start");
XYZ end = activeDoc.Selection.PickPoint("end");
//create curveloop which will be assigned to the analytical panel
CurveLoop profileloop = new CurveLoop();
profileloop.Append(Line.CreateBound(
start, new XYZ(end.X, start.Y, 0)));
profileloop.Append(Line.CreateBound(
new XYZ(end.X, start.Y, 0), end));
profileloop.Append(Line.CreateBound(
end, new XYZ(start.X, end.Y, 0)));
profileloop.Append(Line.CreateBound(
new XYZ(start.X, end.Y, 0), start));
List<CurveLoop> loops = new List<CurveLoop>();
loops.Add(profileloop);
using (Transaction transaction = new Transaction(document, "Create custom AreaLoad"))
{
transaction.Start();
AreaLoad areaLoad = null;
if (AreaLoad.IsCurveLoopsInsideHostBoundaries(document, selectedElementId, loops))
areaLoad = AreaLoad.Create(document, selectedElementId, loops, new XYZ(1,0,0), null);
transaction.Commit();
}
}
catch (Exception ex)
{
message = ex.Message;
return Result.Failed;
}
return Result.Succeeded;
}
}
}
@@ -0,0 +1,99 @@
//
// (C) Copyright 2003-2021 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Windows.Forms;
using System.Collections;
using System.Collections.Generic;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI.Selection;
namespace ContextualAnalyticalModel
{
/// <summary>
/// Implements the Revit add-in interface IExternalCommand
/// </summary>
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class CreateCustomLineLoad : IExternalCommand
{
/// <summary>
/// Implement this method as an external command for Revit.
/// </summary>
/// <param name="commandData">An object that is passed to the external application
/// which contains data related to the command,
/// such as the application object and active view.</param>
/// <param name="message">A message that can be set by the external application
/// which will be displayed if a failure or cancellation is returned by
/// the external command.</param>
/// <param name="elements">A set of elements to which the external application
/// can add elements that are to be highlighted in case of failure or cancellation.</param>
/// <returns>Return the status of the external command.
/// A result of Succeeded means that the API external method functioned as expected.
/// Cancelled can be used to signify that the user cancelled the external operation
/// at some point. Failure should be returned if the application is unable to proceed with
/// the operation.</returns>
public virtual Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
try
{
Document document = commandData.Application.ActiveUIDocument.Document;
UIDocument activeDoc = commandData.Application.ActiveUIDocument;
//select object for adding a line load
Reference eRef = activeDoc.Selection.PickObject(ObjectType.Element, "Please select the analytical element");
ElementId selectedElementId = null;
if (eRef != null && eRef.ElementId != ElementId.InvalidElementId)
selectedElementId = eRef.ElementId;
using (Transaction transaction = new Transaction(document, "Create custom LineLoad"))
{
transaction.Start();
XYZ start = activeDoc.Selection.PickPoint("start");
XYZ end = activeDoc.Selection.PickPoint("end");
Line line = Line.CreateBound(start, end);
LineLoad lineLoad = null;
if (LineLoad.IsCurveInsideHostBoundaries(document, selectedElementId, line))
lineLoad = LineLoad.Create(document, selectedElementId, line, new XYZ(1,0,0), new XYZ(1,0,0), null);
transaction.Commit();
}
}
catch (Exception ex)
{
message = ex.Message;
return Result.Failed;
}
return Result.Succeeded;
}
}
}
@@ -0,0 +1,96 @@
//
// (C) Copyright 2003-2021 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Windows.Forms;
using System.Collections;
using System.Collections.Generic;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI.Selection;
namespace ContextualAnalyticalModel
{
/// <summary>
/// Implements the Revit add-in interface IExternalCommand
/// </summary>
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class CreateCustomPointLoad : IExternalCommand
{
/// <summary>
/// Implement this method as an external command for Revit.
/// </summary>
/// <param name="commandData">An object that is passed to the external application
/// which contains data related to the command,
/// such as the application object and active view.</param>
/// <param name="message">A message that can be set by the external application
/// which will be displayed if a failure or cancellation is returned by
/// the external command.</param>
/// <param name="elements">A set of elements to which the external application
/// can add elements that are to be highlighted in case of failure or cancellation.</param>
/// <returns>Return the status of the external command.
/// A result of Succeeded means that the API external method functioned as expected.
/// Cancelled can be used to signify that the user cancelled the external operation
/// at some point. Failure should be returned if the application is unable to proceed with
/// the operation.</returns>
public virtual Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
try
{
Document document = commandData.Application.ActiveUIDocument.Document;
UIDocument activeDoc = commandData.Application.ActiveUIDocument;
//select object for adding a line load
Reference eRef = activeDoc.Selection.PickObject(ObjectType.Element, "Please select the analytical element");
ElementId selectedElementId = null;
if (eRef != null && eRef.ElementId != ElementId.InvalidElementId)
selectedElementId = eRef.ElementId;
XYZ location = activeDoc.Selection.PickPoint("Point Load location");
using (Transaction transaction = new Transaction(document, "Create custom PointLoad"))
{
transaction.Start();
PointLoad pointLoad = null;
if(PointLoad.IsPointInsideHostBoundaries(document, selectedElementId, location))
pointLoad = PointLoad.Create(document, selectedElementId, location, new XYZ(1,0,0), new XYZ(1, 0, 0), null);
transaction.Commit();
}
}
catch (Exception ex)
{
message = ex.Message;
return Result.Failed;
}
return Result.Succeeded;
}
}
}
@@ -34,5 +34,23 @@ namespace ContextualAnalyticalModel
return selectedElementId;
}
/// <summary>
/// Selects multiple Revit elements and returns the ElementIds
/// </summary>
/// <param name="uiDoc">UIDocument</param>
/// <param name="msg">status message</param>
/// <returns>List of ElementId of the selected elements</returns>
public static ISet<ElementId> GetSelectedObjects(UIDocument uiDoc, string msg)
{
ISet<ElementId> selectedElementIdList = new HashSet<ElementId>();
IList<Reference> refElemList = uiDoc.Selection.PickObjects(ObjectType.Element, msg);
if (refElemList != null)
{
selectedElementIdList = refElemList.Select(x => x.ElementId).ToHashSet();
}
return selectedElementIdList;
}
}
}