Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
My PC authored and My PC committed Sep 30, 2023
2 parents 52ec36e + fb4437f commit be6487a
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 11 deletions.
6 changes: 5 additions & 1 deletion Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ private void CreateRibbon()
DimW.SetImage("/BimIshou;component/Resources/Icons/RibbonIcon16.png");
DimW.SetLargeImage("/BimIshou;component/Resources/Icons/RibbonIcon32.png");

var DimDoorAndWindow = panel.AddPushButton<AutoDimDoor>("Dim DoorAndWindow");
var DimDoorAndWindow = panel.AddPushButton<AutoDimDoor1>("Dim DoorAndWindow 1");
DimDoorAndWindow.SetImage("/BimIshou;component/Resources/Icons/RibbonIcon16.png");
DimDoorAndWindow.SetLargeImage("/BimIshou;component/Resources/Icons/RibbonIcon32.png");

var DimDoorAndWindow1 = panel.AddPushButton<AutoDimDoor2>("Dim DoorAndWindow 2");
DimDoorAndWindow1.SetImage("/BimIshou;component/Resources/Icons/RibbonIcon16.png");
DimDoorAndWindow1.SetLargeImage("/BimIshou;component/Resources/Icons/RibbonIcon32.png");

var DimTT = panel.AddPushButton<DimTT>("Dim 有効");
DimTT.SetImage("/BimIshou;component/Resources/Icons/RibbonIcon16.png");
DimTT.SetLargeImage("/BimIshou;component/Resources/Icons/RibbonIcon32.png");
Expand Down
122 changes: 122 additions & 0 deletions Commands/AutoDimDoor1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using BimIshou.Utils;
using Nice3point.Revit.Toolkit.External;
using System.Windows;

namespace BimIshou.Commands;

[Transaction(TransactionMode.Manual)]
internal class AutoDimDoor1 : ExternalCommand
{
public override void Execute()
{
ReferenceArray refss = new ReferenceArray();
List<BuiltInCategory> categories = new List<BuiltInCategory>() { BuiltInCategory.OST_Doors, BuiltInCategory.OST_Windows };
var filterWall = new SelectionFilter(BuiltInCategory.OST_Walls, true);
var filterDoorOrWindow = new SelectionFilter(categories, true);
try
{
var ele = UiDocument.Selection.PickObjects(ObjectType.Element, filterWall);
var doororWindow = UiDocument.Selection.PickObjects(ObjectType.Element, filterDoorOrWindow);
var p = UiDocument.Selection.PickPoint();
XYZ dir = null;
if (doororWindow.Count != 0)
{
foreach (Reference obj in doororWindow)
{
if (obj == null) break;
var familyinstance = Document.GetElement(obj) as FamilyInstance;
dir ??= familyinstance.FacingOrientation;
var left = familyinstance.GetReferenceByName("左") ?? familyinstance.GetReferences(FamilyInstanceReferenceType.Left).First();
var right = familyinstance.GetReferenceByName("右") ?? familyinstance.GetReferences(FamilyInstanceReferenceType.Right).First();
refss.Append(left);
refss.Append(right);
}
}
using (TransactionGroup tranG = new TransactionGroup(Document, "AutoDim"))
{
tranG.Start();
foreach (Reference obj in ele)
{
var wall = Document.GetElement(obj) as Wall;
Line line = (wall.Location as LocationCurve).Curve as Line;
dir ??= wall.Orientation;
if (doororWindow.Count != 0)
if (!line.Direction.IsParallel(dir)) continue;
using (Transaction tran = new Transaction(Document, "new Line"))
{
tran.Start();
var newLine = CreateModelLine.OnVerticalPlane(Document, Line.CreateBound(line.GetEndPoint(0), line.GetEndPoint(0).Add(line.Direction * 10)));
refss.Append(newLine.GeometryCurve.Reference);
tran.Commit();
}
}
Dimension dim;
using (Transaction tran = new Transaction(Document, "new tran"))
{
tran.Start();
dim = Document.Create.NewDimension(ActiveView, Line.CreateBound(p, p.Add(dir)), refss);
tran.Commit();
}
var ids = new List<ElementId>();
var refs = dim.References;
foreach (Reference item in refs)
{
var temp = Document.GetElement(item);
if (temp.Category.Id.IntegerValue == (int)BuiltInCategory.OST_CurtainWallMullions)
{
var hostId = (temp as Mullion).Host.Id;
if (!ids.Contains(hostId))
ids.Add(hostId);
}
if (temp.Category.Id.IntegerValue.Equals((int)BuiltInCategory.OST_Doors)
|| temp.Category.Id.IntegerValue.Equals((int)BuiltInCategory.OST_Windows))
{
if (!ids.Contains(temp.Id))
ids.Add(temp.Id);
}
}
foreach (ElementId id in ids)
{
XYZ pos;
ReferenceArray Aref = new();
foreach (Reference item in refs)
{
var temp = Document.GetElement(item);
if (temp.Category.Id.IntegerValue == (int)BuiltInCategory.OST_CurtainWallMullions)
{
var hostId = (temp as Mullion).Host.Id;
if (hostId.IntegerValue == id.IntegerValue)
Aref.Append(item);
}
if (temp.Id.IntegerValue == id.IntegerValue)
Aref.Append(item);
}
using (Transaction tran = new Transaction(Document, "Dim W"))
{
tran.Start();
pos = Document.Create.NewDimension(Document.ActiveView, dim.Curve as Line, Aref).TextPosition;
tran.RollBack();
}
using (Transaction tran = new Transaction(Document, "Dim W"))
{
tran.Start();
foreach (DimensionSegment item in dim.Segments)
{
if (item.TextPosition.IsAlmostEqualTo(pos, 0.00000001))
item.Prefix = "W";
}
tran.Commit();
}
}
tranG.Assimilate();
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
}
15 changes: 8 additions & 7 deletions Commands/AutoDimDoor.cs → Commands/AutoDimDoor2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace BimIshou.Commands;

[Transaction(TransactionMode.Manual)]
internal class AutoDimDoor : ExternalCommand
internal class AutoDimDoor2 : ExternalCommand
{
public override void Execute()
{
Expand All @@ -29,18 +29,21 @@ public override void Execute()
if (obj == null) break;
var familyinstance = Document.GetElement(obj) as FamilyInstance;
dir ??= familyinstance.FacingOrientation;
refss.Append(familyinstance.GetReferences(FamilyInstanceReferenceType.Left).First());
refss.Append(familyinstance.GetReferences(FamilyInstanceReferenceType.Right).First());
var left = familyinstance.GetReferenceByName("左") ?? familyinstance.GetReferences(FamilyInstanceReferenceType.Left).First();
var right = familyinstance.GetReferenceByName("右") ?? familyinstance.GetReferences(FamilyInstanceReferenceType.Right).First();
refss.Append(left);
refss.Append(right);
}
}
foreach (Reference obj in ele)
{
var wall = Document.GetElement(obj) as Wall;
Line line = (wall.Location as LocationCurve).Curve as Line;
dir ??= wall.Orientation;
if (doororWindow.Count != 0)
if (!line.Direction.IsParallel(dir)) continue;
string unique = wall.UniqueId;
var refString = string.Format("{0}:{1}:{2}", unique, -9999, 4);
var refString = string.Format("{0}:{1}:{2}", unique, -9999, 5);
Reference core_centre = Reference.ParseFromStableRepresentation(Document, refString);
refss.Append(core_centre);
}
Expand All @@ -51,7 +54,7 @@ public override void Execute()
using (Transaction tran = new Transaction(Document, "new tran"))
{
tran.Start();
dim = Document.Create.NewDimension(ActiveView, Line.CreateBound(p, p.Add(XYZ.BasisX * 100)), refss);
dim = Document.Create.NewDimension(ActiveView, Line.CreateBound(p, p.Add(dir)), refss);
tran.Commit();
}
var ids = new List<ElementId>();
Expand Down Expand Up @@ -100,9 +103,7 @@ public override void Execute()
foreach (DimensionSegment item in dim.Segments)
{
if (item.TextPosition.IsAlmostEqualTo(pos, 0.00000001))
{
item.Prefix = "W";
}
}
tran.Commit();
}
Expand Down
5 changes: 3 additions & 2 deletions Commands/DimW.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Nice3point.Revit.Toolkit.External;
using System.Windows;

namespace BimIshou.Commands
{
Expand Down Expand Up @@ -72,9 +73,9 @@ private void PostCommanDetailLine_OnPostableCommandModelLineEnded(object sender,
}
PostCommanAlignedDimension.OnPostableCommandModelLineEnded -= PostCommanDetailLine_OnPostableCommandModelLineEnded;
}
catch (Exception)
catch (Exception ee)
{
throw;
MessageBox.Show(ee.Message);
}
}
}
Expand Down
58 changes: 58 additions & 0 deletions Commands/test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Nice3point.Revit.Toolkit.External;
using System.Windows;

namespace BimIshou.Commands
{
[Transaction(TransactionMode.Manual)]
public class test : ExternalCommand
{
public override void Execute()
{
List<XYZ> points = new List<XYZ>();
List<TextNote> texts = new List<TextNote>();
List<Data> datas = new List<Data>();

List<ElementId> elementsIds = UiDocument.Selection.GetElementIds()?.ToList() ?? new List<ElementId>();
List<Element> selectedElements = elementsIds.Count > 0 ? elementsIds.Select(x => Document.GetElement(x)).ToList() : new List<Element>();

foreach (Element _line in selectedElements)
{
var line = _line as ModelLine;
if (line == null) continue;
XYZ p1 = line.GeometryCurve.GetEndPoint(0);
XYZ p2 = line.GeometryCurve.GetEndPoint(1);
if (!points.Exists(x => x.IsAlmostEqualTo(p1))) points.Add(p1);
if (!points.Exists(x => x.IsAlmostEqualTo(p2))) points.Add(p2);
}
foreach (Element _text in selectedElements)
{
var text = _text as TextNote;
if (text == null) continue;
texts.Add(text);
}
foreach (TextNote text in texts)
{
var value = text.Text.Split('+');
var loca = text.GetLeaders().First().End;
foreach (var p in points)
{
if (loca.DistanceTo(p) < 10)
{
datas.Add(new Data(text.Id.IntegerValue, loca, value[0], value[1]));
}
}
}
datas.OrderByDescending(x => x.id);
MessageBox.Show(datas[0].s1);
}
public record Data(int id, XYZ loca, string s1, string s2)
{
public int id { get; set; } = id;
public XYZ loca { get; set; } = loca;
public string s1 { get; set; } = s1;
public string s2 { get; set; } = s2;
}
}
}
17 changes: 16 additions & 1 deletion Setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ WizardStyle=modern
Name: "english"; MessagesFile: "compiler:Default.isl"

[Files]
Source: "D:\BimIshou\bin\Debug R21\BimIshou.addin"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\BimIshou\bin\Debug R21\BimIshou.addin"; DestDir: "C:\Users\HC-07\AppData\Roaming\Autodesk\Revit\Addins\2021\"; Flags: ignoreversion
Source: "D:\BimIshou\bin\Debug R21\BimIshou.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\BimIshou\bin\Debug R21\BimIshou.pdb"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\BimIshou\bin\Debug R21\CommunityToolkit.Mvvm.dll"; DestDir: "{app}"; Flags: ignoreversion
Expand All @@ -46,5 +46,20 @@ Source: "D:\BimIshou\bin\Debug R21\System.Memory.dll"; DestDir: "{app}"; Flags:
Source: "D:\BimIshou\bin\Debug R21\System.Numerics.Vectors.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\BimIshou\bin\Debug R21\System.Runtime.CompilerServices.Unsafe.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\BimIshou\bin\Debug R21\System.Threading.Tasks.Extensions.dll"; DestDir: "{app}"; Flags: ignoreversion

Source: "D:\BimIshou\bin\Debug R21\BimIshou.addin"; DestDir: "C:\Users\HC-07\AppData\Roaming\Autodesk\Revit\Addins\2019\"; Flags: ignoreversion
Source: "D:\BimIshou\bin\Debug R21\BimIshou.dll"; DestDir: "C:\Users\HC-07\AppData\Roaming\Autodesk\Revit\Addins\2019\BimIshou"; Flags: ignoreversion
Source: "D:\BimIshou\bin\Debug R21\BimIshou.pdb"; DestDir: "C:\Users\HC-07\AppData\Roaming\Autodesk\Revit\Addins\2019\BimIshou"; Flags: ignoreversion
Source: "D:\BimIshou\bin\Debug R21\CommunityToolkit.Mvvm.dll"; DestDir: "C:\Users\HC-07\AppData\Roaming\Autodesk\Revit\Addins\2019\BimIshou"; Flags: ignoreversion
Source: "D:\BimIshou\bin\Debug R21\JetBrains.Annotations.dll"; DestDir: "C:\Users\HC-07\AppData\Roaming\Autodesk\Revit\Addins\2019\BimIshou"; Flags: ignoreversion
Source: "D:\BimIshou\bin\Debug R21\Microsoft.Bcl.AsyncInterfaces.dll"; DestDir: "C:\Users\HC-07\AppData\Roaming\Autodesk\Revit\Addins\2019\BimIshou"; Flags: ignoreversion
Source: "D:\BimIshou\bin\Debug R21\Nice3point.Revit.Extensions.dll"; DestDir: "C:\Users\HC-07\AppData\Roaming\Autodesk\Revit\Addins\2019\BimIshou"; Flags: ignoreversion
Source: "D:\BimIshou\bin\Debug R21\Nice3point.Revit.Toolkit.dll"; DestDir: "C:\Users\HC-07\AppData\Roaming\Autodesk\Revit\Addins\2019\BimIshou"; Flags: ignoreversion
Source: "D:\BimIshou\bin\Debug R21\System.Buffers.dll"; DestDir: "C:\Users\HC-07\AppData\Roaming\Autodesk\Revit\Addins\2019\BimIshou"; Flags: ignoreversion
Source: "D:\BimIshou\bin\Debug R21\System.ComponentModel.Annotations.dll"; DestDir: "C:\Users\HC-07\AppData\Roaming\Autodesk\Revit\Addins\2019\BimIshou"; Flags: ignoreversion
Source: "D:\BimIshou\bin\Debug R21\System.Memory.dll"; DestDir: "C:\Users\HC-07\AppData\Roaming\Autodesk\Revit\Addins\2019\BimIshou"; Flags: ignoreversion
Source: "D:\BimIshou\bin\Debug R21\System.Numerics.Vectors.dll"; DestDir: "C:\Users\HC-07\AppData\Roaming\Autodesk\Revit\Addins\2019\BimIshou"; Flags: ignoreversion
Source: "D:\BimIshou\bin\Debug R21\System.Runtime.CompilerServices.Unsafe.dll"; DestDir: "C:\Users\HC-07\AppData\Roaming\Autodesk\Revit\Addins\2019\BimIshou"; Flags: ignoreversion
Source: "D:\BimIshou\bin\Debug R21\System.Threading.Tasks.Extensions.dll"; DestDir: "C:\Users\HC-07\AppData\Roaming\Autodesk\Revit\Addins\2019\BimIshou"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

29 changes: 29 additions & 0 deletions Utils/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,35 @@ public static string Tostring(this List<Face> objects)
return s;
}
}
public static class CreateModelLine
{
public static ModelLine OnHorizontalPlane(Document doc, Line l, double elevation = 0)
{
var ori = new XYZ(0, 0, elevation);
var nor = XYZ.BasisZ;
var plane = Plane.CreateByNormalAndOrigin(nor, ori);
ModelLine modelLine;
var sk = SketchPlane.Create(doc, plane);
modelLine = doc.Create.NewModelCurve(l, sk) as ModelLine;
return modelLine;
}
public static ModelLine OnVerticalPlane(Document doc, Line l)
{
var ori = l.GetEndPoint(0);
var nor = l.Direction.CrossProduct(XYZ.BasisZ);
var plane = Plane.CreateByNormalAndOrigin(nor, ori);
ModelLine modelLine;
var sk = SketchPlane.Create(doc, plane);
modelLine = doc.Create.NewModelCurve(l, sk) as ModelLine;
return modelLine;
}
public static void ByCurve(Plane plane, Curve line, GraphicsStyle ls, Document doc)
{
var skPlane = SketchPlane.Create(doc, plane);
var modelCurve = doc.Create.NewModelCurve(line, skPlane);
if (modelCurve != null) modelCurve.LineStyle = ls;
}
}
public class SelectionFilter : Autodesk.Revit.UI.Selection.ISelectionFilter
{
private BuiltInCategory _builtInCategory;
Expand Down

0 comments on commit be6487a

Please sign in to comment.