added Revit 2022 SDK minus except *rvt and *rfa

This commit is contained in:
Jeremy Tammik
2021-04-20 11:36:21 +02:00
parent 1133a82dc5
commit 7e327986e8
3034 changed files with 1245318 additions and 0 deletions
@@ -0,0 +1,158 @@
//
// (C) Copyright 2003-2020 by Autodesk, Inc. All rights reserved.
//
// 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 ITS 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 Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
namespace Revit.SDK.Samples.InCanvasControlAPI.CS
{
/// <summary>
/// Implements the Revit add-in interface IExternalApplication
/// </summary>
public class Application : IExternalApplication
{
const string TabLabel = "Issues";
#region Class implementation
/// <summary>
/// Creates external application object and initializes event handlers.
/// </summary>
public Application()
{
IssueMarkerTrackingManager issueMarkerTrackingManager = IssueMarkerTrackingManager.GetInstance();
// This event handler moves or deletes the markers based on changes to the tracked elements
updateHandler = (sender, data) =>
{
IssueMarkerUpdater.Execute(data);
};
// This event handler initiates data for the opened document
openHandler = (sender, data) =>
{
issueMarkerTrackingManager.AddTracking(data.Document);
};
// This event handler initiates data for the newly-created document
createHandler = (sender, data) =>
{
issueMarkerTrackingManager.AddTracking(data.Document);
};
// This event handler prepares marker data for the document to be cleaned
closingHandler = (closingSender, closeData) =>
{
IssueMarkerTracking track = issueMarkerTrackingManager.GetTracking(closeData.Document);
if(!closingDocumentIdToIssueTrackingPairs.ContainsKey(closeData.DocumentId) && !closeData.IsCancelled())
closingDocumentIdToIssueTrackingPairs.Add(closeData.DocumentId, track.Id);
};
// This event handler cleans marker data after the document is closed
closedHandler = (closedSender, closedData) =>
{
issueMarkerTrackingManager.DeleteTracking(closingDocumentIdToIssueTrackingPairs[closedData.DocumentId]);
closingDocumentIdToIssueTrackingPairs.Remove(closedData.DocumentId);
};
}
#endregion
#region IExternalApplication Members
/// <summary>
/// Implements the OnShutdown event. It cleans up events and IssueMarkerTrackingManager
/// </summary>
/// <param name="application"></param>
/// <returns></returns>
public Result OnShutdown(UIControlledApplication application)
{
application.ControlledApplication.DocumentChanged -= updateHandler;
application.ControlledApplication.DocumentOpened -= openHandler;
application.ControlledApplication.DocumentCreated -= createHandler;
application.ControlledApplication.DocumentClosing -= closingHandler;
application.ControlledApplication.DocumentClosed -= closedHandler;
IssueMarkerTrackingManager.GetInstance().ClearTrackings();
return Result.Succeeded;
}
/// <summary>
/// Implements the OnStartup event. It adds a server to listen for clicks on issue markers, events that manage issue marker data based on changes in document,
/// and a button that lets user create an issue marker.
/// </summary>
/// <param name="application"></param>
/// <returns></returns>
public Result OnStartup(UIControlledApplication application)
{
IssueSelectHandler click = new IssueSelectHandler();
//This registers a service. On success, we register a button or event as well.
Autodesk.Revit.DB.ExternalService.ExternalService service = Autodesk.Revit.DB.ExternalService.ExternalServiceRegistry.GetService(click.GetServiceId());
if (service != null)
{
service.AddServer(click);
(service as Autodesk.Revit.DB.ExternalService.MultiServerService).SetActiveServers(new List<Guid>() { click.GetServerId() });
RibbonPanel ribbonPanel = application.GetRibbonPanels(Tab.AddIns).Find(x => x.Name == TabLabel);
if (ribbonPanel == null)
ribbonPanel = application.CreateRibbonPanel(Tab.AddIns, TabLabel);
RibbonItemData ribbonItemData = new PushButtonData("Create marker", "Create issue marker on an element",
System.Reflection.Assembly.GetExecutingAssembly().Location, typeof(Command).FullName);
PushButton pushButton = (PushButton)ribbonPanel.AddItem(ribbonItemData);
application.ControlledApplication.DocumentChanged += updateHandler;
application.ControlledApplication.DocumentOpened += openHandler;
application.ControlledApplication.DocumentCreated += createHandler;
application.ControlledApplication.DocumentClosing += closingHandler;
application.ControlledApplication.DocumentClosed += closedHandler;
return Result.Succeeded;
}
return Result.Failed;
}
#endregion
#region Class members
private Dictionary<int, Guid> closingDocumentIdToIssueTrackingPairs = new Dictionary<int, Guid>();
private EventHandler<Autodesk.Revit.DB.Events.DocumentChangedEventArgs> updateHandler;
private EventHandler<Autodesk.Revit.DB.Events.DocumentOpenedEventArgs> openHandler;
private EventHandler<Autodesk.Revit.DB.Events.DocumentCreatedEventArgs> createHandler;
private EventHandler<Autodesk.Revit.DB.Events.DocumentClosedEventArgs> closedHandler;
private EventHandler<Autodesk.Revit.DB.Events.DocumentClosingEventArgs> closingHandler;
#endregion
}
}
@@ -0,0 +1,85 @@
//
// (C) Copyright 2003-2020 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 Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System;
namespace Revit.SDK.Samples.InCanvasControlAPI.CS
{
/// <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 Command : 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;
Selection choices = commandData.Application.ActiveUIDocument.Selection;
IssueMarkerTracking tracking = IssueMarkerTrackingManager.GetInstance().GetTracking(document);
// Pick one object from Revit.
Reference hasPickOne = choices.PickObject(ObjectType.Element, "Select an element to create a control on.");
if (hasPickOne != null && tracking.GetMarkerByElementId(hasPickOne.ElementId) == null)
{
IssueMarker marker = IssueMarker.Create(document, hasPickOne.ElementId);
// Register the marker in tracking.
tracking.SubscribeMarker(marker);
}
return Result.Succeeded;
}
catch (Exception ex)
{
message = ex.Message;
return Result.Failed;
}
}
}
}
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
<AddIn Type="Command">
<Assembly>InCanvasControlAPI.dll</Assembly>
<ClientId>09102c26-2bed-42ae-b43c-8b43054941e8</ClientId>
<FullClassName>Revit.SDK.Samples.InCanvasControlAPI.CS.Command</FullClassName>
<Text>In-Canvas controls</Text>
<Description>This sample will demonstrate how to create, keep track of and handle clicks on In-Canvas controls.</Description>
<VisibilityMode>AlwaysVisible</VisibilityMode>
<LanguageType>Unknown</LanguageType>
<VendorId>ADSK</VendorId>
</AddIn>
<AddIn Type="Application">
<Name>InCanvasControlAPI</Name>
<Assembly>InCanvasControlAPI.dll</Assembly>
<ClientId>4be11e1a-44eb-444e-b186-2fc4472a211a</ClientId>
<FullClassName>Revit.SDK.Samples.InCanvasControlAPI.CS.Application</FullClassName>
<VendorId>ADSK</VendorId>
<VendorDescription>Autodesk, www.autodesk.com</VendorDescription>
</AddIn>
</RevitAddIns>
@@ -0,0 +1,106 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{685C2952-1BD0-42D8-B43B-6856A475DF1F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>InCanvasControlAPI</RootNamespace>
<AssemblyName>InCanvasControlAPI</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DocumentationFile>bin\Debug\InCanvasControlAPI.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DocumentationFile>bin\Release\InCanvasControlAPI.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DocumentationFile>bin\Debug\InCanvasControlAPI.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DocumentationFile>bin\Release\InCanvasControlAPI.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Core">
<RequiredTargetFramework>4.7</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Application.cs" />
<Compile Include="Command.cs" />
<Compile Include="IssueMarkerTracking.cs" />
<Compile Include="IssueMarkerSelector.cs" />
<Compile Include="IssueMarkerTrackingManager.cs" />
<Compile Include="IssueSelectHandler.cs" />
<Compile Include="IssueMarker.cs" />
<Compile Include="IssueMarkerUpdater.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ResourceProvider.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="issue.bmp">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="selected.bmp">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(SolutionDir)VSProps\SDKSamples.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<PropertyGroup>
<PostBuildEvent>set FILEFORSAMPLEREG="$(SolutionDir)..\..\..\..\Regression\API\SDKSamples\UpdateSampleDllForRegression.pl"
if exist %25FILEFORSAMPLEREG%25 perl %25FILEFORSAMPLEREG%25 $(ProjectExt) "$(ProjectPath)" "$(TargetPath)" "$(SolutionDir)"</PostBuildEvent>
</PropertyGroup>
</Project>
@@ -0,0 +1,110 @@
//
// (C) Copyright 2003-2020 by Autodesk, Inc. All rights reserved.
//
// 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 ITS 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 Autodesk.Revit.DB;
namespace Revit.SDK.Samples.InCanvasControlAPI.CS
{
/// <summary>
/// A simple object to keep the connection between marker control and the given element.
/// </summary>
public class IssueMarker
{
#region Class implementation
private IssueMarker(ElementId elementId, int controlIndex, InCanvasControlData inCanvasControlData)
{
this.elementId = elementId;
this.controlIndex = controlIndex;
inCanvasData = inCanvasControlData;
}
/// <summary>
/// Creates an issue marker. It also creates an In-Canvas control on given element's position.
/// </summary>
/// <param name="document">Document in which the tracked element is.</param>
/// <param name="elementId">Tracked element id.</param>
/// <returns>IssueMarker created from data</returns>
public static IssueMarker Create(Document document, ElementId elementId)
{
ResourceProvider resourceProvider = ResourceProvider.GetInstance();
// Prepare InCanvasControlData. It needs position and image path.
// In this example, all controls will share the same image - though it is possible to create controls with different images, or even change it via an update (see IssueMarkerSelector::SelectMarker).
Element elementTracked = document.GetElement(elementId);
XYZ elementLocation = new XYZ();
if (elementTracked.Location is LocationPoint pointLoc)
{
elementLocation = pointLoc.Point;
}
else if (elementTracked.Location is LocationCurve curveLoc)
{
elementLocation = curveLoc.Curve.GetEndPoint(0);
}
InCanvasControlData inCanvasControlData = new InCanvasControlData(resourceProvider.IssueImage, elementLocation);
// Create In-Canvas control
TemporaryGraphicsManager manager = TemporaryGraphicsManager.GetTemporaryGraphicsManager(document);
int controlIndex = manager.AddControl(inCanvasControlData, ElementId.InvalidElementId);
return new IssueMarker(elementId, controlIndex, inCanvasControlData);
}
/// <summary>
/// Data with which an In-Canvas control was created. We need to keep this to make small changes later on.
/// </summary>
public InCanvasControlData InCanvasControlData
{
get
{
return inCanvasData;
}
set
{
inCanvasData = value;
}
}
/// <summary>
/// Index of the control, returned by TemporaryGraphicsManager
/// </summary>
public int ControlIndex { get => controlIndex; }
/// <summary>
/// Id of the element that the marker tracks
/// </summary>
public ElementId TrackedElementId { get => elementId; }
#endregion
#region Class member variables
private int controlIndex;
private ElementId elementId;
private InCanvasControlData inCanvasData;
#endregion
}
}
@@ -0,0 +1,75 @@
//
// (C) Copyright 2003-2020 by Autodesk, Inc. All rights reserved.
//
// 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 ITS 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 Autodesk.Revit.DB;
namespace Revit.SDK.Samples.InCanvasControlAPI.CS
{
/// <summary>
/// This class demonstrates marking a marker selected by changing the in-canvas control's image.
/// </summary>
public class IssueMarkerSelector
{
#region Class implementation
/// <summary>
/// Changes selected issue marker in given document's tracking
/// </summary>
/// <param name="document">A Revit document</param>
/// <param name="controlIndex">Id of the clicked In-Canvas control</param>
public static void SelectMarker(Document document, int controlIndex)
{
TemporaryGraphicsManager tempGraphicsManager = TemporaryGraphicsManager.GetTemporaryGraphicsManager(document);
IssueMarkerTracking issueMarkerTracking = IssueMarkerTrackingManager.GetInstance().GetTracking(document);
ResourceProvider provider = ResourceProvider.GetInstance();
// Check if the new selection is valid
IssueMarker newSelectedMarker = issueMarkerTracking.GetMarkerByIndex(controlIndex);
if (newSelectedMarker == null)
return;
// clear previous selection
IssueMarker selectedMarker = issueMarkerTracking.GetMarkerByIndex(issueMarkerTracking.GetSelected());
if (selectedMarker != null)
{
selectedMarker.InCanvasControlData.ImagePath = provider.IssueImage;
// This is how to set updated data to a control
tempGraphicsManager.UpdateControl(selectedMarker.ControlIndex, selectedMarker.InCanvasControlData);
issueMarkerTracking.SetSelected(-1);
}
if (newSelectedMarker != selectedMarker)
{
newSelectedMarker.InCanvasControlData.ImagePath = provider.SelectedIssueImage;
// This is how to set updated data to a control
tempGraphicsManager.UpdateControl(newSelectedMarker.ControlIndex, newSelectedMarker.InCanvasControlData);
issueMarkerTracking.SetSelected(controlIndex);
}
}
#endregion
}
}
@@ -0,0 +1,128 @@
//
// (C) Copyright 2003-2020 by Autodesk, Inc. All rights reserved.
//
// 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 ITS 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 Autodesk.Revit.DB;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Revit.SDK.Samples.InCanvasControlAPI.CS
{
/// <summary>
/// A class tracks all issue markers in a given document. It also tracks the index of the active selected marker.
/// </summary>
public class IssueMarkerTracking
{
#region Class implementation
/// <summary>
/// Creates IssueMarkerTracking for the opened document and initializes selected index
/// </summary>
/// <param name="document">An opened Revit document</param>
public IssueMarkerTracking(Document document)
{
this.document = document;
guid = Guid.NewGuid();
selectedIndex = -1;
}
/// <summary>
/// Adds a marker to this tracking
/// </summary>
/// <param name="marker">Marker to be updated by selector or updater.</param>
public void SubscribeMarker(IssueMarker marker)
{
issueMarkerSet.Add(marker);
}
/// <summary>
/// Removes marker that tracks the element specified by id.
/// </summary>
/// <param name="elementId">Tracked element id</param>
public void RemoveMarkerByElement(ElementId elementId)
{
issueMarkerSet.RemoveWhere((m) => m.TrackedElementId == elementId);
}
/// <summary>
/// Gets the issue marker that tracks element specified by id
/// </summary>
/// <param name="elementId">Tracked element id</param>
/// <returns>A corresponding Issue Marker</returns>
public IssueMarker GetMarkerByElementId(ElementId elementId)
{
return issueMarkerSet.Where((m) => m.TrackedElementId == elementId).FirstOrDefault();
}
/// <summary>
/// Gets the issue marker by it's id in TemporaryGraphicsManager
/// </summary>
/// <param name="index">Index of the in-canvas control</param>
/// <returns>A corresponding Issue Marker</returns>
public IssueMarker GetMarkerByIndex(int index)
{
return issueMarkerSet.Where((m) => m.ControlIndex == index).FirstOrDefault();
}
/// <summary>
/// Document this object tracks
/// </summary>
public Document Document { get => document; }
/// <summary>
/// Tracker's GUID. This is needed to safely clean up after document closes.
/// </summary>
public Guid Id { get => guid; }
/// <summary>
/// Gets the index of selected marker. This is used by selector
/// </summary>
/// <returns>The index of selected marker</returns>
public int GetSelected()
{
return selectedIndex;
}
/// <summary>
/// Sets the index of selected marker. This is used by selector
/// </summary>
/// <param name="index">Index of the marker</param>
public void SetSelected(int index)
{
selectedIndex = index;
}
#endregion
#region Class member variables
private int selectedIndex;
private HashSet<IssueMarker> issueMarkerSet = new HashSet<IssueMarker>();
private Document document;
private Guid guid;
#endregion
}
}
@@ -0,0 +1,103 @@
//
// (C) Copyright 2003-2020 by Autodesk, Inc. All rights reserved.
//
// 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 ITS 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 Autodesk.Revit.DB;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Revit.SDK.Samples.InCanvasControlAPI.CS
{
/// <summary>
/// This class manages instances of IssueMarkerTracking on per-document basis.
/// </summary>
public class IssueMarkerTrackingManager
{
#region Class implementation
private IssueMarkerTrackingManager()
{
}
/// <summary>
/// Gets an instance of IssueMarkerTrackingManager.
/// </summary>
/// <returns>An instance of IssueMarkerTrackingManager</returns>
public static IssueMarkerTrackingManager GetInstance()
{
if(manager == null)
{
manager = new IssueMarkerTrackingManager();
}
return manager;
}
/// <summary>
/// Gets tracking for specified document
/// </summary>
/// <param name="doc">A Revit document</param>
/// <returns>A corresponding instance of IssueMarkerTracking</returns>
public IssueMarkerTracking GetTracking(Document doc)
{
if (trackings.Where((track) => track.Document.Equals(doc)).FirstOrDefault() is IssueMarkerTracking tracking)
return tracking;
return null;
}
/// <summary>
/// Adds IssueMarkerTracking for the given document
/// </summary>
/// <param name="doc">A Revit document</param>
public void AddTracking(Document doc)
{
if(!trackings.Any((track) => track.Document.Equals(doc)))
trackings.Add(new IssueMarkerTracking(doc));
}
/// <summary>
/// Removes IssueMarkerTracking from this manager
/// </summary>
/// <param name="guid">A GUID of the tracking</param>
public void DeleteTracking(Guid guid)
{
trackings.RemoveWhere((track) => track.Id == guid);
}
/// <summary>
/// Clears all trackings
/// </summary>
public void ClearTrackings()
{
trackings.Clear();
}
#endregion
#region Class member variables
private static IssueMarkerTrackingManager manager;
private HashSet<IssueMarkerTracking> trackings = new HashSet<IssueMarkerTracking>();
#endregion
}
}
@@ -0,0 +1,86 @@
//
// (C) Copyright 2003-2020 by Autodesk, Inc. All rights reserved.
//
// 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 ITS 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 Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;
namespace Revit.SDK.Samples.InCanvasControlAPI.CS
{
/// <summary>
/// This class demonstrates updating in-canvas controls in a DocumentUpdated event handler.
/// </summary>
public class IssueMarkerUpdater
{
#region Class implementation
/// <summary>
/// Perform updates on in-canvas controls.
/// In this example, the In-Canvas controls will be deleted, or have their positions changed, depending on the changes to related elements.
/// </summary>
/// <param name="data">Data about changes in the document.</param>
public static void Execute(DocumentChangedEventArgs data)
{
Document doc = data.GetDocument();
TemporaryGraphicsManager temporaryGraphicsManager = TemporaryGraphicsManager.GetTemporaryGraphicsManager(doc);
IssueMarkerTracking tracking = IssueMarkerTrackingManager.GetInstance().GetTracking(doc);
foreach (ElementId deleted in data.GetDeletedElementIds())
{
if (tracking.GetMarkerByElementId(deleted) is IssueMarker marker)
{
// This is how to delete control
temporaryGraphicsManager.RemoveControl(marker.ControlIndex);
// Don't forget to clean up your own data
tracking.RemoveMarkerByElement(deleted);
}
}
foreach (ElementId updated in data.GetModifiedElementIds())
{
if (tracking.GetMarkerByElementId(updated) is IssueMarker marker)
{
Element element = doc.GetElement(updated);
// Since we keep a copy of InCanvasControlData, we can avoid creating a new one. It already has image and position set - and we can just change the position
InCanvasControlData controlData = marker.InCanvasControlData;
if (element.Location is LocationPoint pointLoc)
{
controlData.Position = pointLoc.Point;
}
else if (element.Location is LocationCurve curveLoc)
{
controlData.Position = curveLoc.Curve.GetEndPoint(0);
}
marker.InCanvasControlData = controlData;
// This is how to set updated data to a control
temporaryGraphicsManager.UpdateControl(marker.ControlIndex, marker.InCanvasControlData);
}
}
}
#endregion
}
}
@@ -0,0 +1,91 @@
//
// (C) Copyright 2003-2020 by Autodesk, Inc. All rights reserved.
//
// 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 ITS 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 Autodesk.Revit.UI;
using System;
namespace Revit.SDK.Samples.InCanvasControlAPI.CS
{
/// <summary>
/// This class demonstrates using external server to handle click events on an in-canvas control.
/// </summary>
public class IssueSelectHandler : ITemporaryGraphicsHandler
{
#region Class interface implementation
/// <summary>
/// Gets the handler's description
/// </summary>
/// <returns></returns>
public string GetDescription()
{
return "Changes Issue marker visual upon marker click";
}
/// <summary>
/// Gets the hander's name
/// </summary>
/// <returns></returns>
public string GetName()
{
return "Issue marker click event handler";
}
/// <summary>
/// Gets server's GUID
/// </summary>
/// <returns>External server GUID</returns>
public Guid GetServerId()
{
return new Guid("81F91FC9-B6D5-4FD4-AB5B-04F307369A79");
}
/// <summary>
/// Gets service id this server should be registered on.
/// </summary>
/// <returns></returns>
public Autodesk.Revit.DB.ExternalService.ExternalServiceId GetServiceId()
{
return Autodesk.Revit.DB.ExternalService.ExternalServices.BuiltInExternalServices.TemporaryGraphicsHandlerService;
}
/// <summary>
/// Gets vendor's name
/// </summary>
/// <returns></returns>
public string GetVendorId()
{
return "ADSK";
}
/// <summary>
/// Handles the event of control being clicked
/// </summary>
/// <param name="data">Data of the event. This only provides us with an index of the control clicked. The developer / API user should make sense of each index himself.</param>
public void OnClick(TemporaryGraphicsCommandData data)
{
IssueMarkerSelector.SelectMarker(data.Document, data.Index);
}
#endregion
}
}
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("InCanvasControlAPI")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Autodesk Inc.")]
[assembly: AssemblyProduct("InCanvasControlAPI")]
[assembly: AssemblyCopyright("Copyright © Autodesk, Inc. 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("685c2952-1bd0-42d8-b43b-6856a475df1f")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,74 @@
//
// (C) Copyright 2003-2020 by Autodesk, Inc. All rights reserved.
//
// 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 ITS 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.IO;
using System.Reflection;
namespace Revit.SDK.Samples.InCanvasControlAPI.CS
{
/// <summary>
/// Provider for string resources
/// </summary>
public class ResourceProvider
{
#region Class implementation
private ResourceProvider()
{
issueImage = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName + "\\issue.bmp";
selectedIssueImage = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName + "\\selected.bmp";
}
/// <summary>
/// Gets the string resource provider
/// </summary>
/// <returns>Instance of the provider</returns>
public static ResourceProvider GetInstance()
{
if (provider == null)
{
provider = new ResourceProvider();
}
return provider;
}
/// <summary>
/// Path to marker's bitmap for unselected issues
/// </summary>
public string IssueImage { get => issueImage; }
/// <summary>
/// Path to marker's bitmap for selected issues
/// </summary>
public string SelectedIssueImage { get => selectedIssueImage; }
#endregion
#region Class member variables
private string issueImage;
private string selectedIssueImage;
private static ResourceProvider provider;
#endregion
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB