mirror of
https://github.com/jeremytammik/RevitSdkSamples.git
synced 2026-09-23 03:59:55 +00:00
updated to Revit 2023 SDK
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
|
||||
using Autodesk.Revit;
|
||||
using Autodesk.Revit.DB;
|
||||
@@ -67,7 +68,9 @@ namespace Revit.SDK.Samples.InPlaceMembers.CS
|
||||
Transaction transaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "External Tool");
|
||||
|
||||
FamilyInstance inPlace = null;
|
||||
AnalyticalModel model = null;
|
||||
|
||||
AnalyticalElement model = null;
|
||||
|
||||
try
|
||||
{
|
||||
transaction.Start();
|
||||
@@ -97,44 +100,55 @@ namespace Revit.SDK.Samples.InPlaceMembers.CS
|
||||
transaction.Commit();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Search for the In-Place family instance's properties data to be listed
|
||||
/// and graphics data to be drawn.
|
||||
/// </summary>
|
||||
/// <param name="inPlaceMember">properties data to be listed</param>
|
||||
/// <param name="model">graphics data to be draw</param>
|
||||
/// <returns>Returns true if retrieved this data</returns>
|
||||
private bool PrepareData(ref FamilyInstance inPlaceMember, ref AnalyticalElement model)
|
||||
{
|
||||
ElementSet selected = new ElementSet();
|
||||
foreach (ElementId elementId in m_commandData.Application.ActiveUIDocument.Selection.GetElementIds())
|
||||
{
|
||||
selected.Insert(m_commandData.Application.ActiveUIDocument.Document.GetElement(elementId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Search for the In-Place family instance's properties data to be listed
|
||||
/// and graphics data to be drawn.
|
||||
/// </summary>
|
||||
/// <param name="inPlaceMember">properties data to be listed</param>
|
||||
/// <param name="model">graphics data to be draw</param>
|
||||
/// <returns>Returns true if retrieved this data</returns>
|
||||
private bool PrepareData(ref FamilyInstance inPlaceMember, ref AnalyticalModel model)
|
||||
{
|
||||
ElementSet selected = new ElementSet();
|
||||
foreach (ElementId elementId in m_commandData.Application.ActiveUIDocument.Selection.GetElementIds())
|
||||
if (selected.Size != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (object o in selected)
|
||||
{
|
||||
inPlaceMember = o as FamilyInstance;
|
||||
if (null == inPlaceMember)
|
||||
{
|
||||
selected.Insert(m_commandData.Application.ActiveUIDocument.Document.GetElement(elementId));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (selected.Size != 1)
|
||||
}
|
||||
Document document = inPlaceMember.Document;
|
||||
AnalyticalToPhysicalAssociationManager relManager = AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager(document);
|
||||
if (relManager != null)
|
||||
{
|
||||
ElementId associatedElementId = relManager.GetAssociatedElementId(inPlaceMember.Id);
|
||||
if (associatedElementId != ElementId.InvalidElementId)
|
||||
{
|
||||
return false;
|
||||
Element associatedElement = document.GetElement(associatedElementId);
|
||||
if (associatedElement != null && associatedElement is AnalyticalElement)
|
||||
{
|
||||
model = associatedElement as AnalyticalElement;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (object o in selected)
|
||||
{
|
||||
inPlaceMember = o as FamilyInstance;
|
||||
if (null == inPlaceMember)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (null == model)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
model = inPlaceMember.GetAnalyticalModel();
|
||||
|
||||
if (null==model)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
|
||||
using Autodesk.Revit.DB.Structure;
|
||||
using Autodesk.Revit.DB;
|
||||
@@ -38,43 +39,51 @@ namespace Revit.SDK.Samples.InPlaceMembers.CS
|
||||
/// </summary>
|
||||
public class GraphicsDataFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// create GraphicsData of given AnalyticalModel3D
|
||||
/// </summary>
|
||||
/// <param name="model">AnalyticalModel3D contains geometry data</param>
|
||||
/// <returns></returns>
|
||||
public static GraphicsData CreateGraphicsData(AnalyticalModel model)
|
||||
{
|
||||
IList<Curve> curveList = model.GetCurves(AnalyticalCurveType.ActiveCurves);
|
||||
/// <summary>
|
||||
/// create GraphicsData of given AnalyticalModel3D
|
||||
/// </summary>
|
||||
/// <param name="model">AnalyticalModel3D contains geometry data</param>
|
||||
/// <returns></returns>
|
||||
public static GraphicsData CreateGraphicsData(AnalyticalElement model)
|
||||
{
|
||||
IList<Curve> curveList = new List<Curve>();
|
||||
if (model is AnalyticalMember)
|
||||
{
|
||||
curveList.Add(model.GetCurve());
|
||||
}
|
||||
else if (model is AnalyticalPanel)
|
||||
{
|
||||
curveList = (model as AnalyticalPanel).GetOuterContour().ToList();
|
||||
}
|
||||
|
||||
if (curveList.Count > 0)
|
||||
{
|
||||
GraphicsData data = new GraphicsData();
|
||||
|
||||
if (curveList.Count > 0)
|
||||
IEnumerator<Curve> curves = curveList.GetEnumerator();
|
||||
curves.Reset();
|
||||
while (curves.MoveNext())
|
||||
{
|
||||
GraphicsData data = new GraphicsData();
|
||||
Curve curve = curves.Current as Curve;
|
||||
|
||||
IEnumerator<Curve> curves = curveList.GetEnumerator();
|
||||
curves.Reset();
|
||||
while (curves.MoveNext())
|
||||
{
|
||||
Curve curve = curves.Current as Curve;
|
||||
|
||||
try
|
||||
{
|
||||
List<XYZ> points = curve.Tessellate() as List<XYZ>;
|
||||
data.InsertCurve(points);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
data.UpdataData();
|
||||
|
||||
return data;
|
||||
try
|
||||
{
|
||||
List<XYZ> points = curve.Tessellate() as List<XYZ>;
|
||||
data.InsertCurve(points);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Can't get curves.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data.UpdataData();
|
||||
|
||||
return data;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Can't get curves.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodeAnalysisRuleSet />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
@@ -39,7 +38,6 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<CodeAnalysisRuleSet />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -48,8 +46,7 @@
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>
|
||||
</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
@@ -59,8 +56,7 @@
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>
|
||||
</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
|
||||
|
||||
Reference in New Issue
Block a user