diff --git a/RookieStation.sln b/RookieStation.sln new file mode 100644 index 0000000..94242b1 --- /dev/null +++ b/RookieStation.sln @@ -0,0 +1,29 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31025.218 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RookieStation", "RookieStation\RookieStation.csproj", "{057C7E8D-42A1-4912-B522-498DB7484894}" +EndProject +Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "RookieStationSetup", "RookieStationSetup\RookieStationSetup.vdproj", "{ACB3490C-778E-4EC3-99F7-243388ACCE4C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {057C7E8D-42A1-4912-B522-498DB7484894}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {057C7E8D-42A1-4912-B522-498DB7484894}.Debug|Any CPU.Build.0 = Debug|Any CPU + {057C7E8D-42A1-4912-B522-498DB7484894}.Release|Any CPU.ActiveCfg = Release|Any CPU + {057C7E8D-42A1-4912-B522-498DB7484894}.Release|Any CPU.Build.0 = Release|Any CPU + {ACB3490C-778E-4EC3-99F7-243388ACCE4C}.Debug|Any CPU.ActiveCfg = Debug + {ACB3490C-778E-4EC3-99F7-243388ACCE4C}.Release|Any CPU.ActiveCfg = Release + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2D748E39-17E6-471A-9DC8-9351921D58F6} + EndGlobalSection +EndGlobal diff --git a/RookieStation/CmdArrangeShelfCards.cs b/RookieStation/CmdArrangeShelfCards.cs new file mode 100644 index 0000000..922bbe0 --- /dev/null +++ b/RookieStation/CmdArrangeShelfCards.cs @@ -0,0 +1,71 @@ +using Autodesk.Revit.DB; +using Autodesk.Revit.UI; +using Autodesk.Revit.UI.Selection; +using RookieStation.Utils; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Windows; + +namespace RookieStation.PackAreaModule +{ + [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] + [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] + internal class CmdArrangeShelfCards : IExternalCommand + { + public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) + { + UIApplication uiapp = commandData.Application; + UIDocument uidoc = uiapp.ActiveUIDocument; + + string addin_path = typeof(RsApp).Assembly.Location; + string assembly_directory = System.IO.Path.GetDirectoryName(addin_path); + AssemblyLoader loader = new AssemblyLoader(assembly_directory); + try + { + loader.HookAssemblyResolve(); + + WpfShelfCards cards_number = new WpfShelfCards(uiapp); + + System.Windows.Interop.WindowInteropHelper mainUI = new System.Windows.Interop.WindowInteropHelper(cards_number) + { + Owner = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle + }; + cards_number.ShowDialog(); + } + catch (Exception ex) + { + TaskDialog.Show("错误", ex.Message); + } + finally + { + loader.UnhookAssemblyResolve(); + } + return Result.Succeeded; + //if (IsVisible("端牌编号")) + //{ + // WinIntPtr.ShowAndActive("端牌编号"); + //} + //else + //{ + // cardsPlacement = new WpfNumberShelfCard(); + + // System.Windows.Interop.WindowInteropHelper mainUI = new System.Windows.Interop.WindowInteropHelper(cardsPlacement); + // mainUI.Owner = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle; + + // cardsPlacement.ShowDialog(); + //} + } + + //public static bool IsVisible(string winname) + //{ + // IntPtr ParenthWndldsl = WinIntPtr.FindWindow(null, winname); + // if (!ParenthWndldsl.Equals(IntPtr.Zero)) + // { + // return true; + // } + // return false; + //} + } +} \ No newline at end of file diff --git a/RookieStation/CmdBrowserFamily.cs b/RookieStation/CmdBrowserFamily.cs new file mode 100644 index 0000000..9f3b388 --- /dev/null +++ b/RookieStation/CmdBrowserFamily.cs @@ -0,0 +1,26 @@ +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 RookieStation.CommonTools +{ + [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] + [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] + internal class CmdBrowserFamily : IExternalCommand + { + public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) + { + UIApplication uiapp = commandData.Application; + UIDocument uidoc = uiapp.ActiveUIDocument; + //var dpid = new DockablePaneId(PaneIdentifiers.GetManagerPaneIdentifier()); + var library_directory = UserConstant.LibraryPreDirectory; + System.Diagnostics.Process.Start(library_directory); + return Result.Succeeded; + } + } +} \ No newline at end of file diff --git a/RookieStation/CmdLogoExtrusion.cs b/RookieStation/CmdLogoExtrusion.cs new file mode 100644 index 0000000..5922ba1 --- /dev/null +++ b/RookieStation/CmdLogoExtrusion.cs @@ -0,0 +1,110 @@ +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 RookieStation +{ + [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] + [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] + internal class CmdLogoExtrusion : 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; + ICollection instances = new FilteredElementCollector(doc).OfClass(typeof(ImportInstance)).Cast().ToList(); + List curves = new List(); + + var geometryElement = instances.First().get_Geometry(new Options()); + + foreach (var geomObj in geometryElement) + { + GeometryInstance geometryInstance = geomObj as GeometryInstance; + if (geometryInstance != null) + { + foreach (var instObj in geometryInstance.GetInstanceGeometry()) + { + Curve curve = instObj as Curve; + if (curve == null) + { + continue; + } + curves.Add(curve); + } + } + } + CurveArrArray arrArray = new CurveArrArray(); + CurveArray array = new CurveArray(); + do + { + Curve curve = curves.Last(); + array.Clear(); + Curve tempcurve = curve; + var endxyz = tempcurve.GetEndPoint(1); + for (int j = curves.Count - 1; j >= 0; j--) + { + Curve cur = curves[j]; + if (cur.Equals(tempcurve)) + { + array.Append(cur); + curves.Remove(cur); + continue; + } + if (cur.GetEndPoint(0).IsAlmostEqualTo(endxyz)) + { + tempcurve = cur; + endxyz = cur.GetEndPoint(1); + array.Append(cur); + curves.Remove(cur); + continue; + } + if (cur.GetEndPoint(1).IsAlmostEqualTo(endxyz)) + { + tempcurve = cur; + endxyz = cur.GetEndPoint(0); + array.Append(cur); + curves.Remove(cur); + continue; + } + } + arrArray.Append(array); + } while (curves.Count > 0); + + using (Transaction trans = new Transaction(doc, "cmd")) + { + try + { + trans.Start(); + //foreach (var item in curves) + //{ + //} + //doc.FamilyCreate.NewModelCurve() + SketchPlane plane = SketchPlane.Create(doc, Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero)); + foreach (CurveArray arr in arrArray) + { + doc.FamilyCreate.NewModelCurveArray(arr, plane); + } + + trans.Commit(); + } + catch (Exception ex) + { + message = ex.Message; + if (trans.GetStatus() == TransactionStatus.Started) + { + trans.RollBack(); + } + return Result.Cancelled; + } + } + return Result.Succeeded; + } + } +} \ No newline at end of file diff --git a/RookieStation/CmdNewDimension.cs b/RookieStation/CmdNewDimension.cs new file mode 100644 index 0000000..b698703 --- /dev/null +++ b/RookieStation/CmdNewDimension.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Autodesk.Revit.DB; +using Autodesk.Revit.UI.Selection; +using Autodesk.Revit.UI; +using RookieStation.Utils; + +namespace RookieStation +{ + [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] + [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] + internal class CmdNewDimension : IExternalCommand + { + public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) + { + UIDocument uidoc = commandData.Application.ActiveUIDocument; + Document doc = uidoc.Document; + + //var instance = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element, new ShelvesFilter(), "请选择货架")) as FamilyInstance; + List instances = uidoc.Selection.PickObjects(ObjectType.Element, "请选择货架") + .Select(x => doc.GetElement(x)) + .Cast() + .ToList(); + + ReferenceArray refArry = new ReferenceArray(); + List reffaces = new List(); + var ins = instances.FirstOrDefault(); + + var p = RsRevitUtils.GetXYZByElement(ins); + var v = ins.FacingOrientation; + Line line = Line.CreateUnbound(p, v); + //createoffest需要根据线的方向和参考方向进行叉乘 + var line1 = line.CreateOffset(1000 / 304.8, XYZ.BasisZ) as Line; + if (instances.Count < 1) + { + return Result.Cancelled; + } + foreach (FamilyInstance instance in instances) + { + List allfaces = new List(); + + Options opt = new Options(); + opt.ComputeReferences = true; + + ICollection eleids = instance.GetSubComponentIds(); + + var referback = instance.GetReferences(FamilyInstanceReferenceType.Back); + var referfront = instance.GetReferences(FamilyInstanceReferenceType.Front); + //var geom = instance.GetGeometryObjectFromReference(referface.FirstOrDefault()); + refArry.Append(referback.First()); + refArry.Append(referfront.First()); + + using (Transaction trans = new Transaction(doc, "创建尺寸标注")) + { + trans.Start(); + + Dimension dim = doc.Create.NewDimension(doc.ActiveView, line1, refArry); + + trans.Commit(); + } + //var fas = RevitCommonUtils.GetFacesByFamilyInstance(instance, opt); + //var fas = RevitCommonUtils.GetFamilyInstanceFaces(instance, opt); + + //foreach (Face face in fas) + //{ + // bool a = face.Reference.ConvertToStableRepresentation(doc).Contains("612:SURFACE"); + // bool b = face.Reference.ConvertToStableRepresentation(doc).Contains("546:SURFACE"); + // if (a || b) + // { + // reffaces.Add(face); + // var pface = face as PlanarFace; + // //var geom = instance.GetGeometryObjectFromReference(face.Reference); + // refArry.Append(face.Reference); + // } + //} + //refArry.Append(reffaces.First().Reference); + //refArry.Append(reffaces.Last().Reference); + } + + return Result.Succeeded; + } + } +} \ No newline at end of file diff --git a/RookieStation/CmdPlaceEntranceGate.cs b/RookieStation/CmdPlaceEntranceGate.cs new file mode 100644 index 0000000..67d95c4 --- /dev/null +++ b/RookieStation/CmdPlaceEntranceGate.cs @@ -0,0 +1,132 @@ +using Autodesk.Revit.DB; +using Autodesk.Revit.UI; +using Autodesk.Revit.UI.Selection; +using RookieStation.Utils; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace RookieStation.PackAreaModule +{ + [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] + [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] + internal class CmdPlaceEntranceGate : IExternalCommand + { + /// + /// 选择一次后停止 + /// + private static bool PlaceSingleInstanceAbort = true; + + /// + /// revit窗口句柄 + /// + private IntPtr revitWindow; + + /// + /// 添加的元素 + /// + private List eleIdsAdded = new List(); + + public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) + { + UIApplication uiapp = commandData.Application; + UIDocument uidoc = uiapp.ActiveUIDocument; + Document doc = uidoc.Document; + revitWindow = uiapp.MainWindowHandle; + + WpfEntranceGate entrancegateLayout = CommonUtils.GenerateWindow(); + return doc.InvokeGroup(tg => + { + if (entrancegateLayout.DialogResult != true) + { + return Result.Cancelled; + } + + try + { + FamilySymbol linesymbol = RsRevitUtils.GetGuideSymbol(doc); + eleIdsAdded.Clear(); + uiapp.Application.DocumentChanged += Application_DocumentChanged; + uidoc.PromptForFamilyInstancePlacement(linesymbol); + uiapp.Application.DocumentChanged -= Application_DocumentChanged; + } + catch (Autodesk.Revit.Exceptions.OperationCanceledException) + { + if (eleIdsAdded.Count == 0) + { + return Result.Cancelled; + } + Line refer_line = RsRevitUtils.GetGuideGeometryAndDeleteGuide(doc, eleIdsAdded); + uiapp.Application.DocumentChanged -= Application_DocumentChanged; + + double interval = (330 + entrancegateLayout.passage_width) / 304.8; + double offest = 0.0; + //布置闸机的数量 + List pts = GetInstancePointsByLine(refer_line, interval); + List instances = new List(); + doc.Invoke(ts => + { + CreateGates(uidoc, pts, out instances, out offest); + }, "创建闸机位置"); + doc.Invoke(ts => + { + RsRevitUtils.AdjustInstances(doc, instances, refer_line, offest); + }, "调整闸机位置"); + } + return Result.Succeeded; + }, "布置入口闸机"); + } + + private void CreateGates(UIDocument uidoc, List pts, out List fis, out double offest) + { + Document doc = uidoc.Document; + fis = new List(); + + Level level = uidoc.ActiveView.GenLevel; + Family gate_family = RsRevitUtils.GetLoadedFamily(doc, UserConstant.LibraryPreDirectory + "Gate\\闸机.rfa"); + ElementId symbol_id = gate_family.GetFamilySymbolIds().FirstOrDefault(); + FamilySymbol gate_symbol = doc.GetElement(symbol_id) as FamilySymbol; + offest = gate_symbol.GetParameters("深度").FirstOrDefault().AsDouble() / 2; + gate_symbol.Activate(); + foreach (var pt in pts) + { + var instance = doc.Create.NewFamilyInstance(pt, gate_symbol, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + fis.Add(instance); + } + } + + private List GetInstancePointsByLine(Line referline, double interval) + { + int n = 50; + List pts = new List(); + for (int i = 0; i < n; i++) + { + double parameter = (i + 0.5) * interval; + if (!referline.IsInside(parameter + (interval / 2))) + { + break; + } + pts.Add(referline.Evaluate(parameter, false)); + } + + return pts; + } + + private void Application_DocumentChanged(object sender, Autodesk.Revit.DB.Events.DocumentChangedEventArgs e) + { + ICollection idsAdded = e.GetAddedElementIds(); + int n = idsAdded.Count; + eleIdsAdded.AddRange(idsAdded); + if (PlaceSingleInstanceAbort && n == 1) + { + KeyPress.PostMessage(revitWindow, (uint)KeyPress.KEYBOARD_MSG.WM_KEYDOWN, (uint)System.Windows.Forms.Keys.Escape, 0); + KeyPress.PostMessage(revitWindow, (uint)KeyPress.KEYBOARD_MSG.WM_KEYDOWN, (uint)System.Windows.Forms.Keys.Escape, 0); + //KeyPress.OneKey(revitWindow, (char)System.Windows.Forms.Keys.Escape); + } + } + } +} \ No newline at end of file diff --git a/RookieStation/CmdPlaceExitGate.cs b/RookieStation/CmdPlaceExitGate.cs new file mode 100644 index 0000000..0247ca7 --- /dev/null +++ b/RookieStation/CmdPlaceExitGate.cs @@ -0,0 +1,232 @@ +using Autodesk.Revit.DB; +using Autodesk.Revit.DB.Events; +using Autodesk.Revit.UI; +using Autodesk.Revit.UI.Selection; +using RookieStation.Utils; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace RookieStation.PackAreaModule +{ + [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] + [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] + internal class CmdPlaceExitGate : IExternalCommand + { + /// + /// 是否起始为通道 + /// + internal bool isPassageStart; + + /// + /// 选择一次后停止 + /// + private static bool PlaceSingleInstanceAbort = true; + + /// + /// revit窗口句柄 + /// + private IntPtr revitWindow; + + /// + /// 添加的元素 + /// + private List eleIdsAdded = new List(); + + public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) + { + UIApplication uiapp = commandData.Application; + UIDocument uidoc = uiapp.ActiveUIDocument; + Document doc = uidoc.Document; + revitWindow = uiapp.MainWindowHandle; + + WpfExitGate gate_layout = CommonUtils.GenerateWindow(); + + if (gate_layout.DialogResult == true) + { + isPassageStart = gate_layout.isStartPassage; + } + else + { + return Result.Cancelled; + } + double interval = (2 * (1030 + gate_layout.passage_width) + 100) / 304.8; + double gate_front_offest = 1630 / 304.8; + List instances = new List(); + + using (TransactionGroup tg = new TransactionGroup(doc, "布置出口收检台")) + { + tg.Start(); + try + { + FamilySymbol line_symbol = RsRevitUtils.GetGuideSymbol(doc); ; + + eleIdsAdded.Clear(); + uiapp.Application.DocumentChanged += Application_DocumentChanged; + uidoc.PromptForFamilyInstancePlacement(line_symbol); + uiapp.Application.DocumentChanged -= Application_DocumentChanged; + } + catch (Autodesk.Revit.Exceptions.OperationCanceledException) + { + if (eleIdsAdded.Count == 0) + { + return Result.Cancelled; + } + //直线向量 + Line refer_line = RsRevitUtils.GetGuideGeometryAndDeleteGuide(doc, eleIdsAdded); + uiapp.Application.DocumentChanged -= Application_DocumentChanged; + + int orders = UserConstant.Orders; + int n = GetGateCountByOrders(orders); + if (orders.Equals(0) || n == 0) + { + TaskDialog.Show("温馨提示", "单量有误"); + return Result.Cancelled; + } + + int m = isPassageStart + ? (int)Math.Floor((refer_line.Length * 304.8 / 1630) + 0.5) + : (int)Math.Floor(((refer_line.Length * 304.8) - 200) / 1630 + 0.5); + if (m < n) + { + n = m; + } + List pts = new List(); + doc.Invoke(ts => + { + Family gate_family = RsRevitUtils.GetLoadedFamily(doc, UserConstant.LibraryPreDirectory + "Gate\\L型收检台.rfa"); + IEnumerable left_symbolId = from id in gate_family.GetFamilySymbolIds() + where doc.GetElement(id).Name == "左" + select id; + IEnumerable right_symbolId = from id in gate_family.GetFamilySymbolIds() + where doc.GetElement(id).Name == "右" + select id; + FamilySymbol right_symbol = doc.GetElement(right_symbolId.FirstOrDefault()) as FamilySymbol; + //ElementId symbolId = family.GetFamilySymbolIds().FirstOrDefault(); + FamilySymbol left_symbol = doc.GetElement(left_symbolId.FirstOrDefault()) as FamilySymbol; + Level level = uidoc.ActiveView.GenLevel; + if (isPassageStart)//起始是通道 + { + for (int i = 0; i < n; i++) + { + XYZ p = refer_line.Evaluate(i * interval, false); + pts.Add(p); + } + + foreach (XYZ location_XYZ in pts) + { + left_symbol.Activate(); + FamilyInstance left_instance = doc.Create.NewFamilyInstance(location_XYZ, left_symbol, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + instances.Add(left_instance); + if (instances.Count() == n + 1) + { + break; + } + right_symbol.Activate(); + FamilyInstance right_instance = doc.Create.NewFamilyInstance(location_XYZ, right_symbol, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + instances.Add(right_instance); + if (instances.Count() == n + 1) + { + break; + } + + //offest = symbol.GetParameters("深度").FirstOrDefault().AsDouble() / 2; + } + + doc.Delete(instances.First().Id); + instances.RemoveAt(0); + } + else//起始是收检台 + { + for (int i = 0; i < n; i++) + { + XYZ p = refer_line.Evaluate((i * interval) + 1830 / 304.8, false); + + pts.Add(p); + } + foreach (var pt in pts) + { + left_symbol.Activate(); + var left_instance = doc.Create.NewFamilyInstance(pt, left_symbol, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + + //offest = symbol.GetParameters("深度").FirstOrDefault().AsDouble() / 2; + instances.Add(left_instance); + if (instances.Count() == n) + { + break; + } + + right_symbol.Activate(); + var right_instance = doc.Create.NewFamilyInstance(pt, right_symbol, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + instances.Add(right_instance); + if (instances.Count() == n) + { + break; + } + } + } + }, "加载并创建收检台"); + doc.Invoke(ts => + { + RsRevitUtils.AdjustInstances(doc, instances, refer_line, gate_front_offest); + }, "调整收检台位置"); + //if (tg.GetStatus() == TransactionStatus.Started) + //{ + // tg.RollBack(); + //} + //return Result.Cancelled; + } + tg.Assimilate(); + } + return Result.Succeeded; + } + + private int GetGateCountByOrders(int orders) + { + int n; + if (0 < orders && orders <= 2000) + { + n = 2; + } + else if (2000 < orders && orders <= 4000) + { + n = 3; + } + else if (4000 < orders && orders <= 6000) + { + n = 4; + } + else if (6000 < orders && orders <= 8000) + { + n = 5; + } + else if (8000 < orders) + { + n = 6; + } + else + { + n = 0; + } + + return n; + } + + private void Application_DocumentChanged(object sender, DocumentChangedEventArgs e) + { + ICollection idsAdded = e.GetAddedElementIds(); + int n = idsAdded.Count; + eleIdsAdded.AddRange(idsAdded); + if (PlaceSingleInstanceAbort && n == 1) + { + KeyPress.PostMessage(revitWindow, (uint)KeyPress.KEYBOARD_MSG.WM_KEYDOWN, (uint)System.Windows.Forms.Keys.Escape, 0); + KeyPress.PostMessage(revitWindow, (uint)KeyPress.KEYBOARD_MSG.WM_KEYDOWN, (uint)System.Windows.Forms.Keys.Escape, 0); + //KeyPress.OneKey(revitWindow, (char)System.Windows.Forms.Keys.Escape); + } + } + } +} \ No newline at end of file diff --git a/RookieStation/CmdPlaceFloorFinishes.cs b/RookieStation/CmdPlaceFloorFinishes.cs new file mode 100644 index 0000000..310b8c3 --- /dev/null +++ b/RookieStation/CmdPlaceFloorFinishes.cs @@ -0,0 +1,564 @@ +using Autodesk.Revit.DB; +using Autodesk.Revit.DB.Architecture; +using Autodesk.Revit.UI; +using Autodesk.Revit.UI.Selection; +using RookieStation.Utils; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Windows; + +namespace RookieStation.CommonTools +{ + [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] + [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] + internal class CmdPlaceFloorFinishes : IExternalCommand + { + private static string AddinPath = typeof(CmdPlaceFloorFinishes).Assembly.Location; + + public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) + { + UIApplication uiapp = commandData.Application; + UIDocument uidoc = uiapp.ActiveUIDocument; + Document doc = uidoc.Document; + Family family = null; + FamilySymbol symbol; + + WpfFloorFinishes floorCovering = CommonUtils.GenerateWindow(); + var rooms = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).ToList(); + if (rooms.Count == 0) + { + TaskDialog.Show("温馨提示", "项目中当前没有房间"); + return Result.Cancelled; + } + + double length; + double width; + double gap; + + if (floorCovering.DialogResult == true) + { + length = floorCovering.cLength / 304.8; + width = floorCovering.cWidth / 304.8; + gap = floorCovering.cGap / 304.8; + } + else + { + return Result.Cancelled; + } + + using (TransactionGroup tg = new TransactionGroup(doc, "地面铺装")) + { + try + { + var v = new FilteredElementCollector(doc).OfClass(typeof(View)) + .Cast() + .FirstOrDefault(x => x.ViewType == ViewType.FloorPlan && x.GenLevel.Elevation == 0); + + var baselevel = new FilteredElementCollector(doc) + .OfClass(typeof(Level)) + .Cast() + .FirstOrDefault(x => x.Elevation == 0); + + List modelCurveIds = new List(); + tg.Start(); + if (uidoc.ActiveView.ViewType != ViewType.FloorPlan) + { + uidoc.RequestViewChange(v); + } + + SelectFilter selfilter = new SelectFilter(); + Reference roomrefer = uidoc.Selection.PickObject(ObjectType.Element, selfilter, "请选择房间"); + Room room = doc.GetElement(roomrefer) as Room; + + var roompoint = RsRevitUtils.GetXYZByElement(room); + var segments = room.GetBoundarySegments(new SpatialElementBoundaryOptions()).FirstOrDefault(); + + doc.Invoke(ts => + { + foreach (var seg in segments) + { + Curve cur = seg.GetCurve(); + Plane plane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, new XYZ()); + var mc = doc.Create.NewModelCurve(cur, SketchPlane.Create(doc, plane)); + modelCurveIds.Add(mc.Id); + } + }, "模型线创建"); + + //Reference edge = uidoc.Selection.PickObject(ObjectType.Edge, "请选择边界"); + SelectFilter mlfilter = new SelectFilter(); + Reference refline = uidoc.Selection.PickObject(ObjectType.Element, mlfilter, "请选择基准边线"); + //模型线选取 + var ml = doc.GetElement(refline) as ModelLine; + Line line = ml.GeometryCurve as Line; + Line line1 = RsRevitUtils.GetLongestSegmentLine(segments, line); + XYZ basepoint = uidoc.Selection.PickPoint(UserConstant.SnapAll, "请选择基准点(位于基准线上)"); + double alength = basepoint.DistanceTo(line.GetEndPoint(0)) + basepoint.DistanceTo(line.GetEndPoint(1)); + if (line.Length - alength > 0.001) + { + MessageBox.Show("请选择基准线上的点", "温馨提示"); + return Result.Cancelled; + } + //if (basepoint.IsAlmostEqualTo(ml.GeometryCurve.GetEndPoint(0)) || basepoint.IsAlmostEqualTo(ml.GeometryCurve.GetEndPoint(1))) + //{ + //} + //基准线端点 + var endp1 = line.GetEndPoint(0); + var endp2 = line.GetEndPoint(1); + //基准点向端点的向量 + XYZ v1 = endp1 - basepoint; + XYZ v2 = endp2 - basepoint; + //用于确认布置方向 + var v0 = roompoint - basepoint; + List curves = new List(); + List instances = new List(); + //Curve currefer = null; + //Curve currefer1 = null; + + double interval = length + gap; + List pts = new List(); + List lastps = new List(); + XYZ zdir1 = null; + XYZ zdir2 = null; + XYZ offestvector = null; + double d1 = 0.0; + double d2 = 0.0; + //切分基准线后,两侧向量不为0 + if (!v1.IsAlmostEqualTo(XYZ.Zero)) + { + if (endp1.DistanceTo(basepoint) < length) + { + System.Windows.MessageBox.Show("基准点与基准线端点距离太近"); + return Result.Cancelled; + } + zdir1 = v1.CrossProduct(v0).Normalize(); + //偏移的方向,直线的侧方向 + offestvector = zdir1.CrossProduct(v1).Normalize(); + Line l1 = Line.CreateBound(basepoint, ml.GeometryCurve.GetEndPoint(0)); + + for (int i = 0; i < 10000; i++) + { + var parameter = i * interval; + if (!l1.IsInside(parameter + interval - gap / 2)) + { + var lastp1 = pts.Last() - offestvector * width / 2; + + d1 = lastp1.DistanceTo(endp1) - length / 2 - gap; + + var lastfinalpoint = lastp1 + (l1.Direction * (d1 / 2 + length / 2 + gap)) + (offestvector * width / 2); + + lastps.Add(lastfinalpoint); + break; + } + XYZ p = l1.Evaluate(parameter, false); + XYZ finalpoint = p + (l1.Direction * interval / 2) + (offestvector * width / 2); + //当选择的基准点为端点时 + if (v2.IsAlmostEqualTo(XYZ.Zero)) + { + finalpoint = p + (l1.Direction * (interval - gap) / 2) + (offestvector * width / 2); + } + + pts.Add(finalpoint); + } + } + + if (!v2.IsAlmostEqualTo(XYZ.Zero)) + { + if (endp2.DistanceTo(basepoint) < length) + { + System.Windows.MessageBox.Show("基准点与基准线端点距离太近"); + return Result.Cancelled; + } + zdir2 = v2.CrossProduct(v0).Normalize(); + offestvector = zdir2.CrossProduct(v2).Normalize(); + Line l2 = Line.CreateBound(basepoint, ml.GeometryCurve.GetEndPoint(1)); + + for (int i = 0; i < 10000; i++) + { + var parameter = i * interval; + if (!l2.IsInside(parameter + interval - gap / 2)) + { + //var lastdistance = pts.Last().DistanceTo(endp1) - interval / 2 - gap / 2; + + var lastp2 = pts.Last() - offestvector * width / 2; + + d2 = lastp2.DistanceTo(endp2) - length / 2 - gap; + + var lastfinalpoint = lastp2 + (l2.Direction * (d2 / 2 + length / 2 + gap)) + (offestvector * width / 2); + + lastps.Add(lastfinalpoint); + break; + } + XYZ p = l2.Evaluate(parameter, false); + //附加的基准线的水平垂直偏移距离 + var finalpoint = p + (l2.Direction * interval / 2) + (offestvector * width / 2); + if (v1.IsAlmostEqualTo(XYZ.Zero)) + { + finalpoint = p + (l2.Direction * (interval - gap) / 2) + (offestvector * width / 2); + } + + pts.Add(finalpoint); + } + //var lastl2 = pts.Last().DistanceTo(endp2); + } + + using (Transaction trans = new Transaction(doc, "地面铺装")) + { + trans.Start(); + //删除模型线 + doc.Delete(modelCurveIds); + family = RsRevitUtils.GetLoadedFamily(doc, UserConstant.LibraryPreDirectory + "FloorFinish\\地砖.rfa"); + ElementId symbolId = family.GetFamilySymbolIds().FirstOrDefault(); + symbol = doc.GetElement(symbolId) as FamilySymbol; + symbol.Activate(); + foreach (var p in pts) + { + var fi = doc.Create + .NewFamilyInstance(p, symbol, baselevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + instances.Add(fi); + } + foreach (var p in lastps) + { + var fi = doc.Create + .NewFamilyInstance(p, symbol, baselevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + instances.Add(fi); + } + trans.Commit(); + } + using (Transaction trans = new Transaction(doc, "调整地砖")) + { + trans.Start(); + XYZ veroffestdir = null; + if (zdir1 != null) + { + veroffestdir = zdir1.CrossProduct(line.Direction).Normalize(); + } + if (zdir2 != null) + { + veroffestdir = zdir2.CrossProduct(line.Direction).Normalize(); + } + //旋转角度 + double angle = XYZ.BasisY.AngleTo(veroffestdir); + //判断相对于Y轴是正向角度(逆时针)还是逆向角度(顺时针) + var z = veroffestdir.CrossProduct(XYZ.BasisY).Normalize(); + if (z.IsAlmostEqualTo(XYZ.BasisZ)) + { + //逆向旋转,角度取负值 + angle = -angle; + } + //单行调整地砖数量 + int n = 0; + if (v2.IsAlmostEqualTo(XYZ.Zero) || v1.IsAlmostEqualTo(XYZ.Zero)) + { + n = 1; + } + else + { + n = 2; + } + for (int i = 0; i < instances.Count; i++) + { + FamilyInstance fi = instances[i]; + + var filp = RsRevitUtils.GetXYZByElement(fi); + Line zaxis = Line.CreateUnbound(filp, XYZ.BasisZ); + + //旋转,移动 + ElementTransformUtils.RotateElement(doc, fi.Id, zaxis, angle); + fi.GetParameters("长").FirstOrDefault().Set(length); + fi.GetParameters("宽").FirstOrDefault().Set(width); + + if (i >= instances.Count - n) + { + var loc = RsRevitUtils.GetXYZByElement(instances[i]); + + var dis1 = loc.DistanceTo(endp1); + var dis2 = loc.DistanceTo(endp2); + + if (dis1 < interval) + { + fi.GetParameters("长").FirstOrDefault().Set(d1); + } + else if (dis2 < interval) + { + fi.GetParameters("长").FirstOrDefault().Set(d2); + } + } + //ElementTransformUtils.CopyElement(doc, fi.Id, offestvector * (width + gap)); + ////垂直基准线平移 + //ElementTransformUtils.MoveElement(doc, fi.Id, offestdir); + + ////平行基准线平移 + //ElementTransformUtils.MoveElement(doc, fi.Id, line.Direction * w / 2); + //if (i >= 1) + //{ + // XYZ additionaldir = zdir.CrossProduct(line.Direction).Normalize() * i * (passagewidth + l); + // ElementTransformUtils.MoveElement(doc, fi.Id, additionaldir); + //} + //位于直线右侧时,需要进行左右翻转 + //if (OnLeft == false && fi.CanFlipHand) + //{ + // fi.flipHand(); + //} + } + + trans.Commit(); + } + using (Transaction trans = new Transaction(doc, "复制地砖")) + { + List copyids = new List(); + trans.Start(); + for (int i = 0; i < instances.Count; i++) + { + FamilyInstance fi = instances[i]; + int num = (int)Math.Floor(line1.Length / (width + gap)); + double rem = line1.Length - num * (width + gap); + for (int j = 1; j <= num; j++) + { + ICollection eles; + if (j == num) + { + eles = ElementTransformUtils.CopyElement(doc, fi.Id, offestvector * ((rem / 2) + (width + gap) * (j - 0.5) + gap)); + FamilyInstance copyinstance = doc.GetElement(eles.FirstOrDefault()) as FamilyInstance; + copyinstance.GetParameters("宽").FirstOrDefault().Set(rem); + + copyids.AddRange(eles.ToList()); + break; + } + eles = ElementTransformUtils.CopyElement(doc, fi.Id, offestvector * (width + gap) * j); + copyids.AddRange(eles.ToList()); + } + } + foreach (var id in copyids) + { + FamilyInstance copyinstance = doc.GetElement(id) as FamilyInstance; + if (copyinstance.Room == null) + { + doc.Delete(id); + } + } + trans.Commit(); + } + + #region MyRegion + + //foreach (var seg in segments) + //{ + // Curve cur = seg.GetCurve(); + // if (cur.GetEndPoint(0).IsAlmostEqualTo(startP) || cur.GetEndPoint(1).IsAlmostEqualTo(startP)) + // { + // currefer = cur; + // } + // if (cur.GetEndPoint(1).IsAlmostEqualTo(startP)) + // { + // currefer1 = cur; + // } + + // //XYZ p1 = cur.Evaluate(100 / 304.8, false); + // //XYZ p2 = cur.Evaluate(200 / 304.8, false); + //} + + //var n = Math.Floor(currefer1.Length / interval) + 1; + //var rem = currefer1.Length % interval / interval; + + //var x = 0.5; + //if (rem < 0.334) + //{ + // x = (1 + rem) / 4; + // for (int i = 0; i < n; i++) + // { + // Curve l = null; + // if (i == 0) + // { + // l = currefer.CreateOffset((i + x) * interval, -XYZ.BasisZ); + // } + // if (i >= 1) + // { + // l = currefer.CreateOffset((i - 0.5 + 2 * x) * interval, -XYZ.BasisZ); + // } + // if (i == n - 1) + // { + // l = currefer.CreateOffset((i - 1 + 3 * x) * interval, -XYZ.BasisZ); + // } + + // curves.Add(l); + // } + //} + //else + //{ + // for (int i = 0; i < n; i++) + // { + // //var v = cur.Direction.CrossProduct(XYZ.BasisZ); + // //createoffset的偏移方向由线方向 叉乘 自己给定的方向 + + // var l = currefer.CreateOffset((i + x) * interval, -XYZ.BasisZ); + // if (i == n - 1) + // { + // l = currefer.CreateOffset((i - 1 + x) * interval, -XYZ.BasisZ); + // } + // curves.Add(l); + // } + //} + + //var m = Math.Floor(currefer.Length / interval) + 1; + //var rem1 = currefer.Length % interval / interval; + //x = 0.5; + //if (rem1 < 0.334) + //{ + // x = (1 + rem1) / 4; + // for (int i = 0; i < m; i++) + // { + // Curve l = null; + // if (i == 0) + // { + // l = currefer1.CreateOffset((i + x) * interval, -XYZ.BasisZ); + // } + // if (i >= 1) + // { + // l = currefer1.CreateOffset((i - 0.5 + 2 * x) * interval, -XYZ.BasisZ); + // } + // if (i == m - 1) + // { + // l = currefer1.CreateOffset((i - 1 + 3 * x) * interval, -XYZ.BasisZ); + // } + + // curves.Add(l); + // } + //} + //else + //{ + // for (int i = 0; i < m; i++) + // { + // var l = currefer1.CreateOffset((i + x) * interval, -XYZ.BasisZ); + // if (i == m - 1) + // { + // l = currefer.CreateOffset((i - 1 + x) * interval, -XYZ.BasisZ); + // } + // curves.Add(l); + // } + //} + + //var pts = GetIntersectPoints(curves); + //Plane pl = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, new XYZ()); + //foreach (var item in curves) + //{ + // ModelCurve model = doc.Create.NewModelCurve(item, SketchPlane.Create(doc, pl)); + //} + + //foreach (var p in pts) + //{ + // var fi = doc.Create + // .NewFamilyInstance(p, symbol, baselevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + // instances.Add(fi); + //} + //foreach (var fi in instances) + //{ + // var lp = fi.Location as LocationPoint; + // var p = lp.Point; + // foreach (var seg in segments) + // { + // var l = seg.GetCurve() as Line; + // if (l.Distance(p) - ((1 + rem) / 4 * interval) < 0.001) + // { + // if (l.Direction.X < 0.001) + // { + // fi.GetParameters("长度").FirstOrDefault().Set((1 + rem) / 2 * (interval - halfgap)); + // } + // else if (l.Direction.Y < 0.001) + // { + // fi.GetParameters("宽度").FirstOrDefault().Set((1 + rem) / 2 * (interval - halfgap)); + // } + // } + // else if (l.Distance(p) - ((1 + rem1) / 4 * interval) < 0.001) + // { + // if (l.Direction.X < 0.001) + // { + // fi.GetParameters("长度").FirstOrDefault().Set((1 + rem1) / 2 * (interval - halfgap)); + // } + // else if (l.Direction.Y < 0.001) + // { + // fi.GetParameters("宽度").FirstOrDefault().Set((1 + rem1) / 2 * (interval - halfgap)); + // } + // } + // if (true) + // { + // } + // } + //} + + //ModelCurve mc = doc.Create.NewModelCurve(); + //var geoelem = room.get_Geometry(new Options()); + //foreach (var geomObj in geoelem) + //{ + // Solid geomSolid = geomObj as Solid; + // if (null != geomSolid) + // { + // foreach (Face geomFace in geomSolid.Faces) + // { + // break; + // } + // break; + // } + //} + + //Do Something. + + #endregion MyRegion + + tg.Assimilate(); + } + catch (Autodesk.Revit.Exceptions.OperationCanceledException) + { + if (tg.GetStatus() == TransactionStatus.Started) + { + tg.RollBack(); + } + return Result.Cancelled; + } + } + return Result.Succeeded; + } + + private List GetIntersectPoints(List curves) + { + //获取轴网的所有交点 + List Points = new List(); + foreach (Curve curve in curves) + { + Curve currentCurve = curve; + foreach (Curve cur in curves) + { + IntersectionResultArray ira = null; + SetComparisonResult scr = currentCurve.Intersect(cur, out ira); + if (scr == SetComparisonResult.Overlap && ira.Size == 1) + { + XYZ tp = ira.get_Item(0).XYZPoint; + if (Points.Where(m => m.IsAlmostEqualTo(tp)).Count() == 0) + { + Points.Add(tp); //收集所有的交点 + } + } + } + } + return Points; + } + + //public class SelectionFilter : ISelectionFilter + //{ + // public bool AllowElement(Element element) + // { + // if (element.Category.Id.IntegerValue == -2000160) + // { + // return true; + // } + // return false; + // } + + // public bool AllowReference(Reference refer, XYZ point) + // { + // return false; + // } + //} + } +} \ No newline at end of file diff --git a/RookieStation/CmdPlaceLamps.cs b/RookieStation/CmdPlaceLamps.cs new file mode 100644 index 0000000..22d654c --- /dev/null +++ b/RookieStation/CmdPlaceLamps.cs @@ -0,0 +1,243 @@ +using Autodesk.Revit.DB; +using Autodesk.Revit.DB.Architecture; +using Autodesk.Revit.DB.Electrical; +using Autodesk.Revit.UI; +using Autodesk.Revit.UI.Selection; +using RookieStation.Utils; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace RookieStation.PackAreaModule +{ + [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] + [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] + internal class CmdPlaceLamps : 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; + Family family = null; + FamilySymbol symbol; + double lrdistance = 0.0; + double fbdistance = 0.0; + + var rooms = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).ToList(); + if (rooms.Count == 0) + { + TaskDialog.Show("温馨提示", "项目中当前没有房间"); + return Result.Cancelled; + } + WpfLampsLayout placeLamps = CommonUtils.GenerateWindow(); + + if (placeLamps.DialogResult == true) + { + lrdistance = placeLamps.LRDistance / 304.8; + fbdistance = placeLamps.LRDistance / 304.8; + } + else + { + return Result.Cancelled; + } + double interval = 2000 / 304.8; + + using (TransactionGroup tg = new TransactionGroup(doc, "布置灯具")) + { + try + { + var v = new FilteredElementCollector(doc).OfClass(typeof(View)) + .Cast() + .FirstOrDefault(x => x.ViewType == ViewType.FloorPlan && x.GenLevel.Elevation == 0); + + var baselevel = new FilteredElementCollector(doc) + .OfClass(typeof(Level)) + .Cast() + .FirstOrDefault(x => x.Elevation == 0); + + List modelCurveIds = new List(); + tg.Start(); + if (uidoc.ActiveView.ViewType != ViewType.FloorPlan) + { + uidoc.RequestViewChange(v); + } + + SelectFilter selfilter = new SelectFilter(); + Reference roomrefer = uidoc.Selection.PickObject(ObjectType.Element, selfilter, "请选择房间"); + Room room = doc.GetElement(roomrefer) as Room; + + var roompoint = RsRevitUtils.GetXYZByElement(room); + + IList segments = room.GetBoundarySegments(new SpatialElementBoundaryOptions()).FirstOrDefault(); + + using (Transaction ts = new Transaction(doc, "模型线创建")) + { + ts.Start(); + foreach (var seg in segments) + { + Curve cur = seg.GetCurve(); + Plane plane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, new XYZ()); + var mc = doc.Create.NewModelCurve(cur, SketchPlane.Create(doc, plane)); + modelCurveIds.Add(mc.Id); + } + + ts.Commit(); + } + //Reference edge = uidoc.Selection.PickObject(ObjectType.Edge, "请选择边界"); + SelectFilter mlfilter = new SelectFilter(); + Reference refline = uidoc.Selection.PickObject(ObjectType.Element, mlfilter, "请选择基准边线"); + //模型线选取 + var ml = doc.GetElement(refline) as ModelLine; + Line line = ml.GeometryCurve as Line; + Line line1 = RsRevitUtils.GetLongestSegmentLine(segments, line); + //var m = doc.GetElement(refer.ElementId); + + XYZ basepoint = uidoc.Selection.PickPoint(UserConstant.SnapAll, "请选择基准点(位于基准线上)"); + double alength = basepoint.DistanceTo(line.GetEndPoint(0)) + basepoint.DistanceTo(line.GetEndPoint(1)); + if (line.Length - alength > 0.001) + { + System.Windows.MessageBox.Show("请选择基准线上的点", "温馨提示"); + return Result.Cancelled; + } + //if (basepoint.IsAlmostEqualTo(ml.GeometryCurve.GetEndPoint(0)) || basepoint.IsAlmostEqualTo(ml.GeometryCurve.GetEndPoint(1))) + //{ + //} + var endp1 = line.GetEndPoint(0); + var endp2 = line.GetEndPoint(1); + var v1 = endp1 - basepoint; + var v2 = endp2 - basepoint; + var v0 = roompoint - basepoint; + List curves = new List(); + List instances = new List(); + //Curve currefer = null; + //Curve currefer1 = null; + + List pts = new List(); + List lastps = new List(); + XYZ zdir1 = null; + XYZ zdir2 = null; + XYZ offestvector = null; + + if (!v1.IsAlmostEqualTo(XYZ.Zero) && endp1.DistanceTo(basepoint) > interval) + { + //if (endp1.DistanceTo(basepoint) < interval) + //{ + // System.Windows.MessageBox.Show("基准点与基准线端点距离太近"); + // return Result.Cancelled; + //} + zdir1 = v1.CrossProduct(v0).Normalize(); + //偏移的方向,直线的侧方向 + offestvector = zdir1.CrossProduct(v1).Normalize(); + Line l1 = Line.CreateBound(basepoint, line.GetEndPoint(0)); + + for (int i = 0; i < 1000; i++) + { + var parameter = i * interval; + if (!l1.IsInside(parameter + lrdistance + interval / 2)) + { + break; + } + XYZ p = l1.Evaluate(parameter, false); + XYZ finalpoint = p + (l1.Direction * interval / 2) + (offestvector * fbdistance); + if (v2.IsAlmostEqualTo(XYZ.Zero)) + { + finalpoint = p + (l1.Direction * lrdistance) + (offestvector * fbdistance); + } + + pts.Add(finalpoint); + } + } + + if (!v2.IsAlmostEqualTo(XYZ.Zero) && endp2.DistanceTo(basepoint) > interval) + { + //if (endp2.DistanceTo(basepoint) < length) + //{ + // System.Windows.MessageBox.Show("基准点与基准线端点距离太近"); + // return Result.Cancelled; + //} + zdir2 = v2.CrossProduct(v0).Normalize(); + offestvector = zdir2.CrossProduct(v2).Normalize(); + var x = zdir2.CrossProduct(v2); + Line l2 = Line.CreateBound(basepoint, line.GetEndPoint(1)); + + for (int i = 0; i < 1000; i++) + { + var parameter = i * interval; + if (!l2.IsInside(parameter + lrdistance + interval / 2)) + { + break; + } + XYZ p = l2.Evaluate(parameter, false); + //附加的基准线的水平垂直偏移距离 + var finalpoint = p + (l2.Direction * interval / 2) + (offestvector * fbdistance); + if (v1.IsAlmostEqualTo(XYZ.Zero)) + { + finalpoint = p + (l2.Direction * lrdistance) + (offestvector * fbdistance); + } + + pts.Add(finalpoint); + } + //var lastl2 = pts.Last().DistanceTo(endp2); + } + + using (Transaction trans = new Transaction(doc, "载入布置灯具")) + { + trans.Start(); + //删除模型线 + doc.Delete(modelCurveIds); + family = RsRevitUtils.GetLoadedFamily(doc, UserConstant.LibraryPreDirectory + "Lamp\\成品吊灯.rfa"); + ElementId symbolId = family.GetFamilySymbolIds().FirstOrDefault(); + symbol = doc.GetElement(symbolId) as FamilySymbol; + symbol.Activate(); + foreach (var p in pts) + { + var fi = doc.Create + .NewFamilyInstance(p, symbol, baselevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + instances.Add(fi); + } + foreach (var p in lastps) + { + var fi = doc.Create + .NewFamilyInstance(p, symbol, baselevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + instances.Add(fi); + } + trans.Commit(); + } + using (Transaction trans = new Transaction(doc, "复制灯具")) + { + trans.Start(); + for (int i = 0; i < instances.Count; i++) + { + FamilyInstance fi = instances[i]; + int num = (int)Math.Floor((line1.Length - 2 * fbdistance) / interval); + double rem = line1.Length - num * interval; + for (int j = 1; j <= num; j++) + { + ElementTransformUtils.CopyElement(doc, fi.Id, offestvector * interval * j); + } + } + trans.Commit(); + } + + tg.Assimilate(); + } + catch (Autodesk.Revit.Exceptions.OperationCanceledException) + { + if (tg.GetStatus() == TransactionStatus.Started) + { + tg.RollBack(); + } + return Result.Cancelled; + } + } + return Result.Succeeded; + } + } +} \ No newline at end of file diff --git a/RookieStation/CmdPlaceReceptionArea.cs b/RookieStation/CmdPlaceReceptionArea.cs new file mode 100644 index 0000000..1d7424f --- /dev/null +++ b/RookieStation/CmdPlaceReceptionArea.cs @@ -0,0 +1,429 @@ +using Autodesk.Revit.DB; +using Autodesk.Revit.DB.Architecture; +using Autodesk.Revit.DB.Events; +using Autodesk.Revit.DB.Structure; +using Autodesk.Revit.UI; +using Autodesk.Revit.UI.Selection; +using RookieStation.Utils; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using System.Linq; +using System.Net; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media.Media3D; + +namespace RookieStation.ShippingAreaModule +{ + [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] + [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] + internal class CmdPlaceReceptionArea : IExternalCommand + { + /// + /// 选择一次后停止 + /// + private static bool PlaceSingleInstanceAbort = true; + + /// + /// revit窗口句柄 + /// + private IntPtr revitWindow; + + /// + /// 添加的元素 + /// + private List eleIdsAdded = new List(); + + public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) + { + UIApplication uiapp = commandData.Application; + UIDocument uidoc = uiapp.ActiveUIDocument; + Document doc = uidoc.Document; + revitWindow = uiapp.MainWindowHandle; + + WpfReceptionArea receptionAreaPlacement = CommonUtils.GenerateWindow(); + //初始值 + //基层厚度 + double base_layer_thickness = 15 / 304.8; + //踢脚线高度 + double Skirting_line_height = 50 / 304.8; + //踢脚线厚度 + double Skirting_line_thickness = 1.2 / 304.8; + //铝塑板长度 + double aluminum_plastic_panel_length = 1220 / 304.8; + //铝塑板高度 + double aluminum_plastic_panel_height = 2400 / 304.8; + //铝塑板厚度 + double aluminum_plastic_panel_thickness = 3 / 304.8; + //分缝 + double gap = 2 / 304.8; + //灰色乳胶漆厚度 + double grey_emulsion_paint_width = 1 / 304.8; + //发光字族类型 + string glow_text_symbol; + //墙间距 + double lamps_wall_distance = 900 / 304.8; + //灯间距 + double lamps_interval = 900 / 304.8; + + if (receptionAreaPlacement.DialogResult == true) + { + //铝塑板长度 + aluminum_plastic_panel_length = receptionAreaPlacement.aluminump_lastic_panel_length / 304.8; + //铝塑板高度 + aluminum_plastic_panel_height = receptionAreaPlacement.aluminump_lastic_panel_height / 304.8; + //分缝 + gap = receptionAreaPlacement.aluminump_lastic_panel_gap / 304.8; + + glow_text_symbol = receptionAreaPlacement.glow_text_symbol; + + lamps_wall_distance = receptionAreaPlacement.lamp_wall_distance / 304.8; + lamps_interval = receptionAreaPlacement.lamps_interval / 304.8; + } + else + { + return Result.Cancelled; + } + Level baselevel = uidoc.ActiveView.GenLevel; + Family family = null; + FamilySymbol symbol; + return doc.InvokeGroup(tg => + { + try + { + FamilySymbol linesymbol = RsRevitUtils.GetGuideSymbol(doc); + eleIdsAdded.Clear(); + uiapp.Application.DocumentChanged += Application_DocumentChanged; + uidoc.PromptForFamilyInstancePlacement(linesymbol); + uiapp.Application.DocumentChanged -= Application_DocumentChanged; + //在此处无法取消订阅 + //uiapp.Application.DocumentChanged -= Application_DocumentChanged; + } + catch (Autodesk.Revit.Exceptions.OperationCanceledException) + { + var interval = gap + aluminum_plastic_panel_length; + if (eleIdsAdded.Count == 0) + { + return Result.Cancelled; + } + Line refer_line = RsRevitUtils.GetGuideGeometryAndDeleteGuide(doc, eleIdsAdded); + uiapp.Application.DocumentChanged -= Application_DocumentChanged; + + double backgroundwall_length = refer_line.Length; + if (backgroundwall_length < 1500 / 304.8) + { + TaskDialog.Show("温馨提示", "距离太接"); + return Result.Cancelled; + } + List wallids = new List(); + WallType base_layer_type = null; + base_layer_thickness = RsRevitUtils.GetWallWidthByWallTypeName(doc, "阻燃板", out base_layer_type); + + WallType grey_emulsion_paint_type = null; + grey_emulsion_paint_width = RsRevitUtils.GetWallWidthByWallTypeName(doc, "灰色乳胶漆", out grey_emulsion_paint_type); + + WallType aluminum_plastic_panel_type = null; + aluminum_plastic_panel_thickness = RsRevitUtils.GetWallWidthByWallTypeName(doc, "铝塑板", out aluminum_plastic_panel_type); + + WallType Skirting_line_type = null; + Skirting_line_thickness = RsRevitUtils.GetWallWidthByWallTypeName(doc, "踢脚线", out Skirting_line_type); + //铝塑板块数 + int n = (int)Math.Floor(refer_line.Length / interval); + double rem = refer_line.Length % (gap + aluminum_plastic_panel_length); + if (base_layer_type == null || aluminum_plastic_panel_type == null || Skirting_line_type == null || grey_emulsion_paint_type == null) + { + TaskDialog.Show("温馨提示", "需要新建装饰所需的墙类型,类型名称需分别包含阻燃板,灰色乳胶漆,铝塑板,踢脚线"); + return Result.Cancelled; + } + doc.Invoke(ts => + { + //长度不满足设置的铝塑板长度时 + if (n == 0) + { + var offestline = refer_line.CreateOffset(aluminum_plastic_panel_thickness / 2 + base_layer_thickness, -XYZ.BasisZ); + var wall = Wall.Create(doc, offestline, aluminum_plastic_panel_type.Id, doc.ActiveView.GenLevel.Id, aluminum_plastic_panel_height, Skirting_line_height, false, false); + wallids.Add(wall.Id); + } + else + { + for (int i = 0; i < n + 1; i++) + { + var startpoint = refer_line.Evaluate(i * interval, false); + var endpoint = refer_line.Evaluate(((i + 1) * interval) - gap, false); + + if (i == n) + { + endpoint = refer_line.GetEndPoint(1); + } + Line line = Line.CreateBound(startpoint, endpoint); + var offestline = line.CreateOffset(aluminum_plastic_panel_thickness / 2 + base_layer_thickness, -XYZ.BasisZ); + var wall = Wall.Create(doc, offestline, aluminum_plastic_panel_type.Id, doc.ActiveView.GenLevel.Id, aluminum_plastic_panel_height, Skirting_line_height, false, false); + //不允许连接 + WallUtils.DisallowWallJoinAtEnd(wall, 0); + //curves.Add() + wallids.Add(wall.Id); + } + } + + var skirting_offestline = refer_line.CreateOffset(Skirting_line_thickness / 2 + base_layer_thickness, -XYZ.BasisZ); + var skirtingwall = Wall.Create(doc, skirting_offestline, Skirting_line_type.Id, doc.ActiveView.GenLevel.Id, Skirting_line_height, 0, false, false); + wallids.Add(skirtingwall.Id); + + var base_layer_offestline = refer_line.CreateOffset(base_layer_thickness / 2, -XYZ.BasisZ); + var baselayerwall = Wall.Create(doc, base_layer_offestline, base_layer_type.Id, doc.ActiveView.GenLevel.Id, UserConstant.Height / 304.8, 0, false, false); + wallids.Add(baselayerwall.Id); + //高度大于3000才有灰色乳胶漆 + if (UserConstant.Height > 3000) + { + double baseheight = aluminum_plastic_panel_height + Skirting_line_height; + var grey_emulsion_paint_offestline = refer_line.CreateOffset(base_layer_thickness + grey_emulsion_paint_width / 2, -XYZ.BasisZ); + var greypaintwall = Wall.Create(doc, grey_emulsion_paint_offestline, grey_emulsion_paint_type.Id, doc.ActiveView.GenLevel.Id, UserConstant.Height / 304.8 - baseheight, baseheight, false, false); + wallids.Add(greypaintwall.Id); + } + + doc.Regenerate(); + doc.Create.NewGroup(wallids); + }, "背景墙创建"); + + //SelectFilter wallfilter = new SelectFilter(); + //var wallrefer = uidoc.Selection.PickObject(ObjectType.Element, wallfilter, "请选择作为背景墙的墙体"); + //var wall = doc.GetElement(wallrefer) as Wall; + + //WallFaceSelectionFilter selfilter = new WallFaceSelectionFilter(wall.Id); + //var facerefer = uidoc.Selection.PickObject(ObjectType.Face, selfilter, "请选择要装饰的墙面"); + + //PlanarFace pf = wall.GetGeometryObjectFromReference(facerefer) as PlanarFace; + + //XYZ normal = pf.FaceNormal; + //XYZ p1 = uidoc.Selection.PickObject(ObjectType.PointOnElement, selfilter, "请选取背景墙左侧端点").GlobalPoint; + + //XYZ p2 = uidoc.Selection.PickObject(ObjectType.PointOnElement, selfilter, "请选取背景墙右侧端点").GlobalPoint; + + //XYZ p1 = uidoc.Selection.PickPoint(UserConstant.SnapAll, "请选取背景墙左侧端点"); + //XYZ p2 = uidoc.Selection.PickPoint(UserConstant.SnapAll, "请选取背景墙右侧端点"); + + //两点的水平距离 + + //if (UserConstant.Height / 3 * 2 < 2200) + //{ + // TaskDialog.Show("温馨提示", "层高设置有误"); + // return Result.Cancelled; + //} + + #region 菜鸟使命布置 + + FamilyInstance signage = null; + doc.Invoke(ts => + { + family = RsRevitUtils.GetLoadedFamily(doc, UserConstant.LibraryPreDirectory + "Sign\\菜鸟使命.rfa"); + ElementId symbolId = family.GetFamilySymbolIds().FirstOrDefault(); + symbol = doc.GetElement(symbolId) as FamilySymbol; + symbol.Activate(); + + //var x = family.FamilyPlacementType; + //signage = doc.Create.NewFamilyInstance(facerefer, p2 + new XYZ(0, 0, height + 100 / 304.8), symbol, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + + var endpoint = refer_line.GetEndPoint(0); + + endpoint += (Skirting_line_height + aluminum_plastic_panel_height) * XYZ.BasisZ; + signage = doc.Create.NewFamilyInstance(endpoint, symbol, StructuralType.NonStructural); + //标准面要朝上,族要面向背侧 + + //symbol.GetParameters("背景墙长度").FirstOrDefault().Set(distance); + }, "菜鸟的使命"); + doc.Invoke(ts => + { + //族的正面要超前 + RsRevitUtils.AdjustInstance(doc, signage, refer_line, grey_emulsion_paint_width + base_layer_thickness); + }, "调整菜鸟使命"); + + #endregion 菜鸟使命布置 + + double reception_length = refer_line.Length / 3 * 2; + double reception_wall_distance = 1000 / 304.8; + FamilyInstance reception = null; + doc.Invoke(ts => + { + family = RsRevitUtils.GetLoadedFamily(doc, UserConstant.LibraryPreDirectory + "Furniture\\寄件接待台.rfa"); + ElementId symbolId = family.GetFamilySymbolIds().FirstOrDefault(); + symbol = doc.GetElement(symbolId) as FamilySymbol; + symbol.Activate(); + var wall_center_point = refer_line.Evaluate(0.5, true); + + reception = doc.Create.NewFamilyInstance(wall_center_point, symbol, baselevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + + symbol.GetParameters("台面长度").FirstOrDefault().Set(reception_length); + //symbol.GetParameters("台面长度").FirstOrDefault().AsDouble(); + }, "接待台布置"); + doc.Invoke(ts => + { + RsRevitUtils.AdjustInstance(doc, reception, refer_line, reception_wall_distance); + }, "调整接待台"); + + FamilyInstance logo = null; + doc.Invoke(ts => + { + family = RsRevitUtils.GetLoadedFamily(doc, UserConstant.LibraryPreDirectory + "Sign\\菜鸟LOGO.rfa"); + ElementId symbolId = family.GetFamilySymbolIds().FirstOrDefault(id => doc.GetElement(id).Name == glow_text_symbol); + symbol = doc.GetElement(symbolId) as FamilySymbol; + symbol.Activate(); + var wall_center_point = refer_line.Evaluate(0.5, true); + + logo = doc.Create.NewFamilyInstance(wall_center_point, symbol, baselevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + + //symbol.GetParameters("背景墙长度").FirstOrDefault().Set(reception_length); + //width = symbol.GetParameters("台面宽度").FirstOrDefault().AsDouble(); + }, "菜鸟LOG布置"); + doc.Invoke(ts => + { + RsRevitUtils.AdjustInstance(doc, logo, refer_line, aluminum_plastic_panel_thickness + base_layer_thickness); + }, "调整lOGO"); + + doc.Invoke(ts => + { + family = RsRevitUtils.GetLoadedFamily(doc, UserConstant.LibraryPreDirectory + "Lamp\\圆形吊灯.rfa"); + ElementId symbolId = family.GetFamilySymbolIds().FirstOrDefault(); + symbol = doc.GetElement(symbolId) as FamilySymbol; + symbol.Activate(); + var normal_direction = refer_line.Direction; + List lamp_location_points = new List(); + var lamps_location_line = refer_line.CreateOffset(lamps_wall_distance, -XYZ.BasisZ); + var center_point = lamps_location_line.Evaluate(0.5, true); + n = (int)Math.Floor(backgroundwall_length / lamps_interval); + //单侧的数量 + int m = (int)Math.Floor((n + 1.0) / 2); + if ((n + 1) % 2 == 0) + { + //开始间隔为0.5 + for (int i = 0; i < m; i++) + { + XYZ p = center_point.Add(normal_direction * (i + 0.5) * lamps_interval); + XYZ reversep = center_point.Add(-normal_direction * (i + 0.5) * lamps_interval); + + lamp_location_points.Add(p); + lamp_location_points.Add(reversep); + } + foreach (XYZ p in lamp_location_points) + { + doc.Create.NewFamilyInstance(p, symbol, baselevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + } + } + else + { + lamp_location_points.Add(center_point); + //i=0时居中,不在单侧,开始间隔为1 + for (int i = 0; i < m; i++) + { + XYZ p = center_point.Add(normal_direction * (i + 1) * lamps_interval); + XYZ reversep = center_point.Add(-normal_direction * (i + 1) * lamps_interval); + lamp_location_points.Add(p); + lamp_location_points.Add(reversep); + } + foreach (XYZ p in lamp_location_points) + { + doc.Create.NewFamilyInstance(p, symbol, baselevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + } + } + }, "吊灯布置"); + + //doc.Invoke(ts => + //{ + // if (backgroundwall.CanFlipFacing && backgroundwall.CanFlipHand && !backgroundwall.FacingOrientation.IsAlmostEqualTo(normal)) + // { + // backgroundwall.flipFacing(); + // backgroundwall.flipHand(); + // } + // if (frontdesk.CanFlipFacing && backgroundwall.CanFlipHand && !frontdesk.FacingOrientation.IsAlmostEqualTo(normal)) + // { + // frontdesk.flipFacing(); + // frontdesk.flipHand(); + // } + //}, "调整"); + } + + return Result.Succeeded; + }, "前台布置"); + } + + private void Application_DocumentChanged(object sender, DocumentChangedEventArgs e) + { + ICollection idsAdded = e.GetAddedElementIds(); + int n = idsAdded.Count; + eleIdsAdded.AddRange(idsAdded); + if (PlaceSingleInstanceAbort && n == 1) + { + //KeyPress.OneKey(revitWindow, (char)System.Windows.Forms.Keys.Escape); + KeyPress.PostMessage(revitWindow, (uint)KeyPress.KEYBOARD_MSG.WM_KEYDOWN, (uint)System.Windows.Forms.Keys.Escape, 0); + KeyPress.PostMessage(revitWindow, (uint)KeyPress.KEYBOARD_MSG.WM_KEYDOWN, (uint)System.Windows.Forms.Keys.Escape, 0); + } + } + + private Face GetPlaceFaceOfWall(Wall wall, XYZ normal) + { + Face face = null; + Options geomOptions = new Options(); + geomOptions.ComputeReferences = true; + GeometryElement wallGeom = wall.get_Geometry(geomOptions); + + foreach (GeometryObject geomObj in wallGeom) + { + Solid geomSolid = geomObj as Solid; + if (null != geomSolid) + { + foreach (Face geomFace in geomSolid.Faces) + { + if (geomFace.ComputeNormal(geomFace.Reference.UVPoint).IsAlmostEqualTo(normal)) + { + face = geomFace; + } + + break; + } + break; + } + } + return face; + } + + private Reference GetWallSideFaceReference(Wall wall, XYZ normal) + { + var facerefer = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Interior).FirstOrDefault(); + var facerefer1 = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Exterior).FirstOrDefault(); + + PlanarFace pf = wall.GetGeometryObjectFromReference(facerefer) as PlanarFace; + if (pf.FaceNormal.IsAlmostEqualTo(normal)) + { + return facerefer; + } + else + { + return facerefer1; + } + } + + public class WallFaceSelectionFilter : ISelectionFilter + { + private ElementId eid = null; + + public WallFaceSelectionFilter(ElementId elementId) + { + eid = elementId; + } + + public bool AllowElement(Element element) + { + return element is Wall && eid == element.Id; + } + + public bool AllowReference(Reference refer, XYZ point) + { + return true; + } + } + } +} \ No newline at end of file diff --git a/RookieStation/CmdPlaceShelves.cs b/RookieStation/CmdPlaceShelves.cs new file mode 100644 index 0000000..3cb0e9a --- /dev/null +++ b/RookieStation/CmdPlaceShelves.cs @@ -0,0 +1,560 @@ +using Autodesk.Revit.DB; +using Autodesk.Revit.DB.Architecture; +using Autodesk.Revit.UI; +using RookieStation.Utils; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Windows; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar; + +namespace RookieStation.PackAreaModule +{ + [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] + [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] + internal class CmdPlaceShelves : IExternalCommand + { + /// + /// 当前编号 + /// + private int currentnum = 1; + + /// + /// 选择一次后停止 + /// + //private static bool PlaceSingleInstanceAbort = true; + + /// + /// revit窗口句柄 + /// + private IntPtr revitWindow; + + /// + /// 添加的元素 + /// + private List eleIdsAdded = new List(); + + public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) + { + UIApplication uiapp = commandData.Application; + UIDocument uidoc = uiapp.ActiveUIDocument; + Document doc = uidoc.Document; + revitWindow = uiapp.MainWindowHandle; + WpfShelvesLayout placement = CommonUtils.GenerateWindow(); + + if (placement.DialogResult != true) + { + return Result.Cancelled; + } + ShelvesPlacementViewModel vm = placement.vm; + ObservableCollection shelves = vm.Data; + + Level level = uidoc.ActiveView.GenLevel; + + return doc.InvokeGroup(tg => + { + try + { + //定位线 + FamilySymbol guide_Symbol = RsRevitUtils.GetGuideSymbol(doc); + + eleIdsAdded.Clear(); + uiapp.Application.DocumentChanged += Application_DocumentChanged; + uidoc.PromptForFamilyInstancePlacement(guide_Symbol); + uiapp.Application.DocumentChanged -= Application_DocumentChanged; + } + catch (Autodesk.Revit.Exceptions.OperationCanceledException) + { + if (eleIdsAdded.Count == 0) + { + return Result.Cancelled; + } + Line refer_line = RsRevitUtils.GetGuideGeometryAndDeleteGuide(doc, eleIdsAdded); + uiapp.Application.DocumentChanged -= Application_DocumentChanged; + //始终位于左侧,Z轴朝上 + var zaxis = XYZ.BasisZ; + Family shelf_family = null; + FamilySymbol shelf_symbol = null; + double shelf_spacing = vm.Spacing / 304.8; + //通道宽度 + double passage_width = vm.PassageWidth / 304.8; + double parallel_referline_offest = vm.ParalelReferOffest / 304.8; + double vertical_referline_offest = vm.VerticalReferOffest / 304.8; + + for (int i = 0; i < shelves.Count; i++) + { + //List all_points = new List(); + List first_row_points = new List(); + Shelf shelf = shelves[i]; + double shelf_width = shelf.Width / 304.8; + double line_parameter = 0.0; + int n = 100;//循环次数 + XYZ p = XYZ.Zero; + + if (parallel_referline_offest < 0.001)//起点无间距 + { + for (int j = 0; j < n; j++) + { + if (!refer_line.IsInside((line_parameter + shelf_width))) + { + break; + } + + if (j % 2 == 0) + { + p = refer_line.Evaluate(line_parameter, false); + line_parameter += shelf_spacing + shelf_width; + } + else + { + p = refer_line.Evaluate(line_parameter, false); + line_parameter += shelf_width; + } + + first_row_points.Add(p); + } + } + else//起点有距离 + { + line_parameter = parallel_referline_offest; + + for (int j = 0; j < n; j++) + { + if (!refer_line.IsInside(line_parameter + shelf_width)) + { + break; + } + if (j % 2 == 0) + { + p = refer_line.Evaluate(line_parameter, false); + line_parameter += shelf_width; + } + else + { + p = refer_line.Evaluate(line_parameter, false); + line_parameter += shelf_spacing + shelf_width; + } + + first_row_points.Add(p); + } + } + double l = shelf.Length / 304.8; + XYZ normal_vertical_offest_vector = zaxis.CrossProduct(refer_line.Direction).Normalize(); + List instances = new List(); + + XYZ final_point = XYZ.Zero; + doc.Invoke(ts => + { + shelf_family = RsRevitUtils.GetLoadedFamily(doc, UserConstant.LibraryPreDirectory + "Shelf\\单联货架.rfa"); + var shelf_symbol_ids = shelf_family.GetFamilySymbolIds(); + foreach (var id in shelf_symbol_ids) + { + FamilySymbol temp_symbol = doc.GetElement(id) as FamilySymbol; + if (temp_symbol.Name == shelf.SymbolName) + { + shelf_symbol = temp_symbol; + break; + } + } + shelf_symbol.Activate(); + }, "加载货架,激活类型"); + + switch (shelf.NumOfGroup) + { + case NumOfGroup.Single: + + for (int j = 0; j < first_row_points.Count; j++) + { + XYZ pt = first_row_points[j]; + XYZ offest_direction = normal_vertical_offest_vector * (vertical_referline_offest + l / 2); + //垂直基准线平移 平行基准线平移 + final_point = pt + offest_direction + refer_line.Direction * shelf_width / 2; + //附加通道和(单联、多联)货架长度的偏移 + if (i > 0) + { + double total_length = GetTotalLength(shelves, i); + //附加排在前面通道和所有货架的长度 + XYZ additional_dir = normal_vertical_offest_vector * (i * passage_width + total_length); + final_point += additional_dir; + } + FamilyInstance instance = null; + //all_points.Add(final_point); + doc.Invoke(ts => + { + instance = doc.Create.NewFamilyInstance(final_point, shelf_symbol, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + instances.Add(instance); + }, "创建货架"); + + //位于直线右侧时,需要进行左右翻转 + doc.Invoke(ts => + { + if (parallel_referline_offest < 0.001) + { + if (j % 2 != 0 && instance.CanFlipHand) + { + instance.flipHand(); + } + } + else + { + if (j % 2 == 0 && instance.CanFlipHand) + { + instance.flipHand(); + } + } + }, "翻转货架"); + } + + break; + + case NumOfGroup.Double: + + for (int j = 0; j < first_row_points.Count; j++) + { + XYZ pt = first_row_points[j]; + //偏移距离 + XYZ offest_direction = normal_vertical_offest_vector * (vertical_referline_offest + l); + //基础偏移距离,移动半个长度到直线的一侧,垂直基准线平移 平行基准线平移 + final_point = pt + offest_direction + refer_line.Direction * shelf_width / 2; + //附加通道和(单联、多联)货架长度的偏移 + if (i > 0) + { + double totallength = GetTotalLength(shelves, i); + + XYZ additionaldir = normal_vertical_offest_vector * (i * passage_width + totallength); + final_point += additionaldir; + } + FamilyInstance end_instance = null; + FamilyInstance start_instance = null; + doc.Invoke(ts => + { + end_instance = doc.Create.NewFamilyInstance(final_point + l / 2 * normal_vertical_offest_vector, shelf_symbol, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + + start_instance = doc.Create.NewFamilyInstance(final_point - l / 2 * normal_vertical_offest_vector, shelf_symbol, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + + instances.Add(start_instance); + + instances.Add(end_instance); + }, "创建货架"); + doc.Invoke(ts => + { + if (parallel_referline_offest < 0.001) + { + if (j % 2 != 0 && start_instance.CanFlipHand && end_instance.CanFlipHand) + { + start_instance.flipHand(); + end_instance.flipHand(); + } + } + else + { + if (j % 2 == 0 && start_instance.CanFlipHand && end_instance.CanFlipHand) + { + start_instance.flipHand(); + end_instance.flipHand(); + } + } + }, "翻转货架"); + + //all_points.Add(final_point + l / 2 * normal_vertical_offest_vector); + //all_points.Add(final_point - l / 2 * normal_vertical_offest_vector); + } + break; + + case NumOfGroup.Three: + + for (int j = 0; j < first_row_points.Count; j++) + { + XYZ pt = first_row_points[j]; + XYZ offestdir = normal_vertical_offest_vector * (vertical_referline_offest + l * 3 / 2); + //垂直基准线平移 平行基准线平移 + final_point = pt + offestdir + refer_line.Direction * shelf_width / 2; + //附加通道和(单联、多联)货架长度的偏移 + if (i > 0) + { + double totallength = GetTotalLength(shelves, i); + XYZ additionaldir = normal_vertical_offest_vector * (i * passage_width + totallength); + final_point += additionaldir; + } + FamilyInstance end_instance = null; + FamilyInstance center_instance = null; + FamilyInstance start_instance = null; + doc.Invoke(ts => + { + center_instance = doc.Create.NewFamilyInstance(final_point, shelf_symbol, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + end_instance = doc.Create.NewFamilyInstance(final_point + l * normal_vertical_offest_vector, shelf_symbol, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + start_instance = doc.Create.NewFamilyInstance(final_point - l * normal_vertical_offest_vector, shelf_symbol, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + instances.Add(center_instance); + instances.Add(end_instance); + instances.Add(start_instance); + }, "创建货架"); + doc.Invoke(ts => + { + if (parallel_referline_offest < 0.001) + { + if (j % 2 != 0 && start_instance.CanFlipHand && center_instance.CanFlipHand && end_instance.CanFlipHand) + { + start_instance.flipHand(); + center_instance.flipHand(); + end_instance.flipHand(); + } + } + else + { + if (j % 2 == 0 && start_instance.CanFlipHand && center_instance.CanFlipHand && end_instance.CanFlipHand) + { + start_instance.flipHand(); + center_instance.flipHand(); + end_instance.flipHand(); + } + } + }, "翻转货架"); + } + break; + + default: + break; + } + + List card_instances = new List(); + + doc.Invoke(ts => + { + XYZ veroffestdir = zaxis.CrossProduct(refer_line.Direction).Normalize(); + //旋转角度 + double angle = XYZ.BasisY.AngleTo(veroffestdir); + //判断相对于Y轴是正向角度(逆时针)还是逆向角度(顺时针) + var z = veroffestdir.CrossProduct(XYZ.BasisY).Normalize(); + if (z.IsAlmostEqualTo(XYZ.BasisZ)) + { + //逆向旋转,角度取负值 + angle = -angle; + } + + for (int j = 0; j < instances.Count; j++) + { + FamilyInstance instance = instances[j]; + var location_XYZ = RsRevitUtils.GetXYZByElement(instance); + + Line zline = Line.CreateUnbound(location_XYZ, XYZ.BasisZ); + //旋转,移动 + ElementTransformUtils.RotateElement(doc, instance.Id, zline, angle); + //旋转后的 + var hand_orientationd = instance.HandOrientation; + //货架左右切换时 + if (instance.HandFlipped) + { + hand_orientationd = -hand_orientationd; + } + ////垂直基准线平移 + //ElementTransformUtils.MoveElement(doc, fi.Id, offestdir); + + ////平行基准线平移 + //ElementTransformUtils.MoveElement(doc, fi.Id, line.Direction * w / 2); + //if (i >= 1) + //{ + // XYZ additionaldir = zdir.CrossProduct(line.Direction).Normalize() * i * (passagewidth + l); + // ElementTransformUtils.MoveElement(doc, fi.Id, additionaldir); + //} + + #region 布置端牌 + + FamilyInstance front_instance = null; + + Reference front_face = instance.GetReferences(FamilyInstanceReferenceType.Front).FirstOrDefault(); + PlaceCard(doc, location_XYZ, instance, hand_orientationd, front_face, out front_instance); + if (front_instance.CanFlipWorkPlane) + { + front_instance.IsWorkPlaneFlipped = true; + } + card_instances.Add(front_instance); + + FamilyInstance back_instance = null; + + Reference back_face = instance.GetReferences(FamilyInstanceReferenceType.Back).FirstOrDefault(); + + PlaceCard(doc, location_XYZ, instance, -hand_orientationd, back_face, out back_instance); + card_instances.Add(back_instance); + switch (shelf.NumOfGroup) + { + case NumOfGroup.Single: + + front_instance.GetParameters("货架号").FirstOrDefault().Set(string.Format("{0}", currentnum)); + back_instance.GetParameters("货架号").FirstOrDefault().Set(string.Format("{0}", currentnum)); + currentnum += 1; + break; + + case NumOfGroup.Double: + //根据组合加上组合数 + if (j % 2 == 0 && j != 0) + { + currentnum += 2; + } + front_instance.GetParameters("货架号").FirstOrDefault().Set(string.Format("{0}{1}{2}", currentnum, "~", currentnum + 1)); + back_instance.GetParameters("货架号").FirstOrDefault().Set(string.Format("{0}{1}{2}", currentnum, "~", currentnum + 1)); + //最后一个需要加上组合数作为下一列的开始 + if (j == instances.Count - 1) + { + currentnum += 2; + } + break; + + case NumOfGroup.Three: + //根据组合加上组合数 + if (j % 3 == 0 && j != 0) + { + currentnum += 3; + } + front_instance.GetParameters("货架号").FirstOrDefault().Set(string.Format("{0}{1}{2}", currentnum, "~", currentnum + 2)); + back_instance.GetParameters("货架号").FirstOrDefault().Set(string.Format("{0}{1}{2}", currentnum, "~", currentnum + 2)); + //最后一个需要加上组合数作为下一列的开始 + if (j == instances.Count - 1) + { + currentnum += 3; + } + break; + + default: + break; + } + + #endregion 布置端牌 + + //Reference backface = fi.GetReferences(FamilyInstanceReferenceType.Back).FirstOrDefault(); + //if (a.Contains("606:SURFACE")) + //{ + // hand = -fi.HandOrientation; + //} + } + }, "调整货架角度及布置端牌"); + + DeleteCards(doc, card_instances); + } + } + return Result.Succeeded; + }, "布置货架及端牌"); + } + + /// + /// 删除多余端牌 + /// + /// + /// + private void DeleteCards(Document doc, List card_instances) + { + using (Transaction ts = new Transaction(doc, "删除多余端牌")) + { + ts.Start(); + List ids_delete = new List(); + + foreach (var ins in card_instances) + { + var lp = RsRevitUtils.GetXYZByElement(ins); + foreach (var card in card_instances) + { + var lpt = RsRevitUtils.GetXYZByElement(card); + if (!card.Id.Equals(ins.Id) && lp.IsAlmostEqualTo(lpt)) + { + ids_delete.Add(ins.Id); + ids_delete.Add(card.Id); + + break; + } + } + } + doc.Delete(ids_delete); + + ts.Commit(); + } + } + + private void Application_DocumentChanged(object sender, Autodesk.Revit.DB.Events.DocumentChangedEventArgs e) + { + ICollection idsAdded = e.GetAddedElementIds(); + int n = idsAdded.Count; + //List eles = new List(); + //foreach (var id in idsAdded) + //{ + // eles.Add(e.GetDocument().GetElement(id)); + //} + eleIdsAdded.AddRange(idsAdded); + //if (PlaceSingleInstanceAbort && n == 1) + if (n == 1) + { + KeyPress.PostMessage(revitWindow, (uint)KeyPress.KEYBOARD_MSG.WM_KEYDOWN, (uint)System.Windows.Forms.Keys.Escape, 0); + KeyPress.PostMessage(revitWindow, (uint)KeyPress.KEYBOARD_MSG.WM_KEYDOWN, (uint)System.Windows.Forms.Keys.Escape, 0); + //KeyPress.OneKey(revitWindow, (char)System.Windows.Forms.Keys.Escape); + } + } + + /// + /// 布置端牌 + /// + /// + /// + /// + /// 左右方向 + /// + /// + private void PlaceCard(Document doc, XYZ p, FamilyInstance fi, XYZ handOrientation, Reference facereference, out FamilyInstance card_instance) + { + var shelfwidth = fi.Symbol.GetParameters("宽度").FirstOrDefault().AsDouble(); + + Family card = RsRevitUtils.GetLoadedFamily(doc, UserConstant.LibraryPreDirectory + "Shelf\\货架端牌.rfa"); + var cardsymbolIds = card.GetFamilySymbolIds(); + + FamilySymbol cardsymbol = null; + foreach (ElementId syid in cardsymbolIds) + { + var sy = doc.GetElement(syid) as FamilySymbol; + var cardwidth = sy.GetParameters("宽度").FirstOrDefault().AsDouble(); + if (cardwidth == shelfwidth) + { + cardsymbol = sy; + } + } + if (!cardsymbol.IsActive) + { + cardsymbol.Activate(); + } + card_instance = doc.Create.NewFamilyInstance(facereference, p, handOrientation, cardsymbol); + } + + /// + /// 获取该行之前的所有货架长度总和(英制) + /// + /// + /// 行数大于1即i>0 + /// + private double GetTotalLength(ObservableCollection shelves, int i) + { + double totallength = 0.0; + for (int j = 0; j < i; j++) + { + switch (shelves[j].NumOfGroup) + { + case NumOfGroup.Single: + totallength += shelves[j].Length; + break; + + case NumOfGroup.Double: + totallength += shelves[j].Length * 2; + break; + + case NumOfGroup.Three: + totallength += shelves[j].Length * 3; + break; + + default: + break; + } + } + + return totallength / 304.8; + } + } +} \ No newline at end of file diff --git a/RookieStation/CmdPlaceWallFinishes.cs b/RookieStation/CmdPlaceWallFinishes.cs new file mode 100644 index 0000000..17dada1 --- /dev/null +++ b/RookieStation/CmdPlaceWallFinishes.cs @@ -0,0 +1,168 @@ +using Autodesk.Revit.DB; +using Autodesk.Revit.DB.Architecture; +using Autodesk.Revit.UI; +using Autodesk.Revit.UI.Selection; +using RookieStation.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.ConstrainedExecution; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Effects; + +namespace RookieStation.CommonTools +{ + [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] + [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] + internal class CmdPlaceWallFinishes : 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; + + List rooms = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).Cast().ToList(); + if (rooms.Count == 0) + { + TaskDialog.Show("温馨提示", "项目中当前没有房间"); + return Result.Cancelled; + } + ElementCategoryFilter ecf = new ElementCategoryFilter(BuiltInCategory.OST_Walls); + ElementCategoryFilter ecf1 = new ElementCategoryFilter(BuiltInCategory.OST_StackedWalls); + LogicalOrFilter lof = new LogicalOrFilter(ecf, ecf1); + var walltypes = new FilteredElementCollector(doc).WherePasses(lof).WhereElementIsElementType().Cast().ToList(); + WpfWallFinishes finishes = null; + + string addin_path = typeof(RsApp).Assembly.Location; + string assembly_directory = System.IO.Path.GetDirectoryName(addin_path); + AssemblyLoader loader = new AssemblyLoader(assembly_directory); + try + { + loader.HookAssemblyResolve(); + + finishes = new WpfWallFinishes(walltypes); + System.Windows.Interop.WindowInteropHelper mainUI = new System.Windows.Interop.WindowInteropHelper(finishes) + { + Owner = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle + }; + finishes.ShowDialog(); + } + catch (Exception ex) + { + TaskDialog.Show("错误", ex.Message); + } + finally + { + loader.UnhookAssemblyResolve(); + } + if (finishes.DialogResult != true) + { + return Result.Cancelled; + } + WallType walltype = finishes.WallType; + bool iscontinue = true; + try + { + while (iscontinue) + { + Reference refer = uidoc.Selection.PickObject(ObjectType.Element, new SelectFilter(), "请选择布置的房间"); + //walltype包含了叠层墙和基本墙,属于不同族,如果出现名称一样,则会过滤出来两个 + //var walltypes = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).OfClass(typeof(WallType)).WhereElementIsElementType(); + + //var walls = new FilteredElementCollector(doc).OfClass(typeof(Wall)); + //var walltype = walltypes.Where(x => x.Name == "常规 - 200mm").FirstOrDefault() as WallType; + + Room room = uidoc.Document.GetElement(refer) as Room; + List curveLoopList = new List(); + List walltojoin = new List(); + List> walltojoinlist = new List>(); + var opts = new SpatialElementBoundaryOptions(); + //{ + // SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish + //}; + double wallwidth = walltype.Width; + double wallheight = finishes.WallHeight; + //BuiltInCategory builtInCategory = (BuiltInCategory)walltype.Category.Id.IntegerValue; + //if (walltype.Kind == WallKind.Stacked) + //{ + // var li = walltype.GetSubelements(); + // walltype.get + //} + //if (walltype.Kind == WallKind.Basic) + //{ + // var compounds = walltype.GetCompoundStructure(); + // for (int i = 0; i < compounds.LayerCount; i++) + // { + // offest += compounds.GetWidth(); + // } + //} + + var segementsList = room.GetBoundarySegments(opts); + + if (segementsList != null) + { + foreach (var boundarySegments in segementsList) + { + CurveLoop curveLoop = new CurveLoop(); + foreach (var boundarySegment in boundarySegments) + { + curveLoop.Append(boundarySegment.GetCurve()); + walltojoin.Add(boundarySegment.ElementId); + } + walltojoinlist.Add(walltojoin); + curveLoopList.Add(curveLoop); + } + } + + doc.Invoke(ts => + { + Plane plane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, new XYZ()); + //var mc = doc.Create.NewModelCurveArray(array, SketchPlane.Create(doc, plane)); + for (int i = 0; i < curveLoopList.Count; i++) + { + //切线方向叉乘参数中的向量,内侧叉乘-z + var offestcurveloop = CurveLoop.CreateViaOffset(curveLoopList[i], wallwidth / 2, -XYZ.BasisZ); + for (int j = 0; j < offestcurveloop.Count(); j++) + { + Curve curve = offestcurveloop.ElementAt(j); + ////c的方向叉乘参数中的向量,内侧叉乘-z + //var lc = c.CreateOffset(100 / 304.8, -XYZ.BasisZ); + + //var x = curve.ComputeDerivatives(0.5, true).BasisX.CrossProduct(-XYZ.BasisZ).Normalize() * 100 / 304.8; + //var mc = doc.Create.NewModelCurve(lc, SketchPlane.Create(doc, plane)); + //var mc = doc.Create.NewModelCurve(c, SketchPlane.Create(doc, plane)); + var w = Wall.Create(doc, curve, walltype.Id, doc.ActiveView.GenLevel.Id, wallheight / 304.8, 0 / 304.8, false, false); + w.get_Parameter(BuiltInParameter.WALL_ATTR_ROOM_BOUNDING).Set(0); + doc.Regenerate(); + //让门窗可以剪切出来 + if (walltojoinlist[i][j].IntegerValue > 0) + { + Element elemtojoin = doc.GetElement(walltojoinlist[i][j]); + try + { + JoinGeometryUtils.JoinGeometry(doc, elemtojoin, w); + } + catch (Exception) + { + } + } + + //WallUtils.AllowWallJoinAtEnd(w, 0); + //offestcurves.Add(lc); + } + } + }, "创建墙饰面"); + } + } + catch (Autodesk.Revit.Exceptions.OperationCanceledException) + { + return Result.Succeeded; + } + + return Result.Succeeded; + } + } +} \ No newline at end of file diff --git a/RookieStation/CmdProjectSettings.cs b/RookieStation/CmdProjectSettings.cs new file mode 100644 index 0000000..92c1a3b --- /dev/null +++ b/RookieStation/CmdProjectSettings.cs @@ -0,0 +1,31 @@ +using Autodesk.Revit.DB; +using Autodesk.Revit.UI; +using Autodesk.Revit.UI.Selection; +using RookieStation.Utils; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RookieStation +{ + [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] + [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] + internal class CmdProjectSettings : 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; + string AddInPath = typeof(CmdProjectSettings).Assembly.Location; + string dirAssembly = Path.GetDirectoryName(AddInPath); + AssemblyLoader loader = new AssemblyLoader(dirAssembly); + WpfProjectSettings settings = CommonUtils.GenerateWindow(); + + return Result.Succeeded; + } + } +} \ No newline at end of file diff --git a/RookieStation/Custom/Enum.cs b/RookieStation/Custom/Enum.cs new file mode 100644 index 0000000..7f4dd98 --- /dev/null +++ b/RookieStation/Custom/Enum.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RookieStation +{ + public enum NumOfGroup + { + [Description("单个")] + Single = 0, + + [Description("双联")] + Double = 1, + + [Description("三联")] + Three = 3, + } + + public enum LengthType + { + [Description("1000")] + x1000 = 1, + + [Description("1200")] + x1200 = 2, + + [Description("1500")] + x1500 = 3, + + [Description("2000")] + x2000 = 4, + } + + public enum WidthType + { + [Description("400")] + x400 = 1, + + [Description("500")] + x500 = 2, + + [Description("600")] + x600 = 3, + } +} \ No newline at end of file diff --git a/RookieStation/Custom/Shelf.cs b/RookieStation/Custom/Shelf.cs new file mode 100644 index 0000000..4130ab7 --- /dev/null +++ b/RookieStation/Custom/Shelf.cs @@ -0,0 +1,40 @@ +using RookieStation.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RookieStation +{ + public class Shelf + { + //public bool IsSelected { get; set; } + public LengthType LengthType { get; set; } + + public WidthType WidthType { get; set; } + public NumOfGroup NumOfGroup { get; set; } + //public int StartNumber { get; set; } + //public int EndNumber { get; set; } + + public double Length + { + get + { + string strlength = CommonUtils.GetEnumDescription(LengthType); + return Convert.ToDouble(strlength); + } + } + + public double Width + { + get + { + string strwidth = CommonUtils.GetEnumDescription(WidthType); + return Convert.ToDouble(strwidth); + } + } + + public string SymbolName => String.Format("{0}{1}{2}{3}", CommonUtils.GetEnumDescription(LengthType), "mmx", CommonUtils.GetEnumDescription(WidthType), "mm"); + } +} \ No newline at end of file diff --git a/RookieStation/Custom/UserConstant.cs b/RookieStation/Custom/UserConstant.cs new file mode 100644 index 0000000..3ece556 --- /dev/null +++ b/RookieStation/Custom/UserConstant.cs @@ -0,0 +1,56 @@ +using Autodesk.Revit.UI.Selection; +using RookieStation.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RookieStation +{ + internal static class UserConstant + { + private static string AddinPath = typeof(RsApp).Assembly.Location; + + public static string AddinDirectory => System.IO.Path.GetDirectoryName(AddinPath); + + internal static string LibraryPreDirectory => AddinDirectory + "\\RsLibrary\\"; + + internal static ObjectSnapTypes SnapAll => + ObjectSnapTypes.Intersections + | ObjectSnapTypes.Endpoints + | ObjectSnapTypes.Centers + | ObjectSnapTypes.Midpoints + | ObjectSnapTypes.Points + | ObjectSnapTypes.Nearest + | ObjectSnapTypes.Perpendicular + | ObjectSnapTypes.WorkPlaneGrid + | ObjectSnapTypes.Quadrants + | ObjectSnapTypes.Tangents; + + private static double height; + private static int orders; + + internal static double Height + { + get + { + //var b = double.TryParse(ProjectConfigUtil.GetCfgValue("Height"), out height); + height = Properties.Settings.Default.Height; + return height; + } + set => height = value; + } + + internal static int Orders + { + get + { + //bool b = int.TryParse(ProjectConfigUtil.GetCfgValue("Orders"), out orders); + orders = Properties.Settings.Default.Orders; + return orders; + } + set => orders = value; + } + } +} \ No newline at end of file diff --git a/RookieStation/Properties/AssemblyInfo.cs b/RookieStation/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..f10f907 --- /dev/null +++ b/RookieStation/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("RookieStation")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("RookieStation")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("057c7e8d-42a1-4912-b522-498db7484894")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 +//通过使用 "*",如下所示: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/RookieStation/Properties/Resources.Designer.cs b/RookieStation/Properties/Resources.Designer.cs new file mode 100644 index 0000000..b580839 --- /dev/null +++ b/RookieStation/Properties/Resources.Designer.cs @@ -0,0 +1,173 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace RookieStation.Properties { + using System; + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// 返回此类使用的缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("RookieStation.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 重写当前线程的 CurrentUICulture 属性,对 + /// 使用此强类型资源类的所有资源查找执行重写。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap cainiao { + get { + object obj = ResourceManager.GetObject("cainiao", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap EntranceGate { + get { + object obj = ResourceManager.GetObject("EntranceGate", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap ExitGate { + get { + object obj = ResourceManager.GetObject("ExitGate", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap FamilyLib { + get { + object obj = ResourceManager.GetObject("FamilyLib", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap FloorFinishes { + get { + object obj = ResourceManager.GetObject("FloorFinishes", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap Lamp { + get { + object obj = ResourceManager.GetObject("Lamp", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap Reception { + get { + object obj = ResourceManager.GetObject("Reception", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap Shelf { + get { + object obj = ResourceManager.GetObject("Shelf", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap ShelfCard { + get { + object obj = ResourceManager.GetObject("ShelfCard", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap Shipping { + get { + object obj = ResourceManager.GetObject("Shipping", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap WallFinishes { + get { + object obj = ResourceManager.GetObject("WallFinishes", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/RookieStation/Properties/Resources.resx b/RookieStation/Properties/Resources.resx new file mode 100644 index 0000000..895d228 --- /dev/null +++ b/RookieStation/Properties/Resources.resx @@ -0,0 +1,154 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\resources\cainiao.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\entrancegate.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\exitgate.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\familylib.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\floorfinishes.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\lamp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\reception.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\shelf.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\shelfcard.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\shipping.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\wallfinishes.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/RookieStation/Properties/Settings.Designer.cs b/RookieStation/Properties/Settings.Designer.cs new file mode 100644 index 0000000..ede4d20 --- /dev/null +++ b/RookieStation/Properties/Settings.Designer.cs @@ -0,0 +1,76 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace RookieStation.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("3000")] + public double Height { + get { + return ((double)(this["Height"])); + } + set { + this["Height"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("4500")] + public int Orders { + get { + return ((int)(this["Orders"])); + } + set { + this["Orders"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("1")] + public int CurrentNumber { + get { + return ((int)(this["CurrentNumber"])); + } + set { + this["CurrentNumber"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("\r\n\r\n 单个,1500,400\r\n")] + public global::System.Collections.Specialized.StringCollection Shelves { + get { + return ((global::System.Collections.Specialized.StringCollection)(this["Shelves"])); + } + set { + this["Shelves"] = value; + } + } + } +} diff --git a/RookieStation/Properties/Settings.settings b/RookieStation/Properties/Settings.settings new file mode 100644 index 0000000..3912822 --- /dev/null +++ b/RookieStation/Properties/Settings.settings @@ -0,0 +1,21 @@ + + + + + + 3000 + + + 4500 + + + 1 + + + <?xml version="1.0" encoding="utf-16"?> +<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + <string>单个,1500,400</string> +</ArrayOfString> + + + \ No newline at end of file diff --git a/RookieStation/Resources/EntranceGate.png b/RookieStation/Resources/EntranceGate.png new file mode 100644 index 0000000..f120173 Binary files /dev/null and b/RookieStation/Resources/EntranceGate.png differ diff --git a/RookieStation/Resources/ExitGate.png b/RookieStation/Resources/ExitGate.png new file mode 100644 index 0000000..7ecfa22 Binary files /dev/null and b/RookieStation/Resources/ExitGate.png differ diff --git a/RookieStation/Resources/FamilyLib.png b/RookieStation/Resources/FamilyLib.png new file mode 100644 index 0000000..64296c4 Binary files /dev/null and b/RookieStation/Resources/FamilyLib.png differ diff --git a/RookieStation/Resources/FloorFinishes.png b/RookieStation/Resources/FloorFinishes.png new file mode 100644 index 0000000..50f3446 Binary files /dev/null and b/RookieStation/Resources/FloorFinishes.png differ diff --git a/RookieStation/Resources/Lamp.png b/RookieStation/Resources/Lamp.png new file mode 100644 index 0000000..a83b338 Binary files /dev/null and b/RookieStation/Resources/Lamp.png differ diff --git a/RookieStation/Resources/Reception.png b/RookieStation/Resources/Reception.png new file mode 100644 index 0000000..6558b4e Binary files /dev/null and b/RookieStation/Resources/Reception.png differ diff --git a/RookieStation/Resources/Shelf.png b/RookieStation/Resources/Shelf.png new file mode 100644 index 0000000..64a9a50 Binary files /dev/null and b/RookieStation/Resources/Shelf.png differ diff --git a/RookieStation/Resources/ShelfCard.png b/RookieStation/Resources/ShelfCard.png new file mode 100644 index 0000000..386cb63 Binary files /dev/null and b/RookieStation/Resources/ShelfCard.png differ diff --git a/RookieStation/Resources/Shipping.png b/RookieStation/Resources/Shipping.png new file mode 100644 index 0000000..a1382b8 Binary files /dev/null and b/RookieStation/Resources/Shipping.png differ diff --git a/RookieStation/Resources/WallFinishes.png b/RookieStation/Resources/WallFinishes.png new file mode 100644 index 0000000..f325afd Binary files /dev/null and b/RookieStation/Resources/WallFinishes.png differ diff --git a/RookieStation/Resources/cainiao.png b/RookieStation/Resources/cainiao.png new file mode 100644 index 0000000..d8e58ec Binary files /dev/null and b/RookieStation/Resources/cainiao.png differ diff --git a/RookieStation/RookieStation.addin b/RookieStation/RookieStation.addin new file mode 100644 index 0000000..bc60930 --- /dev/null +++ b/RookieStation/RookieStation.addin @@ -0,0 +1,11 @@ + + + + 菜鸟驿站插件 + RookieStation.dll + 1aac8233-690c-4dd6-89c0-78221dd65497 + RookieStation.RsApp + ADSK + Autodesk, www.autodesk.com + + \ No newline at end of file diff --git a/RookieStation/RookieStation.csproj b/RookieStation/RookieStation.csproj new file mode 100644 index 0000000..e9025db --- /dev/null +++ b/RookieStation/RookieStation.csproj @@ -0,0 +1,387 @@ + + + + + Debug + AnyCPU + {057C7E8D-42A1-4912-B522-498DB7484894} + Library + Properties + RookieStation + RookieStation + v4.7 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + x64 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + x64 + + + + ..\packages\Revit_API_x64.2020.0.0\lib\NET470\AdWindows.dll + False + + + ..\packages\EPPlus.5.6.4\lib\net45\EPPlus.dll + + + ..\packages\HandyControl.3.1.0\lib\net47\HandyControl.dll + + + ..\packages\Microsoft.IO.RecyclableMemoryStream.1.4.1\lib\net46\Microsoft.IO.RecyclableMemoryStream.dll + + + + + ..\packages\Revit_API_x64.2020.0.0\lib\NET470\RevitAddInUtility.dll + False + + + ..\packages\Revit_API_x64.2020.0.0\lib\NET470\RevitAPI.dll + False + + + ..\packages\Revit_API_x64.2020.0.0\lib\NET470\RevitAPIUI.dll + False + + + + ..\packages\System.ComponentModel.Annotations.4.7.0\lib\net461\System.ComponentModel.Annotations.dll + + + + + + + + + + + + + + + + ..\packages\Revit_API_x64.2020.0.0\lib\NET470\UIFramework.dll + False + + + ..\packages\Revit_API_x64.2020.0.0\lib\NET470\UIFrameworkServices.dll + False + + + + + + + + + True + True + Settings.settings + + + + + + + + + + + + + + + + + + + + + + True + True + Resources.resx + + + + + + + + + + + WpfEntranceGate.xaml + + + WpfExitGate.xaml + + + WpfFloorFinishes.xaml + + + WpfLampsLayout.xaml + + + WpfProjectSettings.xaml + + + WpfShelfCards.xaml + + + WpfReceptionArea.xaml + + + WpfShelvesLayout.xaml + + + WpfWallFinishes.xaml + + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + + + Always + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + + + + + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + + + + + + + + + + + \ No newline at end of file diff --git a/RookieStation/RookieStationDebug.addin b/RookieStation/RookieStationDebug.addin new file mode 100644 index 0000000..84eabc7 --- /dev/null +++ b/RookieStation/RookieStationDebug.addin @@ -0,0 +1,11 @@ + + + + RsApp + C:\Users\Administrator\Desktop\工作内容\菜鸟驿站校企参数化设计开发需求文档v 0.1\RookieStation\RookieStation\bin\Debug\RookieStation.dll + 1aac8233-690c-4dd6-89c0-78221dd65497 + RookieStation.RsApp + ADSK + Autodesk, www.autodesk.com + + \ No newline at end of file diff --git a/RookieStation/RsApp.cs b/RookieStation/RsApp.cs new file mode 100644 index 0000000..e8e496d --- /dev/null +++ b/RookieStation/RsApp.cs @@ -0,0 +1,202 @@ +using Autodesk.Revit.UI; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Interop; +using System.Windows.Media.Imaging; + +namespace RookieStation +{ + internal class RsApp : IExternalApplication + { + private const string TabName = "菜鸟驿站工具"; + private const string ProjectSettingsPanelName = "项目设置"; + private const string ReceptionPanelName = "前台布置"; + private const string EntranceAndExitGatePanelName = "取件区"; + private const string FinishesPanelName = "饰面,完成面"; + private const string CommonTools = "通用工具"; + + //获取Ribbon类所在的通用类库目录 + private static string AddInPath = typeof(RsApp).Assembly.Location; + + //获取AddInPath的目录 + private static string DirRequestAssembly = Path.GetDirectoryName(AddInPath); + + private BitmapSource ConvertFromBitmap(System.Drawing.Bitmap bitmap) + { + return Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); + } + + Result IExternalApplication.OnShutdown(UIControlledApplication application) + { + return Result.Succeeded; + } + + Result IExternalApplication.OnStartup(UIControlledApplication application) + { + try + { + application.CreateRibbonTab(TabName); + + //UserPanel.AddItem(_loginPBData); + //".\\*.*"中的“.”表示通用类库文件所在的目录(Debug),“..”表示的是上级的目录(bin),“..”\\..,引号表示再上一级目录 + //ContextualHelp contextualHelp = new ContextualHelp(ContextualHelpType.Url, "https://www.baidu.com"); + //_loginPBData.SetContextualHelp(contextualHelp); + + //项目设置 + RibbonPanel projectPanel = application.CreateRibbonPanel(TabName, ProjectSettingsPanelName); + PushButtonData projectPBD = new PushButtonData("项目设置", "项目设置", AddInPath, "RookieStation.CmdProjectSettings") + { + LargeImage = ConvertFromBitmap(Properties.Resources.cainiao), + Image = ConvertFromBitmap(Properties.Resources.cainiao) + }; + var projectbtn = (PushButton)projectPanel.AddItem(projectPBD); + //前台布置 + RibbonPanel receptionAreaPanel = application.CreateRibbonPanel(TabName, ReceptionPanelName); + PushButtonData receptionLayoutPBD = new PushButtonData("寄件区布置", "前台布置", AddInPath, "RookieStation.ShippingAreaModule.CmdPlaceReceptionArea") + { + LargeImage = ConvertFromBitmap(Properties.Resources.Reception), + Image = ConvertFromBitmap(Properties.Resources.Reception) + }; + var receptionbtn = (PushButton)receptionAreaPanel.AddItem(receptionLayoutPBD); + receptionbtn.AvailabilityClassName = "RookieStation.ViewPlanCmdEnabled"; + //出入口布置 + RibbonPanel packAreaPanel = application.CreateRibbonPanel(TabName, EntranceAndExitGatePanelName); + PushButtonData entrancegateLayoutPBD = new PushButtonData("入口布置", "入口闸机", AddInPath, "RookieStation.PackAreaModule.CmdPlaceEntranceGate") + { + LargeImage = ConvertFromBitmap(Properties.Resources.EntranceGate), + Image = ConvertFromBitmap(Properties.Resources.EntranceGate) + }; + PushButtonData exitGateLayoutPBD = new PushButtonData("出口布置", "出口收检台", AddInPath, "RookieStation.PackAreaModule.CmdPlaceExitGate") + { + LargeImage = ConvertFromBitmap(Properties.Resources.ExitGate), + Image = ConvertFromBitmap(Properties.Resources.ExitGate) + }; + //var gatebtn = (PushButton)gatePanel.AddItem(exportGateLayoutPBD); + + //IList gateItemsStacked = packAreaPanel.AddStackedItems(entrancegateLayoutPBD, exitGateLayoutPBD); + //var entrancebtn = (PushButton)gateItemsStacked[0]; + //var exitbtn = (PushButton)gateItemsStacked[1]; + var entrancebtn = (PushButton)packAreaPanel.AddItem(entrancegateLayoutPBD); + var exitbtn = (PushButton)packAreaPanel.AddItem(exitGateLayoutPBD); + entrancebtn.AvailabilityClassName = "RookieStation.ViewPlanCmdEnabled"; + exitbtn.AvailabilityClassName = "RookieStation.ViewPlanCmdEnabled"; + + PushButtonData placeShelvesPBD = new PushButtonData("货架布置", "货架布置", AddInPath, "RookieStation.PackAreaModule.CmdPlaceShelves") + { + LargeImage = ConvertFromBitmap(Properties.Resources.Shelf), + Image = ConvertFromBitmap(Properties.Resources.Shelf) + }; + var placeShelvesbtn = (PushButton)packAreaPanel.AddItem(placeShelvesPBD); + placeShelvesbtn.AvailabilityClassName = "RookieStation.ViewPlanCmdEnabled"; + + PushButtonData placeShelveCardsPBD = new PushButtonData("货架端牌", "货架端牌", AddInPath, "RookieStation.PackAreaModule.CmdArrangeShelfCards") + { + LargeImage = ConvertFromBitmap(Properties.Resources.ShelfCard), + Image = ConvertFromBitmap(Properties.Resources.ShelfCard) + }; + var placeShelveCardsbtn = (PushButton)packAreaPanel.AddItem(placeShelveCardsPBD); + + PushButtonData placeLampsPBD = new PushButtonData("灯具布置", "灯具布置", AddInPath, "RookieStation.PackAreaModule.CmdPlaceLamps") + { + LargeImage = ConvertFromBitmap(Properties.Resources.Lamp), + Image = ConvertFromBitmap(Properties.Resources.Lamp) + }; + var placeLampsbtn = (PushButton)packAreaPanel.AddItem(placeLampsPBD); + placeLampsbtn.AvailabilityClassName = "RookieStation.ViewPlanCmdEnabled"; + //饰面,完成面 + RibbonPanel finishesPanel = application.CreateRibbonPanel(TabName, FinishesPanelName); + + PushButtonData floorfinishesPBD = new PushButtonData("地面铺装", "地面铺装", AddInPath, "RookieStation.CommonTools.CmdPlaceFloorFinishes") + { + LargeImage = ConvertFromBitmap(Properties.Resources.FloorFinishes), + Image = ConvertFromBitmap(Properties.Resources.FloorFinishes) + }; + var floorcoveringbtn = (PushButton)finishesPanel.AddItem(floorfinishesPBD); + floorcoveringbtn.AvailabilityClassName = "RookieStation.ViewPlanCmdEnabled"; + + PushButtonData wallcoveringPBD = new PushButtonData("墙饰面", "墙饰面", AddInPath, "RookieStation.CommonTools.CmdPlaceWallFinishes") + { + LargeImage = ConvertFromBitmap(Properties.Resources.WallFinishes), + Image = ConvertFromBitmap(Properties.Resources.WallFinishes) + }; + var wallcoveringbtn = (PushButton)finishesPanel.AddItem(wallcoveringPBD); + wallcoveringbtn.AvailabilityClassName = "RookieStation.ViewPlanCmdEnabled"; + //通用面板 + RibbonPanel commonToolsPanel = application.CreateRibbonPanel(TabName, CommonTools); + + PushButtonData browserfamilyPBD = new PushButtonData("浏览族", "浏览族文件", AddInPath, "RookieStation.CommonTools.CmdBrowserFamily") + { + LargeImage = ConvertFromBitmap(Properties.Resources.FamilyLib), + Image = ConvertFromBitmap(Properties.Resources.FamilyLib) + }; + var browserfamilybtn = (PushButton)commonToolsPanel.AddItem(browserfamilyPBD); + + return Result.Succeeded; + + #region MyRegion + + //RibbonPanel familyUtilPanel = application.CreateRibbonPanel(TabName, PanelName1); + + //PushButtonData FamilyTransmitPBData = new PushButtonData("传递标准", "传递标准", AddInPath, "HandyUtils.Common.RExecute.CmdTransmitStandards"); + //PushButtonData FamilyMassSavePBData = new PushButtonData("批量保存", "批量保存", AddInPath, "HandyUtils.Common.RExecute.CmdFamilyPreservation"); + + //IList FtItemsStacked = familyUtilPanel.AddStackedItems(FamilyTransmitPBData, FamilyMassSavePBData); + ////((PushButton)(ribbonItemsStacked[0])).Image = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "Reset.png"), UriKind.Absolute)); + //((PushButton)FtItemsStacked[0]).Image = ConvertFromBitmap(Properties.Resources.One_Way_Transition_16px); + //((PushButton)FtItemsStacked[1]).Image = ConvertFromBitmap(Properties.Resources.Save_16px); + + //familyUtilPanel.AddSeparator(); + + //PushButtonData ImportFamParaPBD = new PushButtonData("导入族参数", "族参数", AddInPath, "HandyUtils.Common.RExecute.CmdImportParams") + //{ + // ToolTip = "导入族参数到族文件" + //}; + + //PushButtonData ImportSharedParaPBD = new PushButtonData("导入共享参数", "共享参数", AddInPath, "HandyUtils.Common.RExecute.CmdShareParams") + //{ + // ToolTip = "导入参数到共享参数文件" + //}; + //PushButtonData UpdateFamilyFilePBD = new PushButtonData("更新族文件", "更新族", AddInPath, "HandyUtils.Common.RExecute.CmdUpdateFiles") + //{ + // ToolTip = "更新族文件缩略图及升级至当前版本" + //}; + + //IList ParaItemsStacked = familyUtilPanel.AddStackedItems(ImportFamParaPBD, ImportSharedParaPBD, UpdateFamilyFilePBD); + //((PushButton)ParaItemsStacked[0]).Image = ConvertFromBitmap(Properties.Resources.Add_Property_16px); + //((PushButton)ParaItemsStacked[1]).Image = ConvertFromBitmap(Properties.Resources.Import_16px); + //((PushButton)ParaItemsStacked[2]).Image = ConvertFromBitmap(Properties.Resources.Available_Updates_32px); + + #endregion MyRegion + + #region MyRegion + + //RibbonPanel exportPanel = application.CreateRibbonPanel(TabName, "导出族信息"); + + //PushButtonData pbdSettings = new PushButtonData("设置", "导出选项", AddInPath, "HandyUtils.Common.RExecute.CmdSettings") + //{ + // ToolTip = "设置导出选项" + //}; + + //PushButtonData pbdFamilyInfoExport = new PushButtonData("导出", "信息导出", AddInPath, "HandyUtils.Common.RExecute.CmdFamilyInfo") + //{ + // ToolTip = "将族图片、族参数进行导出" + //}; + //IList ExportItemsStacked = exportPanel.AddStackedItems(pbdSettings, pbdFamilyInfoExport); + //((PushButton)ExportItemsStacked[0]).Image = ConvertFromBitmap(Properties.Resources.Settings_16px); + //((PushButton)ExportItemsStacked[1]).Image = ConvertFromBitmap(Properties.Resources.Export_16px); + + #endregion MyRegion + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + return Result.Cancelled; + } + } + } +} \ No newline at end of file diff --git a/RookieStation/RsLibrary/Door/幕墙门-双扇无边框.rfa b/RookieStation/RsLibrary/Door/幕墙门-双扇无边框.rfa new file mode 100644 index 0000000..0b1df25 Binary files /dev/null and b/RookieStation/RsLibrary/Door/幕墙门-双扇无边框.rfa differ diff --git a/RookieStation/RsLibrary/Door/幕墙门-玻璃门.rfa b/RookieStation/RsLibrary/Door/幕墙门-玻璃门.rfa new file mode 100644 index 0000000..a7f5e39 Binary files /dev/null and b/RookieStation/RsLibrary/Door/幕墙门-玻璃门.rfa differ diff --git a/RookieStation/RsLibrary/Equipment/配电箱.rfa b/RookieStation/RsLibrary/Equipment/配电箱.rfa new file mode 100644 index 0000000..825b382 Binary files /dev/null and b/RookieStation/RsLibrary/Equipment/配电箱.rfa differ diff --git a/RookieStation/RsLibrary/Equipment/高拍仪.rfa b/RookieStation/RsLibrary/Equipment/高拍仪.rfa new file mode 100644 index 0000000..4b42705 Binary files /dev/null and b/RookieStation/RsLibrary/Equipment/高拍仪.rfa differ diff --git a/RookieStation/RsLibrary/FloorFinish/地砖.rfa b/RookieStation/RsLibrary/FloorFinish/地砖.rfa new file mode 100644 index 0000000..d84050a Binary files /dev/null and b/RookieStation/RsLibrary/FloorFinish/地砖.rfa differ diff --git a/RookieStation/RsLibrary/FloorFinish/自适应地砖.rfa b/RookieStation/RsLibrary/FloorFinish/自适应地砖.rfa new file mode 100644 index 0000000..ed5aad6 Binary files /dev/null and b/RookieStation/RsLibrary/FloorFinish/自适应地砖.rfa differ diff --git a/RookieStation/RsLibrary/Furniture/L型收检接待台.rfa b/RookieStation/RsLibrary/Furniture/L型收检接待台.rfa new file mode 100644 index 0000000..8e954c7 Binary files /dev/null and b/RookieStation/RsLibrary/Furniture/L型收检接待台.rfa differ diff --git a/RookieStation/RsLibrary/Furniture/寄件接待台.rfa b/RookieStation/RsLibrary/Furniture/寄件接待台.rfa new file mode 100644 index 0000000..9abbed4 Binary files /dev/null and b/RookieStation/RsLibrary/Furniture/寄件接待台.rfa differ diff --git a/RookieStation/RsLibrary/Furniture/拆包桌.rfa b/RookieStation/RsLibrary/Furniture/拆包桌.rfa new file mode 100644 index 0000000..04a5b03 Binary files /dev/null and b/RookieStation/RsLibrary/Furniture/拆包桌.rfa differ diff --git a/RookieStation/RsLibrary/Gate/L型收检台.rfa b/RookieStation/RsLibrary/Gate/L型收检台.rfa new file mode 100644 index 0000000..4e07b55 Binary files /dev/null and b/RookieStation/RsLibrary/Gate/L型收检台.rfa differ diff --git a/RookieStation/RsLibrary/Gate/收检台-右.rfa b/RookieStation/RsLibrary/Gate/收检台-右.rfa new file mode 100644 index 0000000..711c12d Binary files /dev/null and b/RookieStation/RsLibrary/Gate/收检台-右.rfa differ diff --git a/RookieStation/RsLibrary/Gate/收检台-左.rfa b/RookieStation/RsLibrary/Gate/收检台-左.rfa new file mode 100644 index 0000000..4db8ce0 Binary files /dev/null and b/RookieStation/RsLibrary/Gate/收检台-左.rfa differ diff --git a/RookieStation/RsLibrary/Gate/直线形收检台.rfa b/RookieStation/RsLibrary/Gate/直线形收检台.rfa new file mode 100644 index 0000000..afcaba7 Binary files /dev/null and b/RookieStation/RsLibrary/Gate/直线形收检台.rfa differ diff --git a/RookieStation/RsLibrary/Gate/简易收检台.rfa b/RookieStation/RsLibrary/Gate/简易收检台.rfa new file mode 100644 index 0000000..36d2ec1 Binary files /dev/null and b/RookieStation/RsLibrary/Gate/简易收检台.rfa differ diff --git a/RookieStation/RsLibrary/Gate/闸机.rfa b/RookieStation/RsLibrary/Gate/闸机.rfa new file mode 100644 index 0000000..f513f0c Binary files /dev/null and b/RookieStation/RsLibrary/Gate/闸机.rfa differ diff --git a/RookieStation/RsLibrary/Lamp/吊灯.rfa b/RookieStation/RsLibrary/Lamp/吊灯.rfa new file mode 100644 index 0000000..686ab94 Binary files /dev/null and b/RookieStation/RsLibrary/Lamp/吊灯.rfa differ diff --git a/RookieStation/RsLibrary/Lamp/筒灯.0001.rfa b/RookieStation/RsLibrary/Lamp/筒灯.0001.rfa new file mode 100644 index 0000000..115d2c2 Binary files /dev/null and b/RookieStation/RsLibrary/Lamp/筒灯.0001.rfa differ diff --git a/RookieStation/RsLibrary/Lamp/筒灯.rfa b/RookieStation/RsLibrary/Lamp/筒灯.rfa new file mode 100644 index 0000000..f246feb Binary files /dev/null and b/RookieStation/RsLibrary/Lamp/筒灯.rfa differ diff --git a/RookieStation/RsLibrary/Shelf/三联货架.rfa b/RookieStation/RsLibrary/Shelf/三联货架.rfa new file mode 100644 index 0000000..2c39a46 Binary files /dev/null and b/RookieStation/RsLibrary/Shelf/三联货架.rfa differ diff --git a/RookieStation/RsLibrary/Shelf/单联货架.0001.rfa b/RookieStation/RsLibrary/Shelf/单联货架.0001.rfa new file mode 100644 index 0000000..5a7d9c1 Binary files /dev/null and b/RookieStation/RsLibrary/Shelf/单联货架.0001.rfa differ diff --git a/RookieStation/RsLibrary/Shelf/单联货架.rfa b/RookieStation/RsLibrary/Shelf/单联货架.rfa new file mode 100644 index 0000000..e74a9d3 Binary files /dev/null and b/RookieStation/RsLibrary/Shelf/单联货架.rfa differ diff --git a/RookieStation/RsLibrary/Shelf/双联货架.rfa b/RookieStation/RsLibrary/Shelf/双联货架.rfa new file mode 100644 index 0000000..47cf4a7 Binary files /dev/null and b/RookieStation/RsLibrary/Shelf/双联货架.rfa differ diff --git a/RookieStation/RsLibrary/Shelf/货架端牌.rfa b/RookieStation/RsLibrary/Shelf/货架端牌.rfa new file mode 100644 index 0000000..b6639ce Binary files /dev/null and b/RookieStation/RsLibrary/Shelf/货架端牌.rfa differ diff --git a/RookieStation/RsLibrary/Sign/侧招灯箱.rfa b/RookieStation/RsLibrary/Sign/侧招灯箱.rfa new file mode 100644 index 0000000..415e116 Binary files /dev/null and b/RookieStation/RsLibrary/Sign/侧招灯箱.rfa differ diff --git a/RookieStation/RsLibrary/Sign/四牌.rfa b/RookieStation/RsLibrary/Sign/四牌.rfa new file mode 100644 index 0000000..d912e8e Binary files /dev/null and b/RookieStation/RsLibrary/Sign/四牌.rfa differ diff --git a/RookieStation/RsLibrary/Sign/地贴.rfa b/RookieStation/RsLibrary/Sign/地贴.rfa new file mode 100644 index 0000000..d6b8dc1 Binary files /dev/null and b/RookieStation/RsLibrary/Sign/地贴.rfa differ diff --git a/RookieStation/RsLibrary/Sign/墙贴.rfa b/RookieStation/RsLibrary/Sign/墙贴.rfa new file mode 100644 index 0000000..e859c18 Binary files /dev/null and b/RookieStation/RsLibrary/Sign/墙贴.rfa differ diff --git a/RookieStation/RsLibrary/Sign/常规门头.rfa b/RookieStation/RsLibrary/Sign/常规门头.rfa new file mode 100644 index 0000000..75b3a4e Binary files /dev/null and b/RookieStation/RsLibrary/Sign/常规门头.rfa differ diff --git a/RookieStation/RsLibrary/Sign/玻璃贴.rfa b/RookieStation/RsLibrary/Sign/玻璃贴.rfa new file mode 100644 index 0000000..af5a678 Binary files /dev/null and b/RookieStation/RsLibrary/Sign/玻璃贴.rfa differ diff --git a/RookieStation/RsLibrary/Sign/菜鸟LOGO.rfa b/RookieStation/RsLibrary/Sign/菜鸟LOGO.rfa new file mode 100644 index 0000000..89c2505 Binary files /dev/null and b/RookieStation/RsLibrary/Sign/菜鸟LOGO.rfa differ diff --git a/RookieStation/RsLibrary/Sign/菜鸟使命.rfa b/RookieStation/RsLibrary/Sign/菜鸟使命.rfa new file mode 100644 index 0000000..f511aab Binary files /dev/null and b/RookieStation/RsLibrary/Sign/菜鸟使命.rfa differ diff --git a/RookieStation/RsLibrary/Sign/防撞条.rfa b/RookieStation/RsLibrary/Sign/防撞条.rfa new file mode 100644 index 0000000..0023f96 Binary files /dev/null and b/RookieStation/RsLibrary/Sign/防撞条.rfa differ diff --git a/RookieStation/RsLibrary/Texture/免费WiFi.png b/RookieStation/RsLibrary/Texture/免费WiFi.png new file mode 100644 index 0000000..a6f454e Binary files /dev/null and b/RookieStation/RsLibrary/Texture/免费WiFi.png differ diff --git a/RookieStation/RsLibrary/Texture/取件出口.png b/RookieStation/RsLibrary/Texture/取件出口.png new file mode 100644 index 0000000..c35afdf Binary files /dev/null and b/RookieStation/RsLibrary/Texture/取件出口.png differ diff --git a/RookieStation/RsLibrary/Texture/取件区-右.png b/RookieStation/RsLibrary/Texture/取件区-右.png new file mode 100644 index 0000000..d89de9f Binary files /dev/null and b/RookieStation/RsLibrary/Texture/取件区-右.png differ diff --git a/RookieStation/RsLibrary/Texture/取件区-左.png b/RookieStation/RsLibrary/Texture/取件区-左.png new file mode 100644 index 0000000..52d2a88 Binary files /dev/null and b/RookieStation/RsLibrary/Texture/取件区-左.png differ diff --git a/RookieStation/RsLibrary/Texture/寄件出口.png b/RookieStation/RsLibrary/Texture/寄件出口.png new file mode 100644 index 0000000..68b4bf2 Binary files /dev/null and b/RookieStation/RsLibrary/Texture/寄件出口.png differ diff --git a/RookieStation/RsLibrary/Texture/寄件区-右.png b/RookieStation/RsLibrary/Texture/寄件区-右.png new file mode 100644 index 0000000..f653207 Binary files /dev/null and b/RookieStation/RsLibrary/Texture/寄件区-右.png differ diff --git a/RookieStation/RsLibrary/Texture/寄件区-左.png b/RookieStation/RsLibrary/Texture/寄件区-左.png new file mode 100644 index 0000000..8675aa4 Binary files /dev/null and b/RookieStation/RsLibrary/Texture/寄件区-左.png differ diff --git a/RookieStation/RsLibrary/Texture/服务承诺_损失赔偿方法_投诉处理办法(700mm_500mm竖版).jpg b/RookieStation/RsLibrary/Texture/服务承诺_损失赔偿方法_投诉处理办法(700mm_500mm竖版).jpg new file mode 100644 index 0000000..c51ce04 Binary files /dev/null and b/RookieStation/RsLibrary/Texture/服务承诺_损失赔偿方法_投诉处理办法(700mm_500mm竖版).jpg differ diff --git a/RookieStation/RsLibrary/Texture/校园文化墙.jpg b/RookieStation/RsLibrary/Texture/校园文化墙.jpg new file mode 100644 index 0000000..2073e7a Binary files /dev/null and b/RookieStation/RsLibrary/Texture/校园文化墙.jpg differ diff --git a/RookieStation/RsLibrary/Texture/消防安全.png b/RookieStation/RsLibrary/Texture/消防安全.png new file mode 100644 index 0000000..d4058b5 Binary files /dev/null and b/RookieStation/RsLibrary/Texture/消防安全.png differ diff --git a/RookieStation/RsLibrary/Texture/监控提醒.png b/RookieStation/RsLibrary/Texture/监控提醒.png new file mode 100644 index 0000000..48dff03 Binary files /dev/null and b/RookieStation/RsLibrary/Texture/监控提醒.png differ diff --git a/RookieStation/RsLibrary/Texture/确认台卡.jpg b/RookieStation/RsLibrary/Texture/确认台卡.jpg new file mode 100644 index 0000000..7625fc6 Binary files /dev/null and b/RookieStation/RsLibrary/Texture/确认台卡.jpg differ diff --git a/RookieStation/RsLibrary/Texture/禁止吸烟.png b/RookieStation/RsLibrary/Texture/禁止吸烟.png new file mode 100644 index 0000000..7257fc6 Binary files /dev/null and b/RookieStation/RsLibrary/Texture/禁止吸烟.png differ diff --git a/RookieStation/RsLibrary/Texture/禁止寄递物品管理规定_附录禁止寄递物品指导目录(700mm_500mm竖版).jpg b/RookieStation/RsLibrary/Texture/禁止寄递物品管理规定_附录禁止寄递物品指导目录(700mm_500mm竖版).jpg new file mode 100644 index 0000000..10170b8 Binary files /dev/null and b/RookieStation/RsLibrary/Texture/禁止寄递物品管理规定_附录禁止寄递物品指导目录(700mm_500mm竖版).jpg differ diff --git a/RookieStation/RsLibrary/Texture/绿动区-右.png b/RookieStation/RsLibrary/Texture/绿动区-右.png new file mode 100644 index 0000000..ab39899 Binary files /dev/null and b/RookieStation/RsLibrary/Texture/绿动区-右.png differ diff --git a/RookieStation/RsLibrary/Texture/绿动区-左.png b/RookieStation/RsLibrary/Texture/绿动区-左.png new file mode 100644 index 0000000..c9321ee Binary files /dev/null and b/RookieStation/RsLibrary/Texture/绿动区-左.png differ diff --git a/RookieStation/RsLibrary/Texture/联系台卡.jpg b/RookieStation/RsLibrary/Texture/联系台卡.jpg new file mode 100644 index 0000000..2a83aac Binary files /dev/null and b/RookieStation/RsLibrary/Texture/联系台卡.jpg differ diff --git a/RookieStation/RsLibrary/Texture/菜鸟驿站寄件业务收费标准(210_297竖版).jpg b/RookieStation/RsLibrary/Texture/菜鸟驿站寄件业务收费标准(210_297竖版).jpg new file mode 100644 index 0000000..90f7d9a Binary files /dev/null and b/RookieStation/RsLibrary/Texture/菜鸟驿站寄件业务收费标准(210_297竖版).jpg differ diff --git a/RookieStation/RsLibrary/Texture/货架端牌_校园.png b/RookieStation/RsLibrary/Texture/货架端牌_校园.png new file mode 100644 index 0000000..dced896 Binary files /dev/null and b/RookieStation/RsLibrary/Texture/货架端牌_校园.png differ diff --git a/RookieStation/RsLibrary/Texture/邮件快件实名收寄管理办法(700mm_500mm竖版).jpg b/RookieStation/RsLibrary/Texture/邮件快件实名收寄管理办法(700mm_500mm竖版).jpg new file mode 100644 index 0000000..e3e8607 Binary files /dev/null and b/RookieStation/RsLibrary/Texture/邮件快件实名收寄管理办法(700mm_500mm竖版).jpg differ diff --git a/RookieStation/RsLibrary/Texture/邮件快件收寄验视规定(试行)(700mm_500mm竖版).jpg b/RookieStation/RsLibrary/Texture/邮件快件收寄验视规定(试行)(700mm_500mm竖版).jpg new file mode 100644 index 0000000..c2139cc Binary files /dev/null and b/RookieStation/RsLibrary/Texture/邮件快件收寄验视规定(试行)(700mm_500mm竖版).jpg differ diff --git a/RookieStation/RsLibrary/Texture/验视台卡.jpg b/RookieStation/RsLibrary/Texture/验视台卡.jpg new file mode 100644 index 0000000..b33728a Binary files /dev/null and b/RookieStation/RsLibrary/Texture/验视台卡.jpg differ diff --git a/RookieStation/RsLibrary/WallFinish/校园文化墙.rfa b/RookieStation/RsLibrary/WallFinish/校园文化墙.rfa new file mode 100644 index 0000000..2ea580e Binary files /dev/null and b/RookieStation/RsLibrary/WallFinish/校园文化墙.rfa differ diff --git a/RookieStation/RsLibrary/台卡.rfa b/RookieStation/RsLibrary/台卡.rfa new file mode 100644 index 0000000..6a4eb62 Binary files /dev/null and b/RookieStation/RsLibrary/台卡.rfa differ diff --git a/RookieStation/RsLibrary/定位线.rfa b/RookieStation/RsLibrary/定位线.rfa new file mode 100644 index 0000000..64337aa Binary files /dev/null and b/RookieStation/RsLibrary/定位线.rfa differ diff --git a/RookieStation/RsLibrary/寄件收费标准.rfa b/RookieStation/RsLibrary/寄件收费标准.rfa new file mode 100644 index 0000000..2e8c4f2 Binary files /dev/null and b/RookieStation/RsLibrary/寄件收费标准.rfa differ diff --git a/RookieStation/RsLibrary/快递指导规范.rfa b/RookieStation/RsLibrary/快递指导规范.rfa new file mode 100644 index 0000000..cbc0ffc Binary files /dev/null and b/RookieStation/RsLibrary/快递指导规范.rfa differ diff --git a/RookieStation/RsLibrary/箭头.rfa b/RookieStation/RsLibrary/箭头.rfa new file mode 100644 index 0000000..5739605 Binary files /dev/null and b/RookieStation/RsLibrary/箭头.rfa differ diff --git a/RookieStation/RsLibrary/绿动箱.rfa b/RookieStation/RsLibrary/绿动箱.rfa new file mode 100644 index 0000000..5b01844 Binary files /dev/null and b/RookieStation/RsLibrary/绿动箱.rfa differ diff --git a/RookieStation/RsLibrary/背景墙.rfa b/RookieStation/RsLibrary/背景墙.rfa new file mode 100644 index 0000000..34e51d0 Binary files /dev/null and b/RookieStation/RsLibrary/背景墙.rfa differ diff --git a/RookieStation/RsLibrary/菜鸟驿站.rte b/RookieStation/RsLibrary/菜鸟驿站.rte new file mode 100644 index 0000000..68e70df Binary files /dev/null and b/RookieStation/RsLibrary/菜鸟驿站.rte differ diff --git a/RookieStation/RsLibrary/菜鸟驿站图框.rfa b/RookieStation/RsLibrary/菜鸟驿站图框.rfa new file mode 100644 index 0000000..626a92f Binary files /dev/null and b/RookieStation/RsLibrary/菜鸟驿站图框.rfa differ diff --git a/RookieStation/ShelvesPlacementViewModel.cs b/RookieStation/ShelvesPlacementViewModel.cs new file mode 100644 index 0000000..727da74 --- /dev/null +++ b/RookieStation/ShelvesPlacementViewModel.cs @@ -0,0 +1,94 @@ +using RookieStation.Utils; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RookieStation +{ + public class ShelvesPlacementViewModel + { + /// + /// 基于参考线的偏移(垂距) + /// + public double VerticalReferOffest { get; set; } + + /// + /// 通道宽度 + /// + public double PassageWidth { get; set; } + + /// + /// 基于参考线的偏移(起点水平) + /// + public double ParalelReferOffest { get; set; } + + /// + /// 货架间距 + /// + public double Spacing { get; set; } + + public ShelvesPlacementViewModel() + { + Data = CreateShelvesData(); + } + + public ObservableCollection Data { get; set; } + + private ObservableCollection CreateShelvesData() + { + var shelves = new ObservableCollection(); + var sc = Properties.Settings.Default.Shelves; + for (int i = 0; i < sc.Count; i++) + { + Shelf shelf = new Shelf(); + string shelf_string = sc[i]; + string[] shelf_chars = shelf_string.Split(','); + foreach (NumOfGroup ng in Enum.GetValues(typeof(NumOfGroup))) + { + string description = CommonUtils.GetEnumDescription(ng); + if (description == shelf_chars[0]) + { + shelf.NumOfGroup = ng; + break; + } + } + foreach (LengthType lt in Enum.GetValues(typeof(LengthType))) + { + string description = CommonUtils.GetEnumDescription(lt); + if (description == shelf_chars[1]) + { + shelf.LengthType = lt; + break; + } + } + foreach (WidthType wt in Enum.GetValues(typeof(WidthType))) + { + string description = CommonUtils.GetEnumDescription(wt); + if (description == shelf_chars[2]) + { + shelf.WidthType = wt; + break; + } + } + shelves.Add(shelf); + } + return shelves; + //return new ObservableCollection + //{ + // new Shelf() + // { + // LengthType =LengthType.x1500, + // WidthType = WidthType.x400, + // NumOfGroup = NumOfGroup.Single, + // } + //}; + } + + //public IEnumerable Widths => new[] { "400", "500", "600" }; + + //public Dictionary LengthDict = new Dictionary(); + } +} \ No newline at end of file diff --git a/RookieStation/Utils/AssemblyLoader.cs b/RookieStation/Utils/AssemblyLoader.cs new file mode 100644 index 0000000..5884eba --- /dev/null +++ b/RookieStation/Utils/AssemblyLoader.cs @@ -0,0 +1,100 @@ +using System; +using System.IO; +using System.Reflection; +using System.Threading; + +namespace RookieStation +{ + public class AssemblyLoader + { + public AssemblyLoader(string assemblyDir) + { + AssemblyDirectory = assemblyDir; + } + + public string AssemblyDirectory { get; set; } + + public void HookAssemblyResolve() + { + AppDomain.CurrentDomain.AssemblyResolve += this.CurrentDomain_AssemblyResolve; + } + + public void UnhookAssemblyResolve() + { + AppDomain.CurrentDomain.AssemblyResolve -= this.CurrentDomain_AssemblyResolve; + } + + private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) + { + Assembly result; + new AssemblyName(args.Name); + string text = this.SearchAssemblyFile(args.Name); + if (File.Exists(text)) + { + result = this.LoadAddin(text); + } + else + { + if (string.IsNullOrEmpty(text)) + { + string[] array = args.Name.Split(new char[] + { + ',' + }); + string text2 = array[0]; + if (array.Length > 1) + { + string text3 = array[2]; + if (text2.EndsWith(".resources", StringComparison.CurrentCultureIgnoreCase) && !text3.EndsWith("neutral", StringComparison.CurrentCultureIgnoreCase)) + { + text2 = text2.Substring(0, text2.Length - ".resources".Length); + } + text = this.SearchAssemblyFile(text2); + if (File.Exists(text)) + { + return this.LoadAddin(text); + } + //text = this.SearchAssemblyFile(text2); + } + } + result = this.LoadAddin(text); + } + return result; + } + + private string SearchAssemblyFile(string assemName) + { + string[] array = new string[] + { + ".dll", + ".exe" + }; + string text = string.Empty; + string str = assemName.Substring(0, assemName.IndexOf(',')); + foreach (string str2 in array) + { + text = AssemblyDirectory + "\\" + str + str2; + if (File.Exists(text)) + { + return text; + } + } + return string.Empty; + } + + private Assembly LoadAddin(string filePath) + { + Assembly result = null; + try + { + Monitor.Enter(this); + result = Assembly.LoadFile(filePath); + } + finally + { + Monitor.Exit(this); + } + return result; + } + } +} \ No newline at end of file diff --git a/RookieStation/Utils/CommonUtils.cs b/RookieStation/Utils/CommonUtils.cs new file mode 100644 index 0000000..0c323ab --- /dev/null +++ b/RookieStation/Utils/CommonUtils.cs @@ -0,0 +1,85 @@ +using Autodesk.Revit.UI; +using RookieStation.PackAreaModule; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace RookieStation.Utils +{ + internal static class CommonUtils + { + public static String GetEnumDescription(this Type e, int? value) + { + FieldInfo[] fields = e.GetFields(); + for (int i = 1, count = fields.Length; i < count; i++) + { + if ((int)System.Enum.Parse(e, fields[i].Name) == value) + { + DescriptionAttribute[] EnumAttributes = (DescriptionAttribute[])fields[i]. + GetCustomAttributes(typeof(DescriptionAttribute), false); + if (EnumAttributes.Length > 0) + { + return EnumAttributes[0].Description; + } + } + } + return ""; + } + + public static string GetEnumDescription(Enum enumObj) + { + FieldInfo fieldInfo = enumObj.GetType().GetField(enumObj.ToString()); + var descriptionAttr = fieldInfo + .GetCustomAttributes(false) + .OfType() + .Cast() + .SingleOrDefault(); + if (descriptionAttr == null) + { + return enumObj.ToString(); + } + else + { + return descriptionAttr.Description; + } + } + + /// + /// 打开窗口,解决引用UI库样式丢失 + /// + /// + /// + public static T GenerateWindow() where T : System.Windows.Window, new() + { + string AddInPath = typeof(RsApp).Assembly.Location; + string dirAssembly = System.IO.Path.GetDirectoryName(AddInPath); + AssemblyLoader loader = new AssemblyLoader(dirAssembly); + T win = null; + try + { + loader.HookAssemblyResolve(); + + win = new T(); + System.Windows.Interop.WindowInteropHelper mainUI = new System.Windows.Interop.WindowInteropHelper(win) + { + Owner = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle + }; + win.ShowDialog(); + } + catch (Exception ex) + { + TaskDialog.Show("错误", ex.Message); + } + finally + { + loader.UnhookAssemblyResolve(); + } + + return win; + } + } +} \ No newline at end of file diff --git a/RookieStation/Utils/DocumentExtension.cs b/RookieStation/Utils/DocumentExtension.cs new file mode 100644 index 0000000..200a7f4 --- /dev/null +++ b/RookieStation/Utils/DocumentExtension.cs @@ -0,0 +1,210 @@ +using Autodesk.Revit.DB; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RookieStation.Utils +{ + public static class DocumentExtension + { + //private static void UsingThisClass(Document doc) + //{ + // //无返回值 + // doc.Invoke(m => { }, "x"); + // //有返回值 + // doc.Invoke(m => + // { + // return Level.Create(doc, 5); + // }, "x"); + + // doc.InvokeGroup(m => { doc.Invoke(mn => { }, "x"); }, "x"); + // doc.InvokeGroup(m => { doc.Invoke(mn => { }, "x"); doc.Invoke(mn => { }, "Y"); return Level.Create(doc, 5); }, "x"); + // doc.InvokeSub(m => { }); + // doc.InvokeSub(m => { return Level.Create(doc, 5); }); + //} + + public static void Invoke(this Document doc, Action action, string name = "default") + { + using (var tr = new Transaction(doc, name)) + { + tr.Start(); + + action(tr); + + var status = tr.GetStatus(); + + switch (status) + { + case TransactionStatus.Started: + tr.Commit(); + return; + + case TransactionStatus.Committed: + case TransactionStatus.RolledBack: + return; + + case TransactionStatus.Error: + tr.RollBack(); + return; + + default: + return; + } + } + } + + public static TResult Invoke(this Document doc, Func func, string name = "default") + { + using (var tr = new Transaction(doc, name)) + { + tr.Start(); + + var result = func(tr); + + var status = tr.GetStatus(); + switch (status) + { + case TransactionStatus.Started: + tr.Commit(); + return result; + + case TransactionStatus.Committed: + case TransactionStatus.RolledBack: + return result; + + case TransactionStatus.Error: + tr.RollBack(); + return result; + + default: + return result; + } + } + } + + public static void InvokeSub(this Document doc, Action action) + { + using (var st = new SubTransaction(doc)) + { + st.Start(); + + action(st); + + var status = st.GetStatus(); + switch (status) + { + case TransactionStatus.Started: + st.Commit(); + return; + + case TransactionStatus.Committed: + case TransactionStatus.RolledBack: + break; + + case TransactionStatus.Error: + st.RollBack(); + return; + + default: + return; + } + } + } + + public static TResult InvokeSub(this Document doc, Func func) + { + using (var st = new SubTransaction(doc)) + { + st.Start(); + + var result = func(st); + + var status = st.GetStatus(); + switch (status) + { + case TransactionStatus.Started: + st.Commit(); + return result; + + case TransactionStatus.Committed: + case TransactionStatus.RolledBack: + return result; + + case TransactionStatus.Error: + st.RollBack(); + return result; + + default: + return result; + } + } + } + + public static void InvokeGroup(this Document doc, Action action, string name = "default") + { + using (var tg = new TransactionGroup(doc, name)) + { + tg.Start(); + + action(tg); + + var status = tg.GetStatus(); + switch (status) + { + case TransactionStatus.Started: + //tr.Commit(); + tg.Assimilate(); + return; + + case TransactionStatus.Committed: + case TransactionStatus.RolledBack: + break; + + case TransactionStatus.Error: + tg.RollBack(); + return; + + default: + return; + } + } + } + + public static TResult InvokeGroup(this Document doc, Func func, string name = "default") + { + using (var tg = new TransactionGroup(doc, name)) + { + tg.Start(); + + var result = func(tg); + + var status = tg.GetStatus(); + switch (status) + { + case TransactionStatus.Started: + tg.Assimilate(); + //tr.Commit(); + return result; + + case TransactionStatus.Committed: + case TransactionStatus.RolledBack: + return result; + + case TransactionStatus.Error: + tg.RollBack(); + return result; + + default: + return result; + } + } + } + + public static FilteredElementCollector QueryByType(this Document doc) where T : Element + { + return new FilteredElementCollector(doc).OfClass(typeof(T)); + } + } +} \ No newline at end of file diff --git a/RookieStation/Utils/EnumItemsSource.cs b/RookieStation/Utils/EnumItemsSource.cs new file mode 100644 index 0000000..6c93456 --- /dev/null +++ b/RookieStation/Utils/EnumItemsSource.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Globalization; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace RookieStation.Utils +{ + internal class EnumItemsSource : Collection, IValueConverter + { + private Type type; + + private IDictionary valueToNameMap; + + private IDictionary nameToValueMap; + + public Type Type + { + get { return this.type; } + set + { + if (!value.IsEnum) + throw new ArgumentException("不是枚举类型", "value"); + this.type = value; + Initialize(); + } + } + + public Object Convert(Object value, Type targetType, Object parameter, CultureInfo culture) + { + return this.valueToNameMap[value]; + } + + public Object ConvertBack(Object value, Type targetType, Object parameter, CultureInfo culture) + { + return this.nameToValueMap[value]; + } + + private void Initialize() + { + this.valueToNameMap = this.type + .GetFields(BindingFlags.Static | BindingFlags.Public) + .ToDictionary(fi => fi.GetValue(null), GetDescription); + this.nameToValueMap = this.valueToNameMap + .ToDictionary(kvp => kvp.Value, kvp => kvp.Key); + Clear(); + foreach (String name in this.nameToValueMap.Keys) + Add(name); + } + + private static Object GetDescription(FieldInfo fieldInfo) + { + var descriptionAttribute = + (DescriptionAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(DescriptionAttribute)); + return descriptionAttribute != null ? descriptionAttribute.Description : fieldInfo.Name; + } + } +} \ No newline at end of file diff --git a/RookieStation/Utils/ExcelUtils.cs b/RookieStation/Utils/ExcelUtils.cs new file mode 100644 index 0000000..a559cfc --- /dev/null +++ b/RookieStation/Utils/ExcelUtils.cs @@ -0,0 +1,270 @@ +using Autodesk.Revit.DB; +using OfficeOpenXml; +using System; +using System.Collections.Generic; +using System.Data; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RookieStation.Utils +{ + internal class ExcelUtils + { + /// + /// 读取Excel所有表格 + /// + /// + public void ReadExcel(string path) + { + using (ExcelPackage package = new ExcelPackage(new FileStream(path, FileMode.Open))) + { + for (int i = 1; i <= package.Workbook.Worksheets.Count; ++i) + { + ExcelWorksheet sheet = package.Workbook.Worksheets[i]; + for (int j = sheet.Dimension.Start.Column, k = sheet.Dimension.End.Column; j <= k; j++) + { + for (int m = sheet.Dimension.Start.Row, n = sheet.Dimension.End.Row; m <= n; m++) + { + //string str = GetValue(sheet, m, j); + //if (str != null) + //{ + // // do something + //} + } + } + } + } + } + + /// + /// 创建Excel文件添加Excel表格 + /// + /// + public void WriteExcel(string path, string sheetName) + { + using (ExcelPackage package = new ExcelPackage()) + { + ExcelWorksheet sheet = package.Workbook.Worksheets.Add(sheetName); + + using (Stream stream = new FileStream(path, FileMode.Create)) + { + package.SaveAs(stream); + } + } + } + + /// + /// 工作表转换为DataTable,首行为表头 + /// + /// + /// + public static DataTable ExcelSheetToDataTable(ExcelWorksheet worksheet) + { + //获取worksheet的行数 + int rows = worksheet.Dimension.End.Row; + //获取worksheet的列数 + int cols = worksheet.Dimension.End.Column; + + DataTable dt = new DataTable(worksheet.Name); + DataRow dr = null; + for (int i = 1; i <= rows; i++) + { + if (i > 1) + dr = dt.Rows.Add(); + + for (int j = 1; j <= cols; j++) + { + //默认将第一行设置为datatable的标题 + if (i == 1) + dt.Columns.Add(worksheet.Cells[i, j].Value.ToString()); + //剩下的写入datatable + else + dr[j - 1] = worksheet.Cells[i, j].Value.ToString(); + } + } + return dt; + } + + /// + /// 工作表转换为DataTable + /// + /// + /// + /// + public static DataTable ExcelSheetToDataTable(string fileName, string sheetName) + { + FileInfo fi = new FileInfo(fileName); + ExcelPackage p = new ExcelPackage(fi); + ExcelWorkbook workbook = p.Workbook; + DataTable data = new DataTable(); + ExcelWorksheet worksheet = workbook.Worksheets[sheetName]; + //获取worksheet的行数 + int rows = worksheet.Dimension.End.Row; + //获取worksheet的列数 + int cols = worksheet.Dimension.End.Column; + + DataTable dt = new DataTable(worksheet.Name); + DataRow dr = null; + for (int i = 1; i <= rows; i++) + { + if (i > 1) + dr = dt.Rows.Add(); + + for (int j = 1; j <= cols; j++) + { + //默认将第一行设置为datatable的标题 + if (i == 1) + dt.Columns.Add(worksheet.Cells[i, j].Value.ToString()); + //剩下的写入datatable + else + dr[j - 1] = worksheet.Cells[i, j].Value.ToString(); + } + } + return dt; + } + + /// + /// DataTable导出为Excel + /// + /// + /// + public static void DataTableToExcel(string destFileName, DataTable dt) + { + FileInfo fi = new FileInfo(destFileName); + using (ExcelPackage package = new ExcelPackage(fi)) + { + try + { + ExcelWorksheet workSheet = package.Workbook.Worksheets.Add(dt.TableName); + workSheet.Cells["A1"].LoadFromDataTable(dt, true); + } + catch (Exception) + { + } + finally + { + package.Save(); + } + }; + } + + /// + ///给第一个表中的单元格赋值 + /// + /// + /// + /// + /// + public static void EditCellValue(string fileName, int rowNum, int ColumnNum, string value) + { + FileInfo fi = new FileInfo(fileName); + using (ExcelPackage package = new ExcelPackage(fi)) + { + ExcelPackage.LicenseContext = LicenseContext.NonCommercial; + ExcelWorksheet sheet = package.Workbook.Worksheets[0]; + string filename = System.IO.Path.GetFileNameWithoutExtension(fileName); + sheet.Cells[rowNum, ColumnNum].Value = value; + package.Save(); + } + } + + /// + /// 给工作表中的单元格赋值 + /// + /// + /// + /// + /// + /// + public static void EditCellValue(string fileName, string sheetname, int rowNum, int ColumnNum, string value) + { + FileInfo fi = new FileInfo(fileName); + using (ExcelPackage package = new ExcelPackage(fi)) + { + ExcelPackage.LicenseContext = LicenseContext.NonCommercial; + ExcelWorksheet sheet = package.Workbook.Worksheets[sheetname]; + string filename = System.IO.Path.GetFileNameWithoutExtension(fileName); + sheet.Cells[rowNum, ColumnNum].Value = value; + package.Save(); + } + } + + /// + /// 给第一个工作表中的单元格赋值 + /// + /// + /// + /// + /// + /// + public static void EditCellValue(string fileName, string cellName, string value) + { + FileInfo fi = new FileInfo(fileName); + using (ExcelPackage package = new ExcelPackage(fi)) + { + ExcelPackage.LicenseContext = LicenseContext.NonCommercial; + ExcelWorksheet sheet = package.Workbook.Worksheets[0]; + string filename = System.IO.Path.GetFileNameWithoutExtension(fileName); + sheet.Cells[cellName].Value = value; + package.Save(); + } + } + + /// + /// 给工作表中的单元格赋值 + /// + /// + /// + /// 单元格名称,比如A1 + /// + public static void EditCellValue(string fileName, string sheetname, string cellName, string value) + { + FileInfo fi = new FileInfo(fileName); + using (ExcelPackage package = new ExcelPackage(fi)) + { + ExcelPackage.LicenseContext = LicenseContext.NonCommercial; + ExcelWorksheet sheet = package.Workbook.Worksheets[sheetname]; + string filename = System.IO.Path.GetFileNameWithoutExtension(fileName); + sheet.Cells[cellName].Value = value; + package.Save(); + } + } + + /// + /// 导出明细表 + /// + /// + /// + public void ScheduleToExcel(Document doc, string path) + { + ViewSchedule v = doc.ActiveView as ViewSchedule; + TableData td = v.GetTableData(); + TableSectionData tdb = td.GetSectionData(SectionType.Header); + string head = v.GetCellText(SectionType.Header, 0, 0); + + TableSectionData tdd = td.GetSectionData(SectionType.Body); + + int c = tdd.NumberOfColumns; + int r = tdd.NumberOfRows; + + FileInfo fi = new FileInfo(path); + using (ExcelPackage package = new ExcelPackage(fi)) + { + var worksheet = package.Workbook.Worksheets[1]; + //var worksheet = package.Workbook.Worksheets["基本构件"]; + for (int i = 0; i < r; i++) + { + for (int j = 0; j < c; j++) + { + Autodesk.Revit.DB.CellType ctype = tdd.GetCellType(i, j); + string str = v.GetCellText(SectionType.Body, i, j); + worksheet.Cells[i, j].Value = v.GetCellText(SectionType.Body, i, j); + } + } + package.Save(); + }; + } + } +} \ No newline at end of file diff --git a/RookieStation/Utils/KeyPress.cs b/RookieStation/Utils/KeyPress.cs new file mode 100644 index 0000000..4fb4086 --- /dev/null +++ b/RookieStation/Utils/KeyPress.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace RookieStation.Utils +{ + /// + /// 按键 + /// + internal class KeyPress + { + [DllImport("USER32.DLL")] + public static extern bool PostMessage(IntPtr hWnd, uint msg, uint wParam, uint lParam); + + /// + /// 虚拟按钮 + /// + /// + /// + /// + [DllImport("user32.dll")] + private static extern uint MapVirtualKey(uint uCode, uint uMapType); + + private enum WH_KEYBOARD_LPARAM : uint + { + KEYDOWN = 0x00000001, + KEYUP = 0xC0000001 + } + + public enum KEYBOARD_MSG : uint + { + WM_KEYDOWN = 0x100, + WM_KEYUP = 0x101 + } + + private enum MVK_MAP_TYPE : uint + { + VKEY_TO_SCANCODE = 0, + SCANCODE_TO_VKEY = 1, + VKEY_TO_CHAR = 2, + SCANCODE_TO_LR_VKEY = 3 + } + + /// + /// 提交单个按钮 + /// + /// 窗口句柄 + /// + static public void OneKey(IntPtr handle, char letter) + { + uint scanCode = MapVirtualKey(letter, (uint)MVK_MAP_TYPE.VKEY_TO_SCANCODE); + + uint keyDownCode = (uint)WH_KEYBOARD_LPARAM.KEYDOWN | (scanCode << 16); + + uint keyUpCode = (uint)WH_KEYBOARD_LPARAM.KEYUP | (scanCode << 16); + + PostMessage(handle, (uint)KEYBOARD_MSG.WM_KEYDOWN, letter, keyDownCode); + + PostMessage(handle, (uint)KEYBOARD_MSG.WM_KEYUP, letter, keyUpCode); + } + + /// + /// 提交一系列按钮 + /// + /// + /// + public static void Keys(IntPtr revitHandle, string command) + { + //IntPtr revitHandle = System.Diagnostics.Process // 2018 + // .GetCurrentProcess().MainWindowHandle; // 2018 + + foreach (char letter in command) + { + OneKey(revitHandle, letter); + } + } + } +} \ No newline at end of file diff --git a/RookieStation/Utils/ProjectConfigUtil.cs b/RookieStation/Utils/ProjectConfigUtil.cs new file mode 100644 index 0000000..de56a2e --- /dev/null +++ b/RookieStation/Utils/ProjectConfigUtil.cs @@ -0,0 +1,60 @@ +using System; +using System.Configuration; +using System.IO; +using System.Reflection; + +namespace RookieStation.Utils +{ + internal static class ProjectConfigUtil + { + public static string GetCfgValue(string key) + { + Assembly assembly = Assembly.GetCallingAssembly(); + Uri uri = new Uri(Path.GetDirectoryName(assembly.CodeBase)); + ExeConfigurationFileMap map = new ExeConfigurationFileMap(); + map.ExeConfigFilename = Path.Combine(uri.LocalPath, assembly.GetName().Name + ".dll.config"); + Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None); + string loadpath = config.AppSettings.Settings[key].Value;//若路径存在则自动获取该路径 + return loadpath; + } + + /// + /// 保存到程序目录下的配置文件 + /// + /// + /// + public static void SetCfgPairs(string key, string value) + { + Assembly assembly = Assembly.GetCallingAssembly(); + Uri uri = new Uri(Path.GetDirectoryName(assembly.CodeBase)); + ExeConfigurationFileMap map = new ExeConfigurationFileMap(); + map.ExeConfigFilename = Path.Combine(uri.LocalPath, assembly.GetName().Name + ".dll.config"); + + Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None); + config.AppSettings.Settings[key].Value = value; //将用户选取的路径_path赋给app.config中的_path(名称自取) + config.AppSettings.SectionInformation.ForceSave = true; + + config.Save(ConfigurationSaveMode.Modified); //将配置保存 + ConfigurationManager.RefreshSection("appSettings");//刷新配置文件 + } + + /// + /// 选择保存的路径进行配置文件的保存 + /// + /// + /// + /// + public static void SetAndSaveCfg(string path, string key, string value) + { + ExeConfigurationFileMap map = new ExeConfigurationFileMap(); + map.ExeConfigFilename = path; + + Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None); + config.AppSettings.Settings[key].Value = value; //将用户选取的路径_path赋给app.config中的_path(名称自取) + config.AppSettings.SectionInformation.ForceSave = true; + + config.Save(ConfigurationSaveMode.Modified); //将配置保存 + ConfigurationManager.RefreshSection("appSettings");//刷新配置文件 + } + } +} \ No newline at end of file diff --git a/RookieStation/Utils/RsRevitUtils.cs b/RookieStation/Utils/RsRevitUtils.cs new file mode 100644 index 0000000..08f43e6 --- /dev/null +++ b/RookieStation/Utils/RsRevitUtils.cs @@ -0,0 +1,435 @@ +using Autodesk.Revit.DB; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Controls; + +namespace RookieStation.Utils +{ + internal static class RsRevitUtils + { + /// + /// 通过名称获取默认的墙类型完整厚度 + /// + /// 墙类型包含的字符串 + /// + public static double GetWallWidthByWallTypeName(Document doc, string wallTypeName, out WallType walltype) + { + double thickness = 0.0; + var walltypelist = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).OfClass(typeof(WallType)).Cast(); + walltype = walltypelist.FirstOrDefault(t => t.Name.Contains(wallTypeName)); + if (walltype != null) + { + thickness = walltype.Width; + //var compounds = walltype.GetCompoundStructure(); + //for (int i = 0; i < compounds.LayerCount; i++) + //{ + // thickness += compounds.GetWidth(); + //} + } + return thickness; + } + + /// + /// 获取元素定位点(仅以点定位的元素) + /// + /// + /// + public static XYZ GetXYZByElement(Element instance) + { + return instance.Location is LocationPoint lp ? lp.Point : null; + } + + /// + /// 调整族实例位置 + /// + /// + /// 需要偏移的族实例 + /// 用于调整偏移和角度的参考线 + /// 偏移量 + public static void AdjustInstances(Document doc, List fis, Line refer_line, double offest) + { + var zdir = XYZ.BasisZ; + + //通过第三点垂直于直线的单位向量(无论左右侧)*偏移距离(一半的闸机长度) + XYZ offestdir = zdir.CrossProduct(refer_line.Direction).Normalize() * offest; + //旋转角度 + double angle = XYZ.BasisY.AngleTo(offestdir); + //判断相对于Y轴是正向角度(逆时针)还是逆向角度(顺时针) + XYZ z = offestdir.CrossProduct(XYZ.BasisY).Normalize(); + if (z.IsAlmostEqualTo(XYZ.BasisZ)) + { + //逆向旋转,角度取负值 + angle = -angle; + //var ml = doc.Create.NewModelCurve(Line.CreateBound(XYZ.Zero, re), SketchPlane.Create(doc, Plane.CreateByNormalAndOrigin(XYZ.BasisZ, new XYZ()))); + } + + foreach (var fi in fis) + { + var p = GetXYZByElement(fi); + Line l = Line.CreateUnbound(p, XYZ.BasisZ); + //旋转,移动 + ElementTransformUtils.RotateElement(doc, fi.Id, l, angle); + ElementTransformUtils.MoveElement(doc, fi.Id, offestdir); + } + } + + /// + /// 朝着向量方向左侧偏移并调整角度对齐直线 + /// + /// + /// + /// + /// + public static void AdjustInstance(Document doc, FamilyInstance fi, Line refer_line, double offest) + { + //朝着向量方向左侧偏移 + var zdir = XYZ.BasisZ; + + //通过第三点垂直于直线的单位向量(无论左右侧)*偏移距离(一半的闸机长度) + XYZ offest_direction = zdir.CrossProduct(refer_line.Direction).Normalize() * offest; + //旋转角度 + double angle = XYZ.BasisY.AngleTo(offest_direction); + //判断相对于Y轴是正向角度(逆时针)还是逆向角度(顺时针) + XYZ z = offest_direction.CrossProduct(XYZ.BasisY).Normalize(); + if (z.IsAlmostEqualTo(XYZ.BasisZ)) + { + //逆向旋转,角度取负值 + angle = -angle; + } + + var p = GetXYZByElement(fi); + Line l = Line.CreateUnbound(p, XYZ.BasisZ); + //旋转,移动 + ElementTransformUtils.RotateElement(doc, fi.Id, l, angle + Math.PI); + ElementTransformUtils.MoveElement(doc, fi.Id, offest_direction); + } + + /// + /// 添加项目样板 + /// + public static void AddProjectTemplate() + { + //Autodesk.Revit.ApplicationServices.Application.CurrentUsersDataFolderPath + string oriDatei = @"" + Environment.GetEnvironmentVariable("appdata") + @"\Autodesk\Revit\Autodesk Revit 2020\Revit.ini"; + string tmpDatei = UserConstant.LibraryPreDirectory + "\\Rs.ini"; + + if (System.IO.File.Exists(oriDatei)) + { + using (StreamReader sr = new StreamReader(oriDatei, Encoding.Unicode)) + { + StreamWriter sw = new StreamWriter(tmpDatei, false, Encoding.Unicode); + string inputLine = ""; + + while ((inputLine = sr.ReadLine()) != null) + { + if (inputLine.StartsWith("DefaultTemplate=")) + { + inputLine.Insert(16, UserConstant.LibraryPreDirectory + "\\菜鸟驿站.rte,"); + //if (inputLine.Contains("Example_SCHEMA.rte")) + //{ + //} + //else + //{ + // inputLine = inputLine + @", Example_SCHEMA=C:\temp\Example_SCHEMA.rte"; + //} + } + sw.WriteLine(inputLine); + } + sw.Close(); + } + + System.IO.File.Replace(tmpDatei, oriDatei, null); + } + } + + public static FamilySymbol GetGuideSymbol(Document doc) + { + FamilySymbol linesymbol = null; + doc.Invoke(ts => + { + Family linefamily = GetLoadedFamily(doc, UserConstant.LibraryPreDirectory + "定位线.rfa"); + linesymbol = doc.GetElement(linefamily.GetFamilySymbolIds().FirstOrDefault()) as FamilySymbol; + }, "载入定位线并布置"); + + return linesymbol; + } + + public static Line GetGuideGeometryAndDeleteGuide(Document doc, List eleIdsAdded) + { + ElementId referlineid = eleIdsAdded.FirstOrDefault(); + FamilyInstance referline = doc.GetElement(referlineid) as FamilyInstance; + LocationCurve lc = referline.Location as LocationCurve; + Line referlinegeom = lc.Curve as Line; + doc.Invoke(ts => + { + doc.Delete(referlineid); + }, "删除参考线"); + + return referlinegeom; + } + + /// + /// 元素的所有面 + /// + /// 元素 + /// 打开方式 + /// 所有的面 + public static List GetFaceByElement(Element item, Options options) + { + List listFace = new List(); + //根据打开的方式得到几何信息 + GeometryElement geometry = item.get_Geometry(options); + foreach (GeometryObject geomObj in geometry) + { + //geomObj为几何实例 + GeometryInstance geomInstance = geomObj as GeometryInstance; + if (geomInstance != null) + { + //从实例中找到实例的几何体 + foreach (GeometryObject instObj in geomInstance.GetInstanceGeometry()) + { + //三维的实体 + Solid instsolid = instObj as Solid; + if (instsolid == null || instsolid.Faces.Size == 0 || instsolid.Edges.Size == 0) + { + continue; + } + foreach (Face face in instsolid.Faces) + { + listFace.Add(face); + } + } + } + //geomObj为几何体 + Solid solid = geomObj as Solid; + if (solid != null) + { + if (solid.Faces.Size == 0 || solid.Edges.Size == 0) + { + continue; + } + else + { + foreach (Face face in solid.Faces) + { + listFace.Add(face); + } + } + } + } + return listFace; + } + + /// + /// 获取族实例所有面(实际为族类型的所有面) + /// + /// + /// + public static List GetFacesByFamilyInstance(FamilyInstance instance, Options options) + { + List listFace = new List(); + //根据打开的方式得到几何信息 + GeometryElement geometry = instance.get_Geometry(options); + foreach (GeometryObject geomObj in geometry) + { + //geomObj为几何实例 + GeometryInstance geomInstance = geomObj as GeometryInstance; + //族实例未修改过(连接,剪切,复制,扩展) + bool usesSymbolGeometry = (instance is FamilyInstance) && !(instance as FamilyInstance).HasModifiedGeometry(); + var bo = instance.HasModifiedGeometry(); + GeometryElement instanceGeometry = usesSymbolGeometry ? geomInstance.GetSymbolGeometry() : geomInstance.GetInstanceGeometry(); + + if (instanceGeometry != null) + { + //instanceGeometry.GetTransformed(); + //从实例中找到实例的几何体 + foreach (GeometryObject instObj in instanceGeometry) + { + //三维的实体 + Solid instsolid = instObj as Solid; + if (instsolid == null || instsolid.Faces.Size == 0 || instsolid.Edges.Size == 0) + { + continue; + } + foreach (Face face in instsolid.Faces) + { + listFace.Add(face); + } + } + } + //geomObj为几何体 + Solid solid = geomObj as Solid; + if (solid != null) + { + if (solid.Faces.Size == 0 || solid.Edges.Size == 0) + { + continue; + } + else + { + foreach (Face face in solid.Faces) + { + listFace.Add(face); + } + } + } + } + return listFace; + } + + /// + /// 获取族实例所有面(无法用于尺寸标注) + /// + /// + /// + public static List GetFamilyInstanceFaces(FamilyInstance instance, Options options) + { + List listFace = new List(); + //根据打开的方式得到几何信息 + GeometryElement geometry = instance.get_Geometry(options); + + foreach (GeometryObject geomObj in geometry) + { + //geomObj为几何实例 + GeometryInstance geomInstance = geomObj as GeometryInstance; + var ins = geomInstance.GetInstanceGeometry(); + if (geomInstance != null) + { + //instanceGeometry.GetTransformed(); + //从实例中找到实例的几何体 + foreach (GeometryObject instObj in geomInstance.GetInstanceGeometry()) + { + //三维的实体 + Solid instsolid = instObj as Solid; + if (instsolid == null || instsolid.Faces.Size == 0 || instsolid.Edges.Size == 0) + { + continue; + } + foreach (Face face in instsolid.Faces) + { + listFace.Add(face); + } + } + } + //geomObj为几何体 + Solid solid = geomObj as Solid; + if (solid != null) + { + if (solid.Faces.Size == 0 || solid.Edges.Size == 0) + { + continue; + } + else + { + foreach (Face face in solid.Faces) + { + listFace.Add(face); + } + } + } + } + return listFace; + } + + /// + /// 找到嵌套族的默认面参照(仅针对只有一种嵌套族) + /// + /// + /// + /// + public static List GetFaceReferences(Document doc, FamilyInstance familyInstance) + { + //List references = new List(); + var instance = familyInstance.GetSubComponentIds() + .Select(a => doc.GetElement(a)) + .ToList(); + var ops = new Options(); + ops.ComputeReferences = true;//计算参照,为true时才能进行得到参照 + List faces = GetFaceByElement(instance.FirstOrDefault(), ops); + //List listFamilyInstances = new FilteredElementCollector(doc, doc.ActiveView.Id) + // .OfClass(typeof(FamilyInstance)) + // .Cast() + // .Where(a => a.SuperComponent == null) + // .SelectMany(a => a.GetSubComponentIds()) + // .Select(a => doc.GetElement(a)) + // .ToList(); + //foreach (var face in faces) + //{ + // //face.GetSurface(). + // references.Add(face.Reference); + //} + return faces; + } + + /// + /// 获取已载入同名族,若无,则载入 + /// + /// + /// + /// + internal static Family GetLoadedFamily(Document doc, string familyname) + { + Family family; + + family = new FilteredElementCollector(doc) + .OfClass(typeof(Family)) + .Cast() + .Where(f => f.Name == Path.GetFileNameWithoutExtension(familyname)) + .FirstOrDefault(); + if (family == null) + { + doc.LoadFamily(familyname, new RsFamilyLoadOption(), out family); + } + + return family; + } + + /// + /// 获取垂直于基准线的最长边 + /// + /// + /// + /// + public static Line GetLongestSegmentLine(IList segments, Line baseline) + { + Line line = null; + //var m = doc.GetElement(refer.ElementId); + foreach (var seg in segments) + { + Line templine = seg.GetCurve() as Line; + + //判断是否垂直 + double dotp = Math.Abs(templine.Direction.DotProduct(baseline.Direction)); + if (dotp < 0.0001) + { + if (line == null || line.Length < templine.Length) + { + line = templine; + } + } + } + + return line; + } + } + + internal class RsFamilyLoadOption : IFamilyLoadOptions + { + bool IFamilyLoadOptions.OnFamilyFound(bool familyInUse, out bool overwriteParameterValues) + { + overwriteParameterValues = false; + return true; + } + + bool IFamilyLoadOptions.OnSharedFamilyFound(Family sharedFamily, bool familyInUse, out FamilySource source, out bool overwriteParameterValues) + { + source = FamilySource.Project; + overwriteParameterValues = true; + return true; + } + }; +} \ No newline at end of file diff --git a/RookieStation/Utils/SelectFilter.cs b/RookieStation/Utils/SelectFilter.cs new file mode 100644 index 0000000..749ecde --- /dev/null +++ b/RookieStation/Utils/SelectFilter.cs @@ -0,0 +1,23 @@ +using Autodesk.Revit.DB; +using Autodesk.Revit.UI.Selection; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RookieStation.Utils +{ + internal class SelectFilter : ISelectionFilter + { + public bool AllowElement(Autodesk.Revit.DB.Element elem) + { + return elem is T; + } + + public bool AllowReference(Reference refer, XYZ point) + { + return true; + } + } +} \ No newline at end of file diff --git a/RookieStation/Utils/ViewPlanCmdEnabled.cs b/RookieStation/Utils/ViewPlanCmdEnabled.cs new file mode 100644 index 0000000..6756095 --- /dev/null +++ b/RookieStation/Utils/ViewPlanCmdEnabled.cs @@ -0,0 +1,30 @@ +using Autodesk.Revit.DB; +using Autodesk.Revit.UI; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RookieStation +{ + /// + /// 平面视图命令才可用 + /// + internal class ViewPlanCmdEnabled : IExternalCommandAvailability + { + public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) + { + if (null != applicationData.ActiveUIDocument) + { + Autodesk.Revit.DB.View view = applicationData.ActiveUIDocument.Document.ActiveView; + if (view.ViewType == ViewType.FloorPlan) + { + return true; + } + } + + return false; + } + } +} \ No newline at end of file diff --git a/RookieStation/Utils/WinIntPtr.cs b/RookieStation/Utils/WinIntPtr.cs new file mode 100644 index 0000000..ba4852a --- /dev/null +++ b/RookieStation/Utils/WinIntPtr.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace RookieStation.Utils +{ + /// + /// winAPI窗口控制 + /// + internal static class WinIntPtr + { + //窗体标题获取窗口 + [DllImport("user32.dll", EntryPoint = "FindWindow")] + public extern static IntPtr FindWindow(string lpClassName, string lpWindowName); + + //显示窗口 + [DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)] + public static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow);//ShowWindow 的第二参数, 1 表示显示, 0 表示隐藏,2 最小化窗口 3 最大化窗口 + + //设置为激活状态 + [DllImport("user32.dll")] + public static extern IntPtr SetActiveWindow(IntPtr hWnd); + + public static void ShowAndActive(string winname) + { + IntPtr ParenthWndldsl = FindWindow(null, winname); + if (!ParenthWndldsl.Equals(IntPtr.Zero)) + { + try + { + ShowWindow(ParenthWndldsl, 1); + SetActiveWindow(ParenthWndldsl); + } + catch (Exception) + { + throw; + } + } + } + } +} \ No newline at end of file diff --git a/RookieStation/WpfEntranceGate.xaml b/RookieStation/WpfEntranceGate.xaml new file mode 100644 index 0000000..44f5b81 --- /dev/null +++ b/RookieStation/WpfEntranceGate.xaml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + +