建筑外围尺寸标注

This commit is contained in:
GG Z
2021-12-15 18:02:27 +08:00
parent 0599f61301
commit d0391ab843
10 changed files with 847 additions and 51 deletions

View File

@@ -9,6 +9,8 @@ Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "RookieStationSetup", "Rooki
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddinDeployer", "AddinDeployer\AddinDeployer.csproj", "{C60B068A-90A8-4852-B6DC-28A2D3FF2753}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestTools", "TestTools\TestTools.csproj", "{1CCEEB54-FD53-4812-8C2D-3489E7883F86}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -39,6 +41,14 @@ Global
{C60B068A-90A8-4852-B6DC-28A2D3FF2753}.Release|Any CPU.Build.0 = Release|Any CPU
{C60B068A-90A8-4852-B6DC-28A2D3FF2753}.Release|x64.ActiveCfg = Release|x64
{C60B068A-90A8-4852-B6DC-28A2D3FF2753}.Release|x64.Build.0 = Release|x64
{1CCEEB54-FD53-4812-8C2D-3489E7883F86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1CCEEB54-FD53-4812-8C2D-3489E7883F86}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1CCEEB54-FD53-4812-8C2D-3489E7883F86}.Debug|x64.ActiveCfg = Debug|Any CPU
{1CCEEB54-FD53-4812-8C2D-3489E7883F86}.Debug|x64.Build.0 = Debug|Any CPU
{1CCEEB54-FD53-4812-8C2D-3489E7883F86}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1CCEEB54-FD53-4812-8C2D-3489E7883F86}.Release|Any CPU.Build.0 = Release|Any CPU
{1CCEEB54-FD53-4812-8C2D-3489E7883F86}.Release|x64.ActiveCfg = Release|Any CPU
{1CCEEB54-FD53-4812-8C2D-3489E7883F86}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -28,7 +28,8 @@ namespace RookieStation.Drawing.ExecuteCmd
doc.InvokeGroup(tg =>
{
Room room = default;
var wallsToDim = new List<Wall>();
var singleWallsToDim = new List<Wall>();
Dictionary<BoundarySegment, Element> dics = new Dictionary<BoundarySegment, Element>();
doc.Invoke(ts =>
{
room = CreateOuterRoom(doc.ActiveView, out modelCurveArray);
@@ -44,16 +45,20 @@ namespace RookieStation.Drawing.ExecuteCmd
IList<BoundarySegment> edges = new List<BoundarySegment>();
var boundingseg = room.GetBoundarySegments(options);
edges = boundingseg.LastOrDefault();//需要去重
edges = boundingseg.LastOrDefault();
foreach (BoundarySegment segment in edges)
{
var curve = segment.GetCurve() as Line;
if (curve != null)
{
var wall = doc.GetElement(segment.ElementId) as Wall;
if (wall != null)
var b = singleWallsToDim.Where(w => w.Id == wall.Id);//去重
if (wall != null && b.Count() == 0)
{
wallsToDim.Add(wall);
var l = wall.Location as LocationCurve;
singleWallsToDim.Add(wall);
dics.Add(segment, wall);
}
}
}
@@ -68,16 +73,34 @@ namespace RookieStation.Drawing.ExecuteCmd
doc.Invoke(ts =>
{
CreateWallDimension(doc, wallsToDim);
});
//doc.Invoke(ts =>
//{
// doc.Delete(room.Id);
// foreach (ModelCurve curve in modelCurveArray)
// {
// doc.Delete(curve.Id);
// }
//});
List<Element> wallList = GetWallListToDim(doc);
foreach (var outerwall in singleWallsToDim)
{
wallList.Remove(outerwall);
}
CreateInnterWallDimension(doc, wallList);
CreateOuterWallsDimByReferLines(doc, dics);
}, "创建墙尺寸标注");
doc.Invoke(ts =>
{
CreateColumnsDimension(doc);
CreateBeamsDimension(doc);
}, "创建梁和柱标注");
doc.Invoke(ts =>
{
doc.Delete(room.Id);
foreach (ModelCurve curve in modelCurveArray)
{
doc.Delete(curve.Id);
}
}, "删除临时房间");
doc.Invoke(ts =>
{
var visableCol = doc.QueryByView(doc.ActiveView).ToElements();
CreateDoorWinTags(doc, visableCol);
CreateLightAnnotations(doc, visableCol);
CreateShelvesAnnotations(doc, visableCol);
}, "创建标注");
});
return Result.Succeeded;
@@ -139,9 +162,10 @@ namespace RookieStation.Drawing.ExecuteCmd
if (wallList.Count > 0)
{
List<Wall> tempWallList = new List<Wall>();
double distance = 5;
double distance = 1000 / 304.8;
List<Curve> curveList = wallList.Select(p => RsRevitUtils.GetLocationCurveByElement(p)).ToList();
List<XYZ> xyzList = curveList.Select(p => p.GetEndPoint(0)).ToList();
xyzList.AddRange(curveList.Select(p => p.GetEndPoint(1)).ToList());
double xMax = xyzList.Max(p => p.X) + distance;
double xMin = xyzList.Min(p => p.X) - distance;
@@ -208,6 +232,11 @@ namespace RookieStation.Drawing.ExecuteCmd
}
}
/// <summary>
/// 得到要标注的所有墙体
/// </summary>
/// <param name="doc"></param>
/// <returns></returns>
public List<Element> GetWallListToDim(Document doc)
{
var wallList = doc.QueryByView<Wall>(doc.ActiveView).Where(w =>
@@ -221,15 +250,17 @@ namespace RookieStation.Drawing.ExecuteCmd
return wallList.ToList();
}
private static void CreateWallDimension(Document doc, List<Wall> wallList)
private static void CreateInnterWallDimension(Document doc, List<Element> wallList)
{
foreach (Wall wall in wallList)
{
if (wall.Id.IntegerValue == 1949460)
{
}
ReferenceArray wallLengthRefernceArray = new ReferenceArray();
List<Face> faces = new List<Face>();
//List<Face> faces = RsRevitUtils.GetSideFacesByElement(wall);
List<Face> faces = RsRevitUtils.GetSideFacesByElement(wall);
List<ElementId> ids = FindWallIdsConnected(doc, wall);
//var edgearrarray = RsRevitUtils.GetBottomEdgeArrayArray(wall);
foreach (var id in ids)
{
@@ -244,9 +275,12 @@ namespace RookieStation.Drawing.ExecuteCmd
{
continue;
}
if (pf.FaceNormal.CrossProduct(wall.Orientation).IsAlmostEqualTo(XYZ.Zero))
{
//if (doc.GetElement(face.Reference).Id == wall.Id)
//{
// wallThickReferenceArray.Append(face.Reference);//墙厚标注
//}
}
else if (pf.FaceNormal.DotProduct(wall.Orientation) < 0.001)
{
@@ -261,14 +295,13 @@ namespace RookieStation.Drawing.ExecuteCmd
var scale = doc.ActiveView.Scale;
var tranform = Transform.CreateTranslation(wall.Orientation * scale * 15 / 304.8);
var wallcurve = RsRevitUtils.GetLocationCurveByElement(wall) as Line;
Line lengthDimLine = wallcurve.CreateTransformed(tranform) as Line;
//Dimension lengthdim = null;
Dimension lengthdim = doc.Create.NewDimension(doc.ActiveView, lengthDimLine, wallLengthRefernceArray);
Line lengthLine = wallcurve.CreateTransformed(tranform) as Line;
var lengthdim = doc.Create.NewDimension(doc.ActiveView, lengthLine, wallLengthRefernceArray);
doc.Regenerate();
ReferenceArray finallengthreferenceArray = RemoveZeroReferences(wall, wallLengthRefernceArray, lengthdim);
ReferenceArray finallengthreferenceArray = RemoveZeroSegments(lengthdim);
doc.Delete(lengthdim.Id);
lengthdim = doc.Create.NewDimension(doc.ActiveView, lengthDimLine, finallengthreferenceArray);
doc.Create.NewDimension(doc.ActiveView, lengthLine, finallengthreferenceArray);
if (lengthdim.Segments.Size > 2)
{
@@ -278,9 +311,9 @@ namespace RookieStation.Drawing.ExecuteCmd
referenceArray.Append(refer1);
referenceArray.Append(refer2);
var tranform1 = Transform.CreateTranslation(wall.Orientation * scale * 25 / 304.8);
Line lengthTotalDimLine = wallcurve.CreateTransformed(tranform1) as Line;
Line lengthLine1 = wallcurve.CreateTransformed(tranform1) as Line;
doc.Create.NewDimension(doc.ActiveView, lengthTotalDimLine, referenceArray);
doc.Create.NewDimension(doc.ActiveView, lengthLine1, referenceArray);
}
}
catch (Exception)
@@ -290,29 +323,542 @@ namespace RookieStation.Drawing.ExecuteCmd
}
}
private static ReferenceArray RemoveZeroReferences(Wall wall, ReferenceArray wallLengthRefernceArray, Dimension lengthdim)
private static void CreateOuterWallsDimByReferLines(Document doc, Dictionary<BoundarySegment, Element> dics)
{
List<Reference> referencesdelete = new List<Reference>();
var finallengthreferenceArray = new ReferenceArray();
for (int i = 0; i < lengthdim.NumberOfSegments; i++)
for (int i = 0; i < dics.Values.Count; i++)
{
if (lengthdim.Segments.get_Item(i).ValueString == "0")
Wall wall = dics.Values.ElementAt(i) as Wall;
ReferenceArray wallRefernceArray = new ReferenceArray();
List<ElementId> ids = FindWallIdsConnected(doc, wall);
//var edgearrarray = RsRevitUtils.GetBottomEdgeArrayArray(wall);
Line boundaryLine = dics.Keys.ElementAt(i).GetCurve() as Line;
if (boundaryLine == null)
{
if (lengthdim.References.get_Item(i).ElementId == wall.Id)
continue;
}
//Line boundaryLine = Line.CreateBound(curve.GetEndPoint(0), curve.GetEndPoint(1));//直线方向
XYZ offestVector = XYZ.BasisZ.CrossProduct(boundaryLine.Direction).Normalize();
Options options = new Options()
{
ComputeReferences = true,
DetailLevel = ViewDetailLevel.Fine
};
List<Face> faces = new List<Face>();
List<Face> mainWallFaces = RsRevitUtils.GetSideFacesByElement(wall);
faces.AddRange(mainWallFaces);
//相交、相连墙体
List<Face> intersectWallFaces = new List<Face>();
foreach (var id in ids)
{
Element ele = doc.GetElement(id);
intersectWallFaces.AddRange(RsRevitUtils.GetSideFacesByElement(ele));
faces.AddRange(RsRevitUtils.GetSideFacesByElement(ele));
}
foreach (Face face in faces)
{
PlanarFace planarFace = face as PlanarFace;
if (planarFace.FaceNormal.IsAlmostEqualTo(offestVector))
{
referencesdelete.Add(lengthdim.References.get_Item(i));
EdgeArrayArray edgeLoops = face.EdgeLoops;
foreach (EdgeArray edgeLoop in edgeLoops)
{
foreach (Edge edge in edgeLoop)
{
Line line = edge.AsCurve() as Line;
if (line != null && line.Direction.IsAlmostEqualTo(XYZ.BasisZ) || line.Direction.IsAlmostEqualTo(-XYZ.BasisZ))//垂直线
{
wallRefernceArray.Append(edge.Reference);
}
}
}
}
if (lengthdim.References.get_Item(i + 1).ElementId == wall.Id)
}
try
{
var scale = doc.ActiveView.Scale;
var tranform = Transform.CreateTranslation(offestVector * scale * 15 / 304.8);
var wallcurve = RsRevitUtils.GetLocationCurveByElement(wall) as Line;
Line lengthDimLine = wallcurve.CreateTransformed(tranform) as Line;
Dimension templengthdim = doc.Create.NewDimension(doc.ActiveView, lengthDimLine, wallRefernceArray);
//doc.Regenerate();
ReferenceArray finallengthreferenceArray = RemoveZeroSegments(templengthdim);
//finallengthreferenceArray.Append(templengthdim.References.get_Item(templengthdim.References.Size - 1));
//ReferenceArray finallengthreferenceArray = RemoveZeroSegments(wall, templengthdim);
doc.Delete(templengthdim.Id);
var finallengthdim = doc.Create.NewDimension(doc.ActiveView, lengthDimLine, finallengthreferenceArray);
if (finallengthdim.Segments.Size >= 2)
{
referencesdelete.Add(lengthdim.References.get_Item(i + 1));
ReferenceArray referenceArray = new ReferenceArray();
var refer1 = finallengthdim.References.get_Item(0);
var refer2 = finallengthdim.References.get_Item(finallengthdim.References.Size - 1);
referenceArray.Append(refer1);
referenceArray.Append(refer2);
var tranform1 = Transform.CreateTranslation(offestVector * scale * 20 / 304.8);
Line lengthTotalDimLine = wallcurve.CreateTransformed(tranform1) as Line;
doc.Create.NewDimension(doc.ActiveView, lengthTotalDimLine, referenceArray);
}
}
catch (Exception ex)
{
continue;
}
}
}
public void CreateColumnsDimension(Document doc)
{
var col = new FilteredElementCollector(doc, doc.ActiveView.Id);
ElementCategoryFilter categoryFilter1 = new ElementCategoryFilter(BuiltInCategory.OST_StructuralColumns);
ElementCategoryFilter categoryFilter2 = new ElementCategoryFilter(BuiltInCategory.OST_Columns);
LogicalOrFilter andFilter = new LogicalOrFilter(categoryFilter1, categoryFilter2);
col.WherePasses(andFilter);
var columns = col.GroupBy(g => g.Name).Select(s => s.FirstOrDefault());
foreach (FamilyInstance familyInstance in columns)
{
var loc = RsRevitUtils.GetLocationPointByElement(familyInstance);
var faces = RsRevitUtils.GetSideFacesByElement(familyInstance);
if (faces.Count == 0)//找不到实例的几何元素时,需从类型集合查找
{
Options options = new Options
{
ComputeReferences = true
};
faces = RsRevitUtils.GetFacesByFamilyInstance(familyInstance, options);
for (int i = faces.Count - 1; i >= 0; i--)
{
PlanarFace pf = faces[i] as PlanarFace;
if (pf.FaceNormal.CrossProduct(XYZ.BasisZ).IsAlmostEqualTo(XYZ.Zero))
{
faces.Remove(faces[i]);//移除顶面底面
}
}
}
var referenceArray = new ReferenceArray();
var referenceArrayArray = new ReferenceArrayArray();
GetParallFacesReferenceArray(faces, faces.FirstOrDefault(), referenceArray, referenceArrayArray);
foreach (ReferenceArray array in referenceArrayArray)
{
if (array.Size == 0)
{
continue;
}
var face = familyInstance.GetGeometryObjectFromReference(array.get_Item(0)) as PlanarFace;
var line = Line.CreateUnbound(loc, face.FaceNormal).CreateOffset(600 / 304.8, XYZ.BasisZ) as Line;
doc.Create.NewDimension(doc.ActiveView, line, array);
}
}
}
public void CreateBeamsDimension(Document doc)
{
var col = new FilteredElementCollector(doc, doc.ActiveView.Id);
ElementCategoryFilter categoryFilter1 = new ElementCategoryFilter(BuiltInCategory.OST_StructuralFraming);
col.WherePasses(categoryFilter1);
var beams = col.GroupBy(g => g.Name).Select(s => s.FirstOrDefault());
foreach (FamilyInstance familyInstance in beams)
{
var loc = RsRevitUtils.GetLocationPointByElement(familyInstance);
var faces = RsRevitUtils.GetSideFacesByElement(familyInstance);
if (faces.Count == 0)//找不到实例的几何元素时,需从类型集合查找
{
Options options = new Options
{
ComputeReferences = true
};
faces = RsRevitUtils.GetFacesByFamilyInstance(familyInstance, options);
for (int i = faces.Count - 1; i >= 0; i--)
{
PlanarFace pf = faces[i] as PlanarFace;
if (pf.FaceNormal.CrossProduct(XYZ.BasisZ).IsAlmostEqualTo(XYZ.Zero))
{
faces.Remove(faces[i]);//移除顶面底面
}
}
}
var referenceArray = new ReferenceArray();
var referenceArrayArray = new ReferenceArrayArray();
GetParallFacesReferenceArray(faces, faces.FirstOrDefault(), referenceArray, referenceArrayArray);
foreach (ReferenceArray array in referenceArrayArray)
{
var face = familyInstance.GetGeometryObjectFromReference(array.get_Item(0)) as PlanarFace;
var line = Line.CreateUnbound(loc, face.FaceNormal).CreateOffset(600 / 304.8, XYZ.BasisZ) as Line;
doc.Create.NewDimension(doc.ActiveView, line, array);
}
}
}
private void CreateDoorWinTags(Document doc, IList<Element> visableCol)
{
foreach (Element ele in visableCol)
{
var cate = ele.Category;
var loc = RsRevitUtils.GetLocationPointByElement(ele);
var d = ele as FamilyInstance;
if (loc != null && cate != null)
{
if (cate.Id.IntegerValue == -2000023 || cate.Id.IntegerValue == -2000014)
{
IndependentTag independentTag = IndependentTag.Create(doc, doc.ActiveView.Id, new Reference(ele), false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, loc);
//ElementTransformUtils.RotateElement(doc, independentTag.Id, rotateaxis, d.HandOrientation.AngleTo(XYZ.BasisY));
double substract = d.HandOrientation.AngleTo(XYZ.BasisX) - Math.PI / 2;
if (substract > -0.001 && substract < 0.001)
{
independentTag.TagOrientation = TagOrientation.Vertical;
}
}
}
}
for (int i = 0; i < wallLengthRefernceArray.Size; i++)
}
private void CreateLightAnnotations(Document doc, IList<Element> visableCol)
{
List<Element> lights;
CreateLightTags(doc, visableCol, out lights);
CreateLightXDimensions(doc, lights);
CreateLightYDimensions(doc, lights);
}
private bool CreateLightTags(Document doc, IList<Element> visableCol, out List<Element> lights)
{
lights = new List<Element>();
foreach (var light in visableCol)
{
var lightcategory = light.Category;
var loc = RsRevitUtils.GetLocationPointByElement(light);
if (loc != null)
{
loc -= new XYZ(-200 / 304.8, 200 / 304.8, 0);
}
if (loc != null && lightcategory != null && lightcategory.Id.IntegerValue == -2001120)
{
IndependentTag.Create(doc, doc.ActiveView.Id, new Reference(light), false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, loc);
lights.Add(light);
}
}
return true;
}
private void CreateLightXDimensions(Document doc, List<Element> lights)
{
var lightDistincts = lights
.OrderBy(o => RsRevitUtils.GetLocationPointByElement(o).X)
.ThenBy(o => RsRevitUtils.GetLocationPointByElement(o).Y)
.GroupBy(l => Math.Round(RsRevitUtils.GetLocationPointByElement(l).X, 4))
.Select(g => g.First())
.ToList();
var group = lightDistincts.GroupBy(g => g.Name);//按族类型名称分组
List<ReferenceArray> referenceArrays = new List<ReferenceArray>();
List<Line> lines = new List<Line>();
foreach (var g in group)
{
ReferenceArray referenceArray = new ReferenceArray();
Line line = Line.CreateUnbound(RsRevitUtils.GetLocationPointByElement(g.FirstOrDefault()), XYZ.BasisX);
foreach (FamilyInstance ele in g)
{
if (ele != null)
{
referenceArray.Append(ele.GetReferences(FamilyInstanceReferenceType.CenterLeftRight).FirstOrDefault());
}
}
lines.Add(line);
referenceArrays.Add(referenceArray);
}
for (int i = 0; i < referenceArrays.Count; i++)
{
ReferenceArray referenceArray = referenceArrays[i];
Line line = lines[i];
try
{
doc.Create.NewDimension(doc.ActiveView, line, referenceArray);
}
catch (Exception)
{
continue;
}
}
}
private void CreateLightYDimensions(Document doc, List<Element> lights)
{
var lightDistincts = lights
.OrderBy(o => RsRevitUtils.GetLocationPointByElement(o).Y)
.ThenBy(o => RsRevitUtils.GetLocationPointByElement(o).X)
.GroupBy(l => Math.Round(RsRevitUtils.GetLocationPointByElement(l).Y, 4))
.Select(g => g.First())
.ToList();
var group = lightDistincts.GroupBy(g => g.Name);
List<ReferenceArray> referenceArrays = new List<ReferenceArray>();
List<Line> lines = new List<Line>();
foreach (var g in group)
{
ReferenceArray referenceArray = new ReferenceArray();
Line line = Line.CreateUnbound(RsRevitUtils.GetLocationPointByElement(g.FirstOrDefault()), XYZ.BasisY);
foreach (FamilyInstance ele in g)
{
if (ele != null)
{
referenceArray.Append(ele.GetReferences(FamilyInstanceReferenceType.CenterFrontBack).FirstOrDefault());
}
}
lines.Add(line);
referenceArrays.Add(referenceArray);
}
for (int i = 0; i < referenceArrays.Count; i++)
{
ReferenceArray referenceArray = referenceArrays[i];
Line line = lines[i];
try
{
doc.Create.NewDimension(doc.ActiveView, line, referenceArray);
}
catch (Exception)
{
continue;
}
}
}
private static void CreateShelvesAnnotations(Document doc, IList<Element> visableCol)
{
var shelves = new List<Element>();
foreach (var ele in visableCol)
{
var instance = ele as FamilyInstance;
if (instance != null && instance.Symbol.FamilyName.Contains("货架"))
{
shelves.Add(instance);
}
}
CreateShelvesXDimensions(doc, shelves);
CreateShelvesYDimensions(doc, shelves);
}
private static bool CreateShelvesYDimensions(Document doc, List<Element> shelves)
{
var shelfDistincts = shelves
.OrderBy(o => RsRevitUtils.GetLocationPointByElement(o).Y)
.ThenBy(o => RsRevitUtils.GetLocationPointByElement(o).X)
.GroupBy(l => Math.Round(RsRevitUtils.GetLocationPointByElement(l).Y, 4))
.Select(g => g.First() as FamilyInstance)
.ToList();
Func<FamilyInstance, object> p = g =>
{
if (g.Room != null)
{
return g.Room;
}
else
{
return g.Name;
}
};
var group = shelfDistincts.GroupBy(p);
List<ReferenceArray> referenceArrays = new List<ReferenceArray>();
List<Line> lines = new List<Line>();
foreach (var g in group)
{
ReferenceArray referenceArray = new ReferenceArray();
Line line = Line.CreateUnbound(RsRevitUtils.GetLocationPointByElement(g.FirstOrDefault()), XYZ.BasisY);
for (int i = 0; i < g.Count(); i++)
{
FamilyInstance ele = g.ElementAt(i);
if (ele == null)
{
continue;
}
if (ele.FacingOrientation.CrossProduct(XYZ.BasisX).IsAlmostEqualTo(XYZ.Zero))
{
//referenceArray.Append(ele.GetReferences(FamilyInstanceReferenceType.Left).FirstOrDefault());
referenceArray.Append(ele.GetReferences(FamilyInstanceReferenceType.Right).FirstOrDefault());
}
else
{
//if (i < g.Count() - 1)//通道标注
//{
// if (ele.Symbol.GetParameters("长度").FirstOrDefault().AsDouble() < RsRevitUtils.GetLocationPointByElement(g.ElementAt(i + 1)).DistanceTo(RsRevitUtils.GetLocationPointByElement(g.ElementAt(i))))
// {
// referenceArray.Append(ele.GetReferences(FamilyInstanceReferenceType.Back).FirstOrDefault());
// }
//}
referenceArray.Append(ele.GetReferences(FamilyInstanceReferenceType.Front).FirstOrDefault());
//referenceArray.Append(ele.GetReferences(FamilyInstanceReferenceType.Back).FirstOrDefault());
}
}
lines.Add(line);
referenceArrays.Add(referenceArray);
}
for (int i = 0; i < referenceArrays.Count; i++)
{
ReferenceArray referenceArray = referenceArrays[i];
Line line = lines[i];
try
{
doc.Create.NewDimension(doc.ActiveView, line, referenceArray);
}
catch (Exception)
{
continue;
}
}
return true;
}
private static bool CreateShelvesXDimensions(Document doc, List<Element> shelves)
{
var shelfDistincts = shelves
.OrderBy(o => RsRevitUtils.GetLocationPointByElement(o).X)
.ThenBy(o => RsRevitUtils.GetLocationPointByElement(o).Y)
.GroupBy(l => Math.Round(RsRevitUtils.GetLocationPointByElement(l).X, 4))
.Select(g => g.First() as FamilyInstance)
.ToList();
Func<FamilyInstance, object> p = g =>
{
if (g.Room != null)
{
return g.Room;
}
else
{
return g.Name;
}
};
var group = shelfDistincts.GroupBy(p);
List<ReferenceArray> referenceArrays = new List<ReferenceArray>();
List<Line> lines = new List<Line>();
foreach (var g in group)
{
ReferenceArray referenceArray = new ReferenceArray();
Line line = Line.CreateUnbound(RsRevitUtils.GetLocationPointByElement(g.FirstOrDefault()), XYZ.BasisX);
for (int i = 0; i < g.Count(); i++)
{
FamilyInstance ele = g.ElementAt(i);
if (ele == null)
{
continue;
}
if (ele.FacingOrientation.CrossProduct(XYZ.BasisX).IsAlmostEqualTo(XYZ.Zero))
{
//if (i > 0)//通道标注
//{
// if (ele.Symbol.GetParameters("长度").FirstOrDefault().AsDouble() < RsRevitUtils.GetLocationPointByElement(g.ElementAt(i - 1)).DistanceTo(RsRevitUtils.GetLocationPointByElement(g.ElementAt(i))))
// {
// referenceArray.Append(ele.GetReferences(FamilyInstanceReferenceType.Back).FirstOrDefault());
// }
//}
//referenceArray.Append(ele.GetReferences(FamilyInstanceReferenceType.Back).FirstOrDefault());
referenceArray.Append(ele.GetReferences(FamilyInstanceReferenceType.Front).FirstOrDefault());
}
else
{
//referenceArray.Append(ele.GetReferences(FamilyInstanceReferenceType.Left).FirstOrDefault());
referenceArray.Append(ele.GetReferences(FamilyInstanceReferenceType.Right).FirstOrDefault());
}
}
lines.Add(line);
referenceArrays.Add(referenceArray);
}
for (int i = 0; i < referenceArrays.Count; i++)
{
ReferenceArray referenceArray = referenceArrays[i];
Line line = lines[i];
try
{
doc.Create.NewDimension(doc.ActiveView, line, referenceArray);
}
catch (Exception)
{
continue;
}
}
return true;
}
public void GetParallFacesReferenceArray(List<Face> faces, Face firstFace, ReferenceArray referenceArray, ReferenceArrayArray referenceArrayArray)
{
if (referenceArrayArray.Size == 0)
{
referenceArrayArray.Append(referenceArray);
}
for (int i = 0; i < faces.Count; i++)
{
PlanarFace tempFace = faces[i] as PlanarFace;
var pf = firstFace as PlanarFace;
var facenormal = pf.FaceNormal;
//把初始的第一个添加进集合
if (tempFace.FaceNormal.CrossProduct(facenormal).IsAlmostEqualTo(XYZ.Zero))
{
referenceArray.Append(tempFace.Reference);
faces.Remove(tempFace);
GetParallFacesReferenceArray(faces, tempFace, referenceArray, referenceArrayArray);
}
if (i == faces.Count() - 1)
{
referenceArray = new ReferenceArray();
GetParallFacesReferenceArray(faces, faces.FirstOrDefault(), referenceArray, referenceArrayArray);
if (faces.Count() == 0)
{
referenceArrayArray.Append(referenceArray);
}
}
}
}
private static ReferenceArray RemoveZeroSegments(Dimension lengthdim)
{
Document doc = lengthdim.Document;
View view = lengthdim.View;
var finalreferenceArray = new ReferenceArray();
var deleteReferenceArray = new ReferenceArray();
for (int i = 0; i < lengthdim.References.Size; i++)
{
var reference1 = lengthdim.References.get_Item(i);
for (int j = i + 1; j < lengthdim.References.Size; j++)
{
var reference2 = lengthdim.References.get_Item(j);
ReferenceArray referenceArray = new ReferenceArray();
Line line = lengthdim.Curve as Line;
referenceArray.Append(reference1);
referenceArray.Append(reference2);
Dimension dimension = doc.Create.NewDimension(view, line, referenceArray);
if (dimension.ValueString == "0")
{
deleteReferenceArray.Append(reference2);
}
doc.Delete(dimension.Id);
}
//doc.Regenerate();
}
for (int i = 0; i < lengthdim.References.Size; i++)
{
bool isContain = false;
var reference = wallLengthRefernceArray.get_Item(i);
foreach (var referdelete in referencesdelete)
var reference = lengthdim.References.get_Item(i);
foreach (Reference referdelete in deleteReferenceArray)
{
if (reference.EqualTo(referdelete))
{
@@ -321,11 +867,10 @@ namespace RookieStation.Drawing.ExecuteCmd
}
if (!isContain)
{
finallengthreferenceArray.Append(reference);
finalreferenceArray.Append(reference);
}
}
return finallengthreferenceArray;
return finalreferenceArray;
}
private static List<ElementId> FindWallIdsConnected(Document doc, Wall w)

View File

@@ -12,6 +12,7 @@ using Autodesk.Revit.DB.Architecture;
namespace RookieStation.Drawing.ExecuteCmd
{
[Obsolete]
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
internal class CreateViewPlanAnnotation : IExternalCommand
@@ -657,9 +658,8 @@ namespace RookieStation.Drawing.ExecuteCmd
//{
// continue;
//}
//ReferenceArray wallThickReferenceArray = new ReferenceArray();
ReferenceArray wallThickReferenceArray = new ReferenceArray();
ReferenceArray wallLengthRefernceArray = new ReferenceArray();
ReferenceArray ColumnLengthRefernceArray = new ReferenceArray();
List<Face> faces = RsRevitUtils.GetSideFacesByElement(wall);
List<ElementId> ids = FindWallIdsConnected(doc, wall);
@@ -679,10 +679,10 @@ namespace RookieStation.Drawing.ExecuteCmd
if (pf.FaceNormal.CrossProduct(wall.Orientation).IsAlmostEqualTo(XYZ.Zero))
{
//if (doc.GetElement(face.Reference).Id == wall.Id)
//{
// wallThickReferenceArray.Append(face.Reference);//墙厚标注
//}
if (doc.GetElement(face.Reference).Id == wall.Id)
{
wallThickReferenceArray.Append(face.Reference);//墙厚标注
}
}
else if (pf.FaceNormal.DotProduct(wall.Orientation) < 0.001)
{
@@ -706,7 +706,7 @@ namespace RookieStation.Drawing.ExecuteCmd
doc.Create.NewDimension(doc.ActiveView, lengthLine, finallengthreferenceArray);
Line thickLine = Line.CreateUnbound(wallcurve.Evaluate(0.2, true), wall.Orientation);
//var thickdim = doc.Create.NewDimension(doc.ActiveView, thickLine, wallThickReferenceArray);
var thickdim = doc.Create.NewDimension(doc.ActiveView, thickLine, wallThickReferenceArray);
if (lengthdim.Segments.Size > 2)
{

View File

@@ -227,7 +227,7 @@ namespace RookieStation.RibbonMenu
tspb.AddPushButton(ManualAlignPBD);
tspb.AddPushButton(autoAlignPBD);
NewPushButtonData<CreateViewPlanAnnotation>(drawingPanel, "平面标注", Properties.Resources.ViewPlanDim, ViewPlanCmdEnabled);
NewPushButtonData<CreatePalanarViewAnnotation>(drawingPanel, "平面标注", Properties.Resources.ViewPlanDim, ViewPlanCmdEnabled);
NewPushButtonData<CreateViewSectionAnnotation>(drawingPanel, "立面标注", Properties.Resources.ViewSectionDim, ViewSectionCmdEnabled);
NewPushButtonData<CreateWires>(drawingPanel, "创建导线", Properties.Resources.Wire, ViewPlanCmdEnabled);
var UnifyViewportPBD = NewPushButtonData<UnifyViewportOnViewSheet>(drawingPanel, "统一视口", Properties.Resources.UnifyViewport, ViewPlanCmdEnabled);

View File

@@ -31,7 +31,7 @@ namespace RookieStation.Utils
if (null != applicationData.ActiveUIDocument)
{
Autodesk.Revit.DB.View view = applicationData.ActiveUIDocument.Document.ActiveView;
if (view.ViewType == ViewType.FloorPlan && !applicationData.ActiveUIDocument.Document.IsFamilyDocument)
if (view.ViewType == ViewType.FloorPlan || view.ViewType == ViewType.CeilingPlan && !applicationData.ActiveUIDocument.Document.IsFamilyDocument)
{
return true;
}

12
TestTools/Class1.cs Normal file
View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestTools
{
public class Class1
{
}
}

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("TestTools")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TestTools")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("1cceeb54-fd53-4812-8c2d-3489e7883f86")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

119
TestTools/TestCmd.cs Normal file
View File

@@ -0,0 +1,119 @@
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestTools
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class TestCmd : Autodesk.Revit.UI.IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
Document doc = uidoc.Document;
DocumentSet docset = uiapp.Application.Documents;
Reference refer = uidoc.Selection.PickObject(ObjectType.Element, "请选择XXX");
Element e = uidoc.Document.GetElement(refer);
Options options = new Options()
{
ComputeReferences = true,
DetailLevel = ViewDetailLevel.Fine,
};
var eleIds = e.GetGeneratingElementIds(e.get_Geometry(options));
uidoc.Selection.SetElementIds(eleIds);
#region FilterExecute
//var walls = new FilteredElementCollector(doc).OfClass(typeof(Wall)).ToElements();
//using (Transaction trans = new Transaction(doc, "default"))
//{
// try
// {
// trans.Start();
// //Do Something.
// trans.Commit();
// }
// catch (Exception ex)
// {
// message = ex.Message;
// if (trans.GetStatus() == TransactionStatus.Started)
// {
// trans.RollBack();
// }
// return Result.Failed;
// }
//}
#endregion FilterExecute
#region RepeatExecute
//bool isCoutine = true;
//using (Transaction trans = new Transaction(doc, "default"))
//{
// try
// {
// while (isCoutine)
// {
// try
// {
// trans.Start();
// //do something.
// trans.Commit();
// }
// catch (Autodesk.Revit.Exceptions.OperationCanceledException ex)
// {
// trans.Commit();
// return Result.Succeeded;
// }
// }
// }
// catch (Exception ex)
// {
// message = ex.Message;
// if (trans.GetStatus() == TransactionStatus.Started)
// {
// trans.RollBack();
// }
// return Result.Failed;
// }
//}
#endregion RepeatExecute
#region SelectExecute
//using (Transaction trans = new Transaction(doc, "default"))
//{
// try
// {
// Reference refer = uidoc.Selection.PickObject(ObjectType.Element, "请选择XXX");
// Element e = uidoc.Document.GetElement(refer);
// trans.Start();
// trans.Commit();
// }
// catch (Autodesk.Revit.Exceptions.OperationCanceledException ex)
// {
// }
// catch (Exception ex)
// {
// }
//}
#endregion SelectExecute
return Result.Succeeded;
}
}
}

View File

@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{1CCEEB54-FD53-4812-8C2D-3489E7883F86}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TestTools</RootNamespace>
<AssemblyName>TestTools</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</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>
</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>
</PropertyGroup>
<ItemGroup>
<Reference Include="AdWindows, Version=2018.11.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Revit_API_x64.2020.0.0\lib\NET470\AdWindows.dll</HintPath>
</Reference>
<Reference Include="RevitAddInUtility, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Revit_API_x64.2020.0.0\lib\NET470\RevitAddInUtility.dll</HintPath>
</Reference>
<Reference Include="RevitAPI, Version=20.0.0.0, Culture=neutral, processorArchitecture=AMD64">
<HintPath>..\packages\Revit_API_x64.2020.0.0\lib\NET470\RevitAPI.dll</HintPath>
</Reference>
<Reference Include="RevitAPIUI, Version=20.0.0.0, Culture=neutral, processorArchitecture=AMD64">
<HintPath>..\packages\Revit_API_x64.2020.0.0\lib\NET470\RevitAPIUI.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="UIFramework, Version=20.0.0.0, Culture=neutral, processorArchitecture=AMD64">
<HintPath>..\packages\Revit_API_x64.2020.0.0\lib\NET470\UIFramework.dll</HintPath>
</Reference>
<Reference Include="UIFrameworkServices, Version=20.0.0.0, Culture=neutral, processorArchitecture=AMD64">
<HintPath>..\packages\Revit_API_x64.2020.0.0\lib\NET470\UIFrameworkServices.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestCmd.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Revit_API_x64" version="2020.0.0" targetFramework="net472" />
</packages>