diff --git a/RookieStation/CmdArrangeShelfCards.cs b/RookieStation/CmdArrangeShelfCards.cs index 615628d..e8ab8bf 100644 --- a/RookieStation/CmdArrangeShelfCards.cs +++ b/RookieStation/CmdArrangeShelfCards.cs @@ -36,7 +36,6 @@ namespace RookieStation.PackAreaModule } catch (Exception ex) { - TaskDialog.Show("错误", ex.Message); Log.WriteLog(ex.Message); } finally diff --git a/RookieStation/CmdBrowserFamily.cs b/RookieStation/CmdBrowserFamily.cs index f9e7415..92bffc7 100644 --- a/RookieStation/CmdBrowserFamily.cs +++ b/RookieStation/CmdBrowserFamily.cs @@ -1,6 +1,7 @@ using Autodesk.Revit.DB; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; +using RookieStation.Utils; using System; using System.Collections.Generic; using System.Linq; @@ -13,17 +14,29 @@ namespace RookieStation.CommonTools [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] internal class CmdBrowserFamily : IExternalCommand { + private Guid guid = new Guid("{028001AD-0588-4A9C-AA03-D7E472D85050}"); + public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { - //var dpid = new DockablePaneId(PaneIdentifiers.GetManagerPaneIdentifier()); try { - var libraryDirectory = UserConstant.FamilyLibraryDirectory; - System.Diagnostics.Process.Start(libraryDirectory); + DockablePaneId id = new DockablePaneId(guid); + DockablePane pane = commandData.Application.GetDockablePane(id); + if (pane.IsShown()) + { + pane.Hide(); + } + else + { + pane.Show(); + } + //var libraryDirectory = UserConstant.FamilyLibraryDirectory; + //System.Diagnostics.Process.Start(libraryDirectory); } - catch (Exception) + catch (Exception ex) { - TaskDialog.Show("温馨提示", "路径不存在,无法浏览文件"); + Log.WriteLog(ex.Message); + //TaskDialog.Show("温馨提示", "路径不存在,无法浏览文件"); return Result.Failed; } diff --git a/RookieStation/CmdFloorFinishes.cs b/RookieStation/CmdFloorFinishes.cs new file mode 100644 index 0000000..d0f9fce --- /dev/null +++ b/RookieStation/CmdFloorFinishes.cs @@ -0,0 +1,540 @@ +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.Finishes +{ + [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] + [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] + [Obsolete] + internal class CmdFloorFinishes : IExternalCommand + { + 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; + var rooms = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms); + if (rooms.Count() == 0) + { + TaskDialog.Show("温馨提示", "项目中当前没有房间"); + return Result.Cancelled; + } + WpfFloorFinishes floorCovering = CommonUtils.GenerateWindow(); + + double length; + double width; + double gap; + + if (floorCovering.DialogResult == true) + { + length = floorCovering.PavementLength / 304.8; + width = floorCovering.PavementWidth / 304.8; + gap = floorCovering.PavementGap / 304.8; + } + else + { + return Result.Cancelled; + } + + return doc.InvokeGroup(tg => + { + Level baseLevel = doc.ActiveView.GenLevel; + if (baseLevel == null) + { + return Result.Failed; + } + + List modelCurveIds = new List(); + + try + { + //var v = new FilteredElementCollector(doc).OfClass(typeof(View)) + // .Cast() + // .FirstOrDefault(x => x.ViewType == ViewType.FloorPlan && x.GenLevel.Elevation == 0); + + //if (uidoc.ActiveView.ViewType != ViewType.FloorPlan) + //{ + // uidoc.RequestViewChange(v); + //} + + SelectFilter roomFilter = new SelectFilter(); + Reference roomReference = uidoc.Selection.PickObject(ObjectType.Element, roomFilter, "请选择房间"); + Room room = doc.GetElement(roomReference) as Room; + + var roompoint = RsRevitUtils.GetLocationPointByElement(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 referline = ml.GeometryCurve as Line; + Line longestLine = RsRevitUtils.GetLongestSegmentLine(segments, referline); + XYZ basePoint = uidoc.Selection.PickPoint(UserConstant.SnapAll, "请选择基准点(位于基准线上)"); + double lengthCount = basePoint.DistanceTo(referline.GetEndPoint(0)) + basePoint.DistanceTo(referline.GetEndPoint(1)); + if (referline.Length - lengthCount > 0.001) + { + MessageBox.Show("请选择基准线上的点", "温馨提示"); + return Result.Cancelled; + } + //if (basepoint.IsAlmostEqualTo(ml.GeometryCurve.GetEndPoint(0)) || basepoint.IsAlmostEqualTo(ml.GeometryCurve.GetEndPoint(1))) + //{ + //} + //基准线端点 + var endpoint1 = referline.GetEndPoint(0); + var endpoint2 = referline.GetEndPoint(1); + //基准点向端点的向量 + XYZ v1 = endpoint1 - basePoint; + XYZ v2 = endpoint2 - 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 lastpoints = 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 (endpoint1.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(endpoint1) - length / 2 - gap; + + var lastfinalpoint = lastp1 + (l1.Direction * (d1 / 2 + length / 2 + gap)) + (offestVector * width / 2); + + lastpoints.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 (endpoint2.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(endpoint2) - length / 2 - gap; + + var lastFinalPoint = lastp2 + (l2.Direction * (d2 / 2 + length / 2 + gap)) + (offestVector * width / 2); + + lastpoints.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); + } + doc.Invoke(ts => + { + //删除模型线 + doc.Delete(modelCurveIds); + family = RsRevitUtils.GetLoadedFamily(doc, UserConstant.FamilyLibraryDirectory + "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 lastpoints) + { + var fi = doc.Create + .NewFamilyInstance(p, symbol, baseLevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + instances.Add(fi); + } + }, "地面铺装"); + + doc.Invoke(ts => + { + XYZ veroffestdir = null; + if (zdir1 != null) + { + veroffestdir = zdir1.CrossProduct(referline.Direction).Normalize(); + } + if (zdir2 != null) + { + veroffestdir = zdir2.CrossProduct(referline.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.GetLocationPointByElement(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.GetLocationPointByElement(instances[i]); + + var dis1 = loc.DistanceTo(endpoint1); + var dis2 = loc.DistanceTo(endpoint2); + + 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(); + //} + } + }, "调整地砖"); + + doc.Invoke(ts => + { + List idsCopied = new List(); + for (int i = 0; i < instances.Count; i++) + { + FamilyInstance fi = instances[i]; + int num = (int)Math.Floor(longestLine.Length / (width + gap)); + double rem = longestLine.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); + + idsCopied.AddRange(eles.ToList()); + break; + } + eles = ElementTransformUtils.CopyElement(doc, fi.Id, offestVector * (width + gap) * j); + idsCopied.AddRange(eles.ToList()); + } + } + foreach (var id in idsCopied) + { + FamilyInstance instanceCopied = doc.GetElement(id) as FamilyInstance; + if (instanceCopied.Room == null) + { + doc.Delete(id); + } + } + }, "复制地砖"); + + #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) + // { + // } + // } + //} + + //Do Something. + + #endregion MyRegion + } + catch (Autodesk.Revit.Exceptions.OperationCanceledException) + { + if (tg.GetStatus() == TransactionStatus.Started) + { + tg.RollBack(); + } + return Result.Succeeded; + } + 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/CmdLogoExtrusion.cs b/RookieStation/CmdLogoExtrusion.cs index 3c2d8a6..b18a90c 100644 --- a/RookieStation/CmdLogoExtrusion.cs +++ b/RookieStation/CmdLogoExtrusion.cs @@ -1,6 +1,7 @@ using Autodesk.Revit.DB; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; +using RookieStation.Utils; using System; using System.Collections.Generic; using System.Linq; @@ -96,7 +97,7 @@ namespace RookieStation } catch (Exception ex) { - message = ex.Message; + Log.WriteLog(ex.Message); if (trans.GetStatus() == TransactionStatus.Started) { trans.RollBack(); diff --git a/RookieStation/CmdNewDimension.cs b/RookieStation/CmdNewDimension.cs index 85f93c2..7c75c11 100644 --- a/RookieStation/CmdNewDimension.cs +++ b/RookieStation/CmdNewDimension.cs @@ -60,25 +60,24 @@ namespace RookieStation 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); } + //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; } } diff --git a/RookieStation/CmdPlaceEntranceGate.cs b/RookieStation/CmdPlaceEntranceGate.cs index 91a5c22..29bd9b0 100644 --- a/RookieStation/CmdPlaceEntranceGate.cs +++ b/RookieStation/CmdPlaceEntranceGate.cs @@ -85,7 +85,12 @@ namespace RookieStation.PackAreaModule Document doc = uidoc.Document; fis = new List(); - Level level = uidoc.ActiveView.GenLevel; + Level baseLevel = doc.ActiveView.GenLevel; + if (baseLevel == null) + { + offest = 0.0; + return; + } Family gateFamily = RsRevitUtils.GetLoadedFamily(doc, UserConstant.FamilyLibraryDirectory + "Gate\\闸机.rfa"); ElementId symbolId = gateFamily.GetFamilySymbolIds().FirstOrDefault(); FamilySymbol gateSymbol = doc.GetElement(symbolId) as FamilySymbol; @@ -93,7 +98,7 @@ namespace RookieStation.PackAreaModule gateSymbol.Activate(); foreach (XYZ p in points) { - var instance = doc.Create.NewFamilyInstance(p, gateSymbol, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + var instance = doc.Create.NewFamilyInstance(p, gateSymbol, baseLevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); fis.Add(instance); } } diff --git a/RookieStation/CmdPlaceExitGate.cs b/RookieStation/CmdPlaceExitGate.cs index 1620f6a..9d606b8 100644 --- a/RookieStation/CmdPlaceExitGate.cs +++ b/RookieStation/CmdPlaceExitGate.cs @@ -109,6 +109,10 @@ namespace RookieStation.PackAreaModule //ElementId symbolId = family.GetFamilySymbolIds().FirstOrDefault(); FamilySymbol leftSymbol = doc.GetElement(leftSymbolId.FirstOrDefault()) as FamilySymbol; Level level = uidoc.ActiveView.GenLevel; + if (level == null) + { + return; + } if (isPassageStart)//起始是通道 { for (int i = 0; i < n; i++) diff --git a/RookieStation/CmdPlaceFloorFinishes.cs b/RookieStation/CmdPlaceFloorFinishes.cs index e4cfd4b..4a02077 100644 --- a/RookieStation/CmdPlaceFloorFinishes.cs +++ b/RookieStation/CmdPlaceFloorFinishes.cs @@ -5,9 +5,10 @@ using Autodesk.Revit.UI.Selection; using RookieStation.Utils; using System; using System.Collections.Generic; -using System.IO; using System.Linq; -using System.Windows; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Controls; namespace RookieStation.Finishes { @@ -15,522 +16,235 @@ namespace RookieStation.Finishes [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; + Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; Document doc = uidoc.Document; - Family family = null; - FamilySymbol symbol; - - WpfFloorFinishes floorCovering = CommonUtils.GenerateWindow(); - var roomcounts = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).OfClass(typeof(Room)).GetElementCount(); - if (roomcounts == 0) + var baselevel = doc.ActiveView.GenLevel; + if (baselevel == null) { - TaskDialog.Show("温馨提示", "项目中当前没有房间"); - return Result.Cancelled; + return Result.Failed; } - double length; - double width; - double gap; + WpfFloorFinishes floorCovering = CommonUtils.GenerateWindow(); + + double length, width, gap, thickness; if (floorCovering.DialogResult == true) { - length = floorCovering.PavementLength / 304.8; - width = floorCovering.PavementWidth / 304.8; - gap = floorCovering.PavementGap / 304.8; + length = floorCovering.PavementLength; + width = floorCovering.PavementWidth; + gap = floorCovering.PavementGap; + thickness = floorCovering.PavementThickness; } else { return Result.Cancelled; } - return doc.InvokeGroup(tg => - { - try - { - //var v = new FilteredElementCollector(doc).OfClass(typeof(View)) - // .Cast() - // .FirstOrDefault(x => x.ViewType == ViewType.FloorPlan && x.GenLevel.Elevation == 0); - - //if (uidoc.ActiveView.ViewType != ViewType.FloorPlan) - //{ - // uidoc.RequestViewChange(v); - //} - var baseLevel = doc.ActiveView.GenLevel; - List modelCurveIds = new List(); - - SelectFilter roomFilter = new SelectFilter(); - Reference roomReference = uidoc.Selection.PickObject(ObjectType.Element, roomFilter, "请选择房间"); - Room room = doc.GetElement(roomReference) as Room; - - var roompoint = RsRevitUtils.GetLocationPointByElement(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 referline = ml.GeometryCurve as Line; - Line longestLine = RsRevitUtils.GetLongestSegmentLine(segments, referline); - XYZ basePoint = uidoc.Selection.PickPoint(UserConstant.SnapAll, "请选择基准点(位于基准线上)"); - double lengthCount = basePoint.DistanceTo(referline.GetEndPoint(0)) + basePoint.DistanceTo(referline.GetEndPoint(1)); - if (referline.Length - lengthCount > 0.001) - { - MessageBox.Show("请选择基准线上的点", "温馨提示"); - return Result.Cancelled; - } - //if (basepoint.IsAlmostEqualTo(ml.GeometryCurve.GetEndPoint(0)) || basepoint.IsAlmostEqualTo(ml.GeometryCurve.GetEndPoint(1))) - //{ - //} - //基准线端点 - var endpoint1 = referline.GetEndPoint(0); - var endpoint2 = referline.GetEndPoint(1); - //基准点向端点的向量 - XYZ v1 = endpoint1 - basePoint; - XYZ v2 = endpoint2 - 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 lastpoints = 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 (endpoint1.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(endpoint1) - length / 2 - gap; - - var lastfinalpoint = lastp1 + (l1.Direction * (d1 / 2 + length / 2 + gap)) + (offestVector * width / 2); - - lastpoints.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 (endpoint2.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(endpoint2) - length / 2 - gap; - - var lastFinalPoint = lastp2 + (l2.Direction * (d2 / 2 + length / 2 + gap)) + (offestVector * width / 2); - - lastpoints.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); - } - doc.Invoke(ts => - { - //删除模型线 - doc.Delete(modelCurveIds); - family = RsRevitUtils.GetLoadedFamily(doc, UserConstant.FamilyLibraryDirectory + "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 lastpoints) - { - var fi = doc.Create - .NewFamilyInstance(p, symbol, baseLevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); - instances.Add(fi); - } - }, "地面铺装"); - - doc.Invoke(ts => - { - XYZ veroffestdir = null; - if (zdir1 != null) - { - veroffestdir = zdir1.CrossProduct(referline.Direction).Normalize(); - } - if (zdir2 != null) - { - veroffestdir = zdir2.CrossProduct(referline.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.GetLocationPointByElement(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.GetLocationPointByElement(instances[i]); - - var dis1 = loc.DistanceTo(endpoint1); - var dis2 = loc.DistanceTo(endpoint2); - - 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(); - //} - } - }, "调整地砖"); - - doc.Invoke(ts => - { - List idsCopied = new List(); - for (int i = 0; i < instances.Count; i++) - { - FamilyInstance fi = instances[i]; - int num = (int)Math.Floor(longestLine.Length / (width + gap)); - double rem = longestLine.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); - - idsCopied.AddRange(eles.ToList()); - break; - } - eles = ElementTransformUtils.CopyElement(doc, fi.Id, offestVector * (width + gap) * j); - idsCopied.AddRange(eles.ToList()); - } - } - foreach (var id in idsCopied) - { - FamilyInstance instanceCopied = doc.GetElement(id) as FamilyInstance; - if (instanceCopied.Room == null) - { - doc.Delete(id); - } - } - }, "复制地砖"); - - #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) - // { - // } - // } - //} - - //Do Something. - - #endregion MyRegion - } - catch (Autodesk.Revit.Exceptions.OperationCanceledException) - { - if (tg.GetStatus() == TransactionStatus.Started) - { - tg.RollBack(); - } - return Result.Succeeded; - } - return Result.Succeeded; - }, "地面铺装"); + CreateCurtainSystemByFace(uidoc, doc, length, width, gap, thickness); + //CreateCurtainSystemByRoom(uidoc, length, width, gap, thickness); + return Result.Succeeded; + //ModelCurveArray mca = new ModelCurveArray(); + //var roofTypes = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Roofs).OfClass(typeof(RoofType)).ToElements(); + //RoofType roofType = null; + //foreach (RoofType rooftype in roofTypes) + //{ + // if (rooftype.Name == "常规 - 400mm") + // { + // roofType = rooftype; + // break; + // } + //} + //doc.Invoke(ts => + //{ + // doc.Create.NewFootPrintRoof(curveArray, baselevel, roofType, out mca); + //}); } - private List GetIntersectPoints(List curves) + private static void CreateCurtainSystemByFace(UIDocument uidoc, Document doc, double length, double width, double gap, double thickness) { - //获取轴网的所有交点 - List Points = new List(); - foreach (Curve curve in curves) + Reference faceReference = uidoc.Selection.PickObject(ObjectType.Face, "请选择铺贴面"); + Element element = doc.GetElement(faceReference); + Face face = element.GetGeometryObjectFromReference(faceReference) as Face; + FaceArray faceArray = new FaceArray(); + faceArray.Append(face); + doc.InvokeGroup(tg => { - Curve currentCurve = curve; - foreach (Curve cur in curves) + var curtainSystemType = SetCurtainSystemType(doc, length, width, gap, thickness); + doc.Invoke(ts => { - IntersectionResultArray ira = null; - SetComparisonResult scr = currentCurve.Intersect(cur, out ira); - if (scr == SetComparisonResult.Overlap && ira.Size == 1) + var eleid = doc.Create.NewCurtainSystem(faceArray, curtainSystemType); + }); + }); + } + + private static void CreateCurtainSystemByRoom(UIDocument uidoc, double length, double width, double gap, double thickness) + { + Document doc = uidoc.Document; + + var rooms = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms); + if (rooms.Count() == 0) + { + TaskDialog.Show("温馨提示", "项目中当前没有房间"); + //return Result.Cancelled; + } + Reference refer = uidoc.Selection.PickObject(ObjectType.Element, new SelectFilter(), "请选择布置的房间"); + Room room = doc.GetElement(refer) as Room; + List curveLoops = new List(); + var opts = new SpatialElementBoundaryOptions(); + var segementsList = room.GetBoundarySegments(opts); + if (segementsList != null) + { + foreach (var boundarySegments in segementsList) + { + CurveLoop curveLoop = new CurveLoop(); + + foreach (var boundarySegment in boundarySegments) { - XYZ tp = ira.get_Item(0).XYZPoint; - if (Points.Where(m => m.IsAlmostEqualTo(tp)).Count() == 0) + curveLoop.Append(boundarySegment.GetCurve()); + } + curveLoops.Add(curveLoop); + } + } + doc.InvokeGroup(tg => + { + //平面视图Z方向 + //doc.ActiveView.ViewDirection; + FaceArray array = new FaceArray(); + DirectShape ds = null; + doc.Invoke(ts => + { + Solid solid = GeometryCreationUtilities.CreateExtrusionGeometry(curveLoops, -XYZ.BasisZ, 10.0); + ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_Mass)); + if (ds != null) + { + ds.AppendShape(new List() { solid }); + } + //doc.Create.NewFamilyInstance(,,,) + + foreach (Face face in solid.Faces) + { + PlanarFace pf = face as PlanarFace; + if (pf.FaceNormal.IsAlmostEqualTo(XYZ.BasisZ)) { - Points.Add(tp); //收集所有的交点 + array.Append(face); + break; + } + } + }, "创建体量,获取底面"); + + CurtainSystemType curtainSystemType = SetCurtainSystemType(doc, length, width, gap, thickness); + doc.Invoke(ts => + { + doc.Create.NewCurtainSystem(array, curtainSystemType); + if (ds != null) + { + doc.Delete(ds.Id); + } + }, "创建幕墙系统"); + }); + } + + private static CurtainSystemType SetCurtainSystemType(Document doc, double length, double width, double gap, double thickness) + { + var curtainSystemTypeCollector = new FilteredElementCollector(doc).OfClass(typeof(CurtainSystemType)).OfCategory(BuiltInCategory.OST_CurtaSystem); + var panelTypeCollector = new FilteredElementCollector(doc).OfClass(typeof(PanelType)).OfCategory(BuiltInCategory.OST_CurtainWallPanels); + var curtainWallMullionsTypeCollector = new FilteredElementCollector(doc).OfClass(typeof(MullionType)).OfCategory(BuiltInCategory.OST_CurtainWallMullions); + + CurtainSystemType curtainSystemType = null; + PanelType panelType = null; + MullionType mullionType = null; + + string cutainSystemTypeName = String.Format("{0}{1}{2}{3}", length, " x ", width, "mm"); + string panelTypeName = "铺贴"; + string mullionTypeName = String.Format("{0}{1}{2}{3}", gap, " x ", thickness, "mm"); + + doc.Invoke(ts => + { + try + { + PanelType defaultPanelType = panelTypeCollector.FirstOrDefault(p => p.Name.Contains("实体") || p.Name.Contains("Solid")) as PanelType; + panelType = defaultPanelType.Duplicate(panelTypeName) as PanelType; + } + catch (Autodesk.Revit.Exceptions.ArgumentException) + { + foreach (PanelType t in panelTypeCollector) + { + if (t.Name == panelTypeName) + { + panelType = t; + break; } } } - } - return Points; + }, "创建嵌板类型"); + doc.Invoke(ts => + { + try + { + MullionType defaultMullionType = curtainWallMullionsTypeCollector.FirstOrDefault(m => ((MullionType)m).FamilyName.Contains("矩形") || ((MullionType)m).FamilyName.Contains("Rectangular")) as MullionType; + mullionType = defaultMullionType.Duplicate(mullionTypeName) as MullionType; + } + catch (Autodesk.Revit.Exceptions.ArgumentException) + { + foreach (MullionType t in curtainWallMullionsTypeCollector) + { + if (t.Name == mullionTypeName) + { + mullionType = t; + break; + } + } + } + }, "创建竖挺类型"); + doc.Invoke(ts => + { + try + { + CurtainSystemType defaultCurtainSystemType = curtainSystemTypeCollector.FirstOrDefault() as CurtainSystemType; + curtainSystemType = defaultCurtainSystemType.Duplicate(cutainSystemTypeName) as CurtainSystemType; + } + catch (Autodesk.Revit.Exceptions.ArgumentException) + { + foreach (CurtainSystemType t in curtainSystemTypeCollector) + { + if (t.Name == cutainSystemTypeName) + { + curtainSystemType = t; + break; + } + } + } + }, "创建幕墙系统类型"); + doc.Invoke(ts => + { + mullionType.get_Parameter(BuiltInParameter.RECT_MULLION_WIDTH1).Set(gap / 304.8 / 2); + mullionType.get_Parameter(BuiltInParameter.RECT_MULLION_WIDTH2).Set(gap / 304.8 / 2); + mullionType.get_Parameter(BuiltInParameter.RECT_MULLION_THICK).Set(thickness / 304.8 * 2); + //mullionType.get_Parameter(BuiltInParameter.MULLION_OFFSET).Set(0); + //mullionType.get_Parameter(BuiltInParameter.MULLION_OFFSET).Set(thickness / 304.8 * 0.75 / 2); + + panelType.get_Parameter(BuiltInParameter.CURTAIN_WALL_SYSPANEL_THICKNESS).Set(thickness / 304.8 * 2); + //panelType.get_Parameter(BuiltInParameter.CURTAIN_WALL_SYSPANEL_OFFSET).Set(0); + //panelType.get_Parameter(BuiltInParameter.CURTAIN_WALL_SYSPANEL_OFFSET).Set(-thickness / 304.8 / 2); + + curtainSystemType.get_Parameter(BuiltInParameter.SPACING_LENGTH_1).Set((length + gap) / 304.8); + curtainSystemType.get_Parameter(BuiltInParameter.SPACING_LENGTH_2).Set((width + gap) / 304.8); + try + { + curtainSystemType.get_Parameter(BuiltInParameter.AUTO_PANEL).Set(panelType.Id); + curtainSystemType.get_Parameter(BuiltInParameter.AUTO_MULLION_INTERIOR_GRID1).Set(mullionType.Id); + curtainSystemType.get_Parameter(BuiltInParameter.AUTO_MULLION_INTERIOR_GRID2).Set(mullionType.Id); + } + catch (Exception) + { + throw; + } + }, "设置参数"); + return curtainSystemType; } - - //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 index 0cd79ba..e0143b2 100644 --- a/RookieStation/CmdPlaceLamps.cs +++ b/RookieStation/CmdPlaceLamps.cs @@ -30,8 +30,8 @@ namespace RookieStation.PackAreaModule double leftRightDistance = 0.0; double frontDistance = 0.0; - var roomCount = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).GetElementCount(); - if (roomCount == 0) + var rooms = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms); + if (rooms.Count() == 0) { TaskDialog.Show("温馨提示", "项目中当前没有房间"); return Result.Cancelled; @@ -53,21 +53,26 @@ namespace RookieStation.PackAreaModule { 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(); - if (uidoc.ActiveView.ViewType != ViewType.FloorPlan) - { - uidoc.RequestViewChange(v); - } + //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); + + //if (uidoc.ActiveView.ViewType != ViewType.FloorPlan) + //{ + // uidoc.RequestViewChange(v); + //} + Level baseLevel = doc.ActiveView.GenLevel; + if (baseLevel == null) + { + return Result.Failed; + } SelectFilter roomFilter = new SelectFilter(); Reference roomReference = uidoc.Selection.PickObject(ObjectType.Element, roomFilter, "请选择房间"); Room room = doc.GetElement(roomReference) as Room; diff --git a/RookieStation/CmdPlaceReceptionArea.cs b/RookieStation/CmdPlaceReceptionArea.cs index 116ed0d..ce4bcbb 100644 --- a/RookieStation/CmdPlaceReceptionArea.cs +++ b/RookieStation/CmdPlaceReceptionArea.cs @@ -93,6 +93,10 @@ namespace RookieStation.ShippingAreaModule return Result.Cancelled; } Level baseLevel = uidoc.ActiveView.GenLevel; + if (baseLevel == null) + { + return Result.Failed; + } Family family = null; FamilySymbol symbol; return doc.InvokeGroup(tg => @@ -149,7 +153,7 @@ namespace RookieStation.ShippingAreaModule if (n == 0) { var offestline = referline.CreateOffset(aluminumPlasticPanelThickness / 2 + baseLayerThickness, -XYZ.BasisZ); - var wall = Wall.Create(doc, offestline, aluminumPlasticPanelType.Id, doc.ActiveView.GenLevel.Id, aluminumPlasticPanelHeight, skirtingLineHeight, false, false); + var wall = Wall.Create(doc, offestline, aluminumPlasticPanelType.Id, baseLevel.Id, aluminumPlasticPanelHeight, skirtingLineHeight, false, false); wallIds.Add(wall.Id); } else @@ -165,7 +169,7 @@ namespace RookieStation.ShippingAreaModule } Line line = Line.CreateBound(startpoint, endpoint); var offestline = line.CreateOffset(aluminumPlasticPanelThickness / 2 + baseLayerThickness, -XYZ.BasisZ); - var wall = Wall.Create(doc, offestline, aluminumPlasticPanelType.Id, doc.ActiveView.GenLevel.Id, aluminumPlasticPanelHeight, skirtingLineHeight, false, false); + var wall = Wall.Create(doc, offestline, aluminumPlasticPanelType.Id, baseLevel.Id, aluminumPlasticPanelHeight, skirtingLineHeight, false, false); //不允许连接 WallUtils.DisallowWallJoinAtEnd(wall, 0); //curves.Add() @@ -174,18 +178,18 @@ namespace RookieStation.ShippingAreaModule } var skirtingOffestLine = referline.CreateOffset(skirtingLineThickness / 2 + baseLayerThickness, -XYZ.BasisZ); - var skirtingwall = Wall.Create(doc, skirtingOffestLine, skirtingLineType.Id, doc.ActiveView.GenLevel.Id, skirtingLineHeight, 0, false, false); + var skirtingwall = Wall.Create(doc, skirtingOffestLine, skirtingLineType.Id, baseLevel.Id, skirtingLineHeight, 0, false, false); wallIds.Add(skirtingwall.Id); var baseLayerOffestLine = referline.CreateOffset(baseLayerThickness / 2, -XYZ.BasisZ); - var baseLayerWall = Wall.Create(doc, baseLayerOffestLine, baseLayerType.Id, doc.ActiveView.GenLevel.Id, UserConstant.Height / 304.8, 0, false, false); + var baseLayerWall = Wall.Create(doc, baseLayerOffestLine, baseLayerType.Id, baseLevel.Id, UserConstant.Height / 304.8, 0, false, false); wallIds.Add(baseLayerWall.Id); //高度大于3000才有灰色乳胶漆 if (UserConstant.Height > 3000) { double baseHeight = aluminumPlasticPanelHeight + skirtingLineHeight; var greyEmulsionPaintOffestLine = referline.CreateOffset(baseLayerThickness + greyEmulsionPaintWidth / 2, -XYZ.BasisZ); - Wall greyPaintWall = Wall.Create(doc, greyEmulsionPaintOffestLine, greyEmulsionPaintType.Id, doc.ActiveView.GenLevel.Id, UserConstant.Height / 304.8 - baseHeight, baseHeight, false, false); + Wall greyPaintWall = Wall.Create(doc, greyEmulsionPaintOffestLine, greyEmulsionPaintType.Id, baseLevel.Id, UserConstant.Height / 304.8 - baseHeight, baseHeight, false, false); wallIds.Add(greyPaintWall.Id); } diff --git a/RookieStation/CmdPlaceShelves.cs b/RookieStation/CmdPlaceShelves.cs index b03451a..47208a2 100644 --- a/RookieStation/CmdPlaceShelves.cs +++ b/RookieStation/CmdPlaceShelves.cs @@ -54,7 +54,10 @@ namespace RookieStation.PackAreaModule ObservableCollection shelves = vm.Data; Level level = uidoc.ActiveView.GenLevel; - + if (level == null) + { + return Result.Failed; + } return doc.InvokeGroup(tg => { try diff --git a/RookieStation/CmdPlaceWallFinishes.cs b/RookieStation/CmdPlaceWallFinishes.cs index 7287152..28dd5b2 100644 --- a/RookieStation/CmdPlaceWallFinishes.cs +++ b/RookieStation/CmdPlaceWallFinishes.cs @@ -46,7 +46,6 @@ namespace RookieStation.Finishes } catch (Exception ex) { - TaskDialog.Show("错误", ex.Message); Log.WriteLog(ex.Message); } finally @@ -68,13 +67,15 @@ namespace RookieStation.Finishes { while (isContinue) { + var baselevel = doc.ActiveView.GenLevel; + if (placeType == "房间") { - var roomCount = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).GetElementCount(); - if (roomCount == 0) + var rooms = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms); + if (rooms.Count() == 0) { TaskDialog.Show("温馨提示", "项目中当前没有房间"); - return Result.Failed; + return Result.Cancelled; } Reference refer = uidoc.Selection.PickObject(ObjectType.Element, new SelectFilter(), "请选择布置的房间"); Room room = uidoc.Document.GetElement(refer) as Room; @@ -134,7 +135,7 @@ namespace RookieStation.Finishes //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 wallCreated = Wall.Create(doc, curve, wallType.Id, doc.ActiveView.GenLevel.Id, wallHeight / 304.8, wallBaseOffest / 304.8, false, false); + var wallCreated = Wall.Create(doc, curve, wallType.Id, baselevel.Id, wallHeight / 304.8, wallBaseOffest / 304.8, false, false); wallCreated.get_Parameter(BuiltInParameter.WALL_ATTR_ROOM_BOUNDING).Set(0); doc.Regenerate(); //连接墙体让门窗可以剪切出来 @@ -143,7 +144,18 @@ namespace RookieStation.Finishes Element elemToJoin = doc.GetElement(wallToJoinList[i][j]); try { - JoinGeometryUtils.JoinGeometry(doc, elemToJoin, wallCreated); + if (wallCreated.WallType.Kind == WallKind.Stacked) + { + foreach (var wallid in wallCreated.GetStackedWallMemberIds()) + { + Wall stackedwall = doc.GetElement(wallid) as Wall; + JoinGeometryUtils.JoinGeometry(doc, elemToJoin, stackedwall); + } + } + else + { + JoinGeometryUtils.JoinGeometry(doc, elemToJoin, wallCreated); + } } catch (Exception ex) { @@ -168,13 +180,25 @@ namespace RookieStation.Finishes face.Intersect(bottomFace, out instersectCurve); doc.Invoke(ts => { - Curve curve = instersectCurve.CreateOffset(wallWidth / 2, XYZ.BasisZ); + Curve curve = instersectCurve.CreateOffset(wallWidth / 2, XYZ.BasisZ).CreateReversed(); - var wallCreated = Wall.Create(doc, curve, wallType.Id, doc.ActiveView.GenLevel.Id, wallHeight / 304.8, wallBaseOffest / 304.8, false, false); + var wallCreated = Wall.Create(doc, curve, wallType.Id, baselevel.Id, wallHeight / 304.8, wallBaseOffest / 304.8, false, false); doc.Regenerate(); try { - JoinGeometryUtils.JoinGeometry(doc, wall, wallCreated); + if (wallCreated.WallType.Kind == WallKind.Stacked) + { + foreach (var wallid in wallCreated.GetStackedWallMemberIds()) + { + Wall stackedwall = doc.GetElement(wallid) as Wall; + JoinGeometryUtils.JoinGeometry(doc, wall, stackedwall); + } + } + else + { + JoinGeometryUtils.JoinGeometry(doc, wall, wallCreated); + } + //JoinGeometryUtils.JoinGeometry(doc, wall, wallCreated); } catch (Exception ex) { @@ -216,12 +240,24 @@ namespace RookieStation.Finishes for (int i = 0; i < curs.Count(); i++) { Curve curve = curs.ElementAt(i).CreateOffset(wallWidth / 2, -XYZ.BasisZ); - var wallCreated = Wall.Create(doc, curve, wallType.Id, doc.ActiveView.GenLevel.Id, wallHeight / 304.8, wallBaseOffest / 304.8, false, false); + var wallCreated = Wall.Create(doc, curve, wallType.Id, baselevel.Id, wallHeight / 304.8, wallBaseOffest / 304.8, false, false); doc.Regenerate(); try { - JoinGeometryUtils.JoinGeometry(doc, wall, wallCreated); + if (wallCreated.WallType.Kind == WallKind.Stacked) + { + foreach (var wallid in wallCreated.GetStackedWallMemberIds()) + { + Wall stackedwall = doc.GetElement(wallid) as Wall; + JoinGeometryUtils.JoinGeometry(doc, wall, stackedwall); + } + } + else + { + JoinGeometryUtils.JoinGeometry(doc, wall, wallCreated); + } + //JoinGeometryUtils.JoinGeometry(doc, wall, wallCreated); } catch (Exception ex) { diff --git a/RookieStation/Custom/Enum.cs b/RookieStation/Common/Enum.cs similarity index 100% rename from RookieStation/Custom/Enum.cs rename to RookieStation/Common/Enum.cs diff --git a/RookieStation/Common/FamilyInfo.cs b/RookieStation/Common/FamilyInfo.cs new file mode 100644 index 0000000..e216c0c --- /dev/null +++ b/RookieStation/Common/FamilyInfo.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Interop; +using System.Windows.Media.Imaging; +using System.Windows; +using RookieStation.Utils; + +namespace RookieStation +{ + internal class FamilyInfo + { + public FamilyInfo(string fullFileName) + { + FullFileName = fullFileName; + } + + public string FullFileName { get; internal set; } + + public BitmapSource ImageData => LoadImage(FullFileName, 128, 128); + public string Title => Path.GetFileNameWithoutExtension(FullFileName); + public string ToolTip { get; set; } + + public FileInfo FileInfo { get; set; } + + private BitmapSource LoadImage(string filename, int width, int height) + { + Bitmap bm = WindowsThumbnailProvider.GetThumbnail(filename, width, height, ThumbnailOptions.None); + return Imaging.CreateBitmapSourceFromHBitmap(bm.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); + } + } +} \ No newline at end of file diff --git a/RookieStation/Custom/Shelf.cs b/RookieStation/Common/Shelf.cs similarity index 96% rename from RookieStation/Custom/Shelf.cs rename to RookieStation/Common/Shelf.cs index 9d40f6a..ddc4cb4 100644 --- a/RookieStation/Custom/Shelf.cs +++ b/RookieStation/Common/Shelf.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace RookieStation +namespace RookieStation.PackAreaModule { public class Shelf { diff --git a/RookieStation/Custom/UserConstant.cs b/RookieStation/Common/UserConstant.cs similarity index 72% rename from RookieStation/Custom/UserConstant.cs rename to RookieStation/Common/UserConstant.cs index 609d84e..6a6647d 100644 --- a/RookieStation/Custom/UserConstant.cs +++ b/RookieStation/Common/UserConstant.cs @@ -14,7 +14,17 @@ namespace RookieStation public static string AddinDirectory => System.IO.Path.GetDirectoryName(AddinPath); - internal static string FamilyLibraryDirectory => AddinDirectory + "RsLibrary\\FamilyLibrary\\"; + //打包路径 + //internal static string FamilyLibraryDirectory => AddinDirectory + "\\FamilyLibrary\\"; + + //调试路径 + internal static string FamilyLibraryDirectory => AddinDirectory + "\\RsLibrary\\FamilyLibrary\\"; + + //打包路径 + //internal static string DocumentDirectory => AddinDirectory + "\\Document\\"; + + //调试路径 + internal static string DocumentDirectory => AddinDirectory + "\\RsLibrary\\Document\\"; internal static ObjectSnapTypes SnapAll => ObjectSnapTypes.Intersections diff --git a/RookieStation/FamilyDockablePaneHandler.cs b/RookieStation/FamilyDockablePaneHandler.cs new file mode 100644 index 0000000..2bff3f5 --- /dev/null +++ b/RookieStation/FamilyDockablePaneHandler.cs @@ -0,0 +1,59 @@ +using Autodesk.Revit.DB; +using Autodesk.Revit.UI; +using RookieStation.Utils; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RookieStation.CommonTools +{ + internal class LoadFamilyHandler : IExternalEventHandler + { + public FamilyInfo FamilyInfo { get; set; } + + public void Execute(UIApplication app) + { + try + { + Document doc = app.ActiveUIDocument.Document; + RsFamilyLoadOption familyLoadOption = new RsFamilyLoadOption(); + Family family = null; + FamilySymbol fs = null; + + doc.Invoke(ts => + { + var canloaded = doc.LoadFamily(FamilyInfo.FullFileName, familyLoadOption, out family); + if (canloaded) + { + fs = doc.GetElement(family.GetFamilySymbolIds().FirstOrDefault()) as FamilySymbol; + if (!fs.IsActive) + { + fs.Activate(); + } + } + else + { + TaskDialog.Show("温馨提示", "族已载入或载入失败。"); + } + }, "载入-" + FamilyInfo.Title); + if (fs != null) + { + app.ActiveUIDocument.PromptForFamilyInstancePlacement(fs); + //app.ActiveUIDocument.PromptToPlaceElementTypeOnLegendView(fs); + } + } + catch (Exception e) + { + Log.WriteLog(e.Message); + } + } + + public string GetName() + { + return "加载族"; + } + } +} \ No newline at end of file diff --git a/RookieStation/Properties/Settings.Designer.cs b/RookieStation/Properties/Settings.Designer.cs index ede4d20..21c21c6 100644 --- a/RookieStation/Properties/Settings.Designer.cs +++ b/RookieStation/Properties/Settings.Designer.cs @@ -72,5 +72,17 @@ namespace RookieStation.Properties { this["Shelves"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("C:\\ProgramData\\Autodesk\\Revit\\Addins\\2020\\RsLibrary\\FamilyLibrary")] + public string FamilyFolder { + get { + return ((string)(this["FamilyFolder"])); + } + set { + this["FamilyFolder"] = value; + } + } } } diff --git a/RookieStation/Properties/Settings.settings b/RookieStation/Properties/Settings.settings index 3912822..4576528 100644 --- a/RookieStation/Properties/Settings.settings +++ b/RookieStation/Properties/Settings.settings @@ -17,5 +17,8 @@ <string>单个,1500,400</string> </ArrayOfString> + + C:\ProgramData\Autodesk\Revit\Addins\2020\RsLibrary\FamilyLibrary + \ No newline at end of file diff --git a/RookieStation/Resources/Fonts/iconfont.ttf b/RookieStation/Resources/Fonts/iconfont.ttf new file mode 100644 index 0000000..e3938c7 Binary files /dev/null and b/RookieStation/Resources/Fonts/iconfont.ttf differ diff --git a/RookieStation/Resources/cainiao.png b/RookieStation/Resources/cainiao.png index d8e58ec..89b3204 100644 Binary files a/RookieStation/Resources/cainiao.png and b/RookieStation/Resources/cainiao.png differ diff --git a/RookieStation/RookieStation.addin b/RookieStation/RookieStation.addin index 29bc588..273f049 100644 --- a/RookieStation/RookieStation.addin +++ b/RookieStation/RookieStation.addin @@ -2,7 +2,7 @@ 菜鸟驿站插件 - \RsLibrary\RookieStation.dll + RsLibrary\RookieStation.dll 1aac8233-690c-4dd6-89c0-78221dd65497 RookieStation.RsApp ADSK diff --git a/RookieStation/RookieStation.csproj b/RookieStation/RookieStation.csproj index 87b79b6..1a56ca5 100644 --- a/RookieStation/RookieStation.csproj +++ b/RookieStation/RookieStation.csproj @@ -90,8 +90,11 @@ + + + True True @@ -107,13 +110,13 @@ - + - + - + @@ -127,8 +130,9 @@ - - + + + WpfEntranceGate.xaml @@ -136,6 +140,9 @@ WpfExitGate.xaml + + WpfFamilyDockablePane.xaml + WpfFloorFinishes.xaml @@ -164,6 +171,7 @@ SettingsSingleFileGenerator Settings.Designer.cs + Always @@ -185,6 +193,9 @@ Always + + Always + Always @@ -278,6 +289,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/RookieStation/RsApp.cs b/RookieStation/RsApp.cs index 8893467..bddd15d 100644 --- a/RookieStation/RsApp.cs +++ b/RookieStation/RsApp.cs @@ -1,4 +1,10 @@ using Autodesk.Revit.UI; +using RookieStation.CommonTools; +using RookieStation.Finishes; +using RookieStation.PackAreaModule; +using RookieStation.ShippingAreaModule; +using RookieStation.Statistics; +using RookieStation.Utils; using System; using System.Collections.Generic; using System.IO; @@ -27,6 +33,8 @@ namespace RookieStation //获取AddInPath的目录 private static string DirRequestAssembly = Path.GetDirectoryName(AddInPath); + private static string ViewPlanCmdEnabled = typeof(EnableCmdInViewPlan).ToString(); + private BitmapSource ConvertFromBitmap(System.Drawing.Bitmap bitmap) { return Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); @@ -50,7 +58,7 @@ namespace RookieStation //项目设置 RibbonPanel projectPanel = application.CreateRibbonPanel(TabName, ProjectSettingsPanelName); - PushButtonData projectPBD = new PushButtonData("项目设置", "项目设置", AddInPath, "RookieStation.CmdProjectSettings") + PushButtonData projectPBD = new PushButtonData("项目设置", "项目设置", AddInPath, typeof(CmdProjectSettings).FullName) { LargeImage = ConvertFromBitmap(Properties.Resources.cainiao), Image = ConvertFromBitmap(Properties.Resources.cainiao) @@ -58,21 +66,21 @@ namespace RookieStation var projectBtn = (PushButton)projectPanel.AddItem(projectPBD); //前台布置 RibbonPanel receptionAreaPanel = application.CreateRibbonPanel(TabName, ReceptionPanelName); - PushButtonData receptionLayoutPBD = new PushButtonData("寄件区布置", "前台布置", AddInPath, "RookieStation.ShippingAreaModule.CmdPlaceReceptionArea") + PushButtonData receptionLayoutPBD = new PushButtonData("寄件区布置", "前台布置", AddInPath, typeof(CmdPlaceReceptionArea).FullName) { LargeImage = ConvertFromBitmap(Properties.Resources.Reception), Image = ConvertFromBitmap(Properties.Resources.Reception) }; var receptionBtn = (PushButton)receptionAreaPanel.AddItem(receptionLayoutPBD); - receptionBtn.AvailabilityClassName = "RookieStation.ViewPlanCmdEnabled"; + receptionBtn.AvailabilityClassName = ViewPlanCmdEnabled; //出入口布置 RibbonPanel packAreaPanel = application.CreateRibbonPanel(TabName, EntranceAndExitGatePanelName); - PushButtonData entrancegateLayoutPBD = new PushButtonData("入口布置", "入口闸机", AddInPath, "RookieStation.PackAreaModule.CmdPlaceEntranceGate") + PushButtonData entrancegateLayoutPBD = new PushButtonData("入口布置", "入口闸机", AddInPath, typeof(CmdPlaceEntranceGate).FullName) { LargeImage = ConvertFromBitmap(Properties.Resources.EntranceGate), Image = ConvertFromBitmap(Properties.Resources.EntranceGate) }; - PushButtonData exitGateLayoutPBD = new PushButtonData("出口布置", "出口收检台", AddInPath, "RookieStation.PackAreaModule.CmdPlaceExitGate") + PushButtonData exitGateLayoutPBD = new PushButtonData("出口布置", "出口收检台", AddInPath, typeof(CmdPlaceExitGate).FullName) { LargeImage = ConvertFromBitmap(Properties.Resources.ExitGate), Image = ConvertFromBitmap(Properties.Resources.ExitGate) @@ -84,54 +92,54 @@ namespace RookieStation //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"; + entranceBtn.AvailabilityClassName = ViewPlanCmdEnabled; + exitBtn.AvailabilityClassName = ViewPlanCmdEnabled; - PushButtonData placeShelvesPBD = new PushButtonData("货架布置", "货架布置", AddInPath, "RookieStation.PackAreaModule.CmdPlaceShelves") + PushButtonData placeShelvesPBD = new PushButtonData("货架布置", "货架布置", AddInPath, typeof(CmdPlaceShelves).FullName) { LargeImage = ConvertFromBitmap(Properties.Resources.Shelf), Image = ConvertFromBitmap(Properties.Resources.Shelf) }; var placeShelvesBtn = (PushButton)packAreaPanel.AddItem(placeShelvesPBD); - placeShelvesBtn.AvailabilityClassName = "RookieStation.ViewPlanCmdEnabled"; + placeShelvesBtn.AvailabilityClassName = ViewPlanCmdEnabled; - PushButtonData placeShelveCardsPBD = new PushButtonData("货架端牌", "货架端牌", AddInPath, "RookieStation.PackAreaModule.CmdArrangeShelfCards") + PushButtonData placeShelveCardsPBD = new PushButtonData("货架端牌", "货架端牌", AddInPath, typeof(CmdArrangeShelfCards).FullName) { LargeImage = ConvertFromBitmap(Properties.Resources.ShelfCard), Image = ConvertFromBitmap(Properties.Resources.ShelfCard) }; var placeShelveCardsBtn = (PushButton)packAreaPanel.AddItem(placeShelveCardsPBD); - PushButtonData placeLampsPBD = new PushButtonData("灯具布置", "灯具布置", AddInPath, "RookieStation.PackAreaModule.CmdPlaceLamps") + PushButtonData placeLampsPBD = new PushButtonData("灯具布置", "灯具布置", AddInPath, typeof(CmdPlaceLamps).FullName) { LargeImage = ConvertFromBitmap(Properties.Resources.Lamp), Image = ConvertFromBitmap(Properties.Resources.Lamp) }; var placeLampsBtn = (PushButton)packAreaPanel.AddItem(placeLampsPBD); - placeLampsBtn.AvailabilityClassName = "RookieStation.ViewPlanCmdEnabled"; + placeLampsBtn.AvailabilityClassName = ViewPlanCmdEnabled; //饰面,完成面 RibbonPanel finishesPanel = application.CreateRibbonPanel(TabName, FinishesPanelName); - PushButtonData floorfinishesPBD = new PushButtonData("地面铺装", "地面铺装", AddInPath, "RookieStation.Finishes.CmdPlaceFloorFinishes") + PushButtonData floorfinishesPBD = new PushButtonData("地面铺装", "地面铺装", AddInPath, typeof(CmdPlaceFloorFinishes).FullName) { LargeImage = ConvertFromBitmap(Properties.Resources.FloorFinishes), Image = ConvertFromBitmap(Properties.Resources.FloorFinishes) }; var floorcoveringBtn = (PushButton)finishesPanel.AddItem(floorfinishesPBD); - floorcoveringBtn.AvailabilityClassName = "RookieStation.ViewPlanCmdEnabled"; + floorcoveringBtn.AvailabilityClassName = ViewPlanCmdEnabled; - PushButtonData wallcoveringPBD = new PushButtonData("墙饰面", "墙饰面", AddInPath, "RookieStation.Finishes.CmdPlaceWallFinishes") + PushButtonData wallcoveringPBD = new PushButtonData("墙饰面", "墙饰面", AddInPath, typeof(CmdPlaceWallFinishes).FullName) { LargeImage = ConvertFromBitmap(Properties.Resources.WallFinishes), Image = ConvertFromBitmap(Properties.Resources.WallFinishes) }; var wallcoveringBtn = (PushButton)finishesPanel.AddItem(wallcoveringPBD); - wallcoveringBtn.AvailabilityClassName = "RookieStation.ViewPlanCmdEnabled"; + wallcoveringBtn.AvailabilityClassName = ViewPlanCmdEnabled; //统计面板 RibbonPanel statisticsPanel = application.CreateRibbonPanel(TabName, StatisticsPanelName); - PushButtonData statisticsfamilyPBD = new PushButtonData("输出统计表", "工程量统计", AddInPath, "RookieStation.Statistics.CmdExportWorkSchedule") + PushButtonData statisticsfamilyPBD = new PushButtonData("输出统计表", "工程量统计", AddInPath, typeof(CmdExportWorkSchedule).FullName) { LargeImage = ConvertFromBitmap(Properties.Resources.WorkSchedule), Image = ConvertFromBitmap(Properties.Resources.WorkSchedule) @@ -140,13 +148,14 @@ namespace RookieStation //通用面板 RibbonPanel commonToolsPanel = application.CreateRibbonPanel(TabName, CommonTools); - PushButtonData browserfamilyPBD = new PushButtonData("浏览族", "浏览族文件", AddInPath, "RookieStation.CommonTools.CmdBrowserFamily") + PushButtonData browserfamilyPBD = new PushButtonData("浏览族", "浏览族文件", AddInPath, typeof(CmdBrowserFamily).FullName) { LargeImage = ConvertFromBitmap(Properties.Resources.FamilyLib), Image = ConvertFromBitmap(Properties.Resources.FamilyLib) }; commonToolsPanel.AddItem(browserfamilyPBD); + RegisterDockPane(application); return Result.Succeeded; #region MyRegion @@ -205,9 +214,17 @@ namespace RookieStation } catch (Exception ex) { - MessageBox.Show(ex.Message); + Log.WriteLog(ex.Message); return Result.Cancelled; } } + + private void RegisterDockPane(UIControlledApplication application) + { + Guid guid = new Guid("{028001AD-0588-4A9C-AA03-D7E472D85050}"); + DockablePaneId id = new DockablePaneId(guid); + WpfFamilyDockablePane pane = new WpfFamilyDockablePane(); + application.RegisterDockablePane(id, "族库", pane as IDockablePaneProvider); + } } } \ No newline at end of file diff --git a/RookieStation/RsLibrary/Document/样板工程量清单.xlsx b/RookieStation/RsLibrary/Document/样板工程量清单.xlsx index 2c854e7..d8de16c 100644 Binary files a/RookieStation/RsLibrary/Document/样板工程量清单.xlsx and b/RookieStation/RsLibrary/Document/样板工程量清单.xlsx differ diff --git a/RookieStation/RsLibrary/FamilyLibrary/Gate/直线形收检台.0001.rfa b/RookieStation/RsLibrary/FamilyLibrary/Gate/直线形收检台.0001.rfa new file mode 100644 index 0000000..afcaba7 Binary files /dev/null and b/RookieStation/RsLibrary/FamilyLibrary/Gate/直线形收检台.0001.rfa differ diff --git a/RookieStation/RsLibrary/FamilyLibrary/Gate/直线形收检台.rfa b/RookieStation/RsLibrary/FamilyLibrary/Gate/直线形收检台.rfa index afcaba7..5924c76 100644 Binary files a/RookieStation/RsLibrary/FamilyLibrary/Gate/直线形收检台.rfa and b/RookieStation/RsLibrary/FamilyLibrary/Gate/直线形收检台.rfa differ diff --git a/RookieStation/ShelvesPlacementViewModel.cs b/RookieStation/ShelvesPlacementViewModel.cs index feb396c..585e018 100644 --- a/RookieStation/ShelvesPlacementViewModel.cs +++ b/RookieStation/ShelvesPlacementViewModel.cs @@ -6,7 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace RookieStation +namespace RookieStation.PackAreaModule { public class ShelvesPlacementViewModel { diff --git a/RookieStation/Utils/CommonUtils.cs b/RookieStation/Utils/CommonUtils.cs index abcf59b..f7dcc86 100644 --- a/RookieStation/Utils/CommonUtils.cs +++ b/RookieStation/Utils/CommonUtils.cs @@ -72,7 +72,6 @@ namespace RookieStation.Utils } catch (Exception ex) { - TaskDialog.Show("错误", ex.Message); Log.WriteLog(ex.Message); } finally diff --git a/RookieStation/Utils/ViewPlanCmdEnabled.cs b/RookieStation/Utils/EnableCmdInViewPlan.cs similarity index 95% rename from RookieStation/Utils/ViewPlanCmdEnabled.cs rename to RookieStation/Utils/EnableCmdInViewPlan.cs index b1461f5..7440353 100644 --- a/RookieStation/Utils/ViewPlanCmdEnabled.cs +++ b/RookieStation/Utils/EnableCmdInViewPlan.cs @@ -11,7 +11,7 @@ namespace RookieStation /// /// 平面视图命令才可用 /// - internal class ViewPlanCmdEnabled : IExternalCommandAvailability + internal class EnableCmdInViewPlan : IExternalCommandAvailability { public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) { diff --git a/RookieStation/Utils/ExcelUtils.cs b/RookieStation/Utils/ExcelUtils.cs index fd282da..ebc4490 100644 --- a/RookieStation/Utils/ExcelUtils.cs +++ b/RookieStation/Utils/ExcelUtils.cs @@ -140,8 +140,9 @@ namespace RookieStation.Utils ExcelWorksheet workSheet = package.Workbook.Worksheets.Add(dt.TableName); workSheet.Cells["A1"].LoadFromDataTable(dt, true); } - catch (Exception) + catch (Exception ex) { + Log.WriteLog(ex.Message); } finally { diff --git a/RookieStation/Utils/Log.cs b/RookieStation/Utils/Log.cs index e68e137..4f80c00 100644 --- a/RookieStation/Utils/Log.cs +++ b/RookieStation/Utils/Log.cs @@ -13,7 +13,7 @@ namespace RookieStation.Utils { try { - string logFolder = UserConstant.FamilyLibraryDirectory + "\\Log"; + string logFolder = UserConstant.FamilyLibraryDirectory + "Log\\"; string logFile = Path.Combine(logFolder, DateTime.Now.ToString("yyyyMMdd") + ".log"); if (!Directory.Exists(logFolder)) Directory.CreateDirectory(logFolder); diff --git a/RookieStation/Utils/WindowsThumbnailProvider.cs b/RookieStation/Utils/WindowsThumbnailProvider.cs new file mode 100644 index 0000000..690bcd0 --- /dev/null +++ b/RookieStation/Utils/WindowsThumbnailProvider.cs @@ -0,0 +1,210 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace RookieStation.Utils +{ + public enum ThumbnailOptions + { + None = 0x00, + BiggerSizeOk = 0x01, + InMemoryOnly = 0x02, + IconOnly = 0x04, + ThumbnailOnly = 0x08, + InCacheOnly = 0x10, + } + + public class WindowsThumbnailProvider + { + private const string IShellItem2Guid = "7E9FB0D3-919F-4307-AB2E-9B1860310C93"; + + [DllImport("shell32.dll", CharSet = CharSet.Unicode, SetLastError = true)] + internal static extern int SHCreateItemFromParsingName( + [MarshalAs(UnmanagedType.LPWStr)] string path, + // The following parameter is not used - binding context. + IntPtr pbc, + ref Guid riid, + [MarshalAs(UnmanagedType.Interface)] out IShellItem shellItem); + + [DllImport("gdi32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + internal static extern bool DeleteObject(IntPtr hObject); + + [ComImport] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe")] + internal interface IShellItem + { + void BindToHandler(IntPtr pbc, + [MarshalAs(UnmanagedType.LPStruct)] Guid bhid, + [MarshalAs(UnmanagedType.LPStruct)] Guid riid, + out IntPtr ppv); + + void GetParent(out IShellItem ppsi); + + void GetDisplayName(SIGDN sigdnName, out IntPtr ppszName); + + void GetAttributes(uint sfgaoMask, out uint psfgaoAttribs); + + void Compare(IShellItem psi, uint hint, out int piOrder); + }; + + internal enum SIGDN : uint + { + NORMALDISPLAY = 0, + PARENTRELATIVEPARSING = 0x80018001, + PARENTRELATIVEFORADDRESSBAR = 0x8001c001, + DESKTOPABSOLUTEPARSING = 0x80028000, + PARENTRELATIVEEDITING = 0x80031001, + DESKTOPABSOLUTEEDITING = 0x8004c000, + FILESYSPATH = 0x80058000, + URL = 0x80068000 + } + + internal enum HResult + { + Ok = 0x0000, + False = 0x0001, + InvalidArguments = unchecked((int)0x80070057), + OutOfMemory = unchecked((int)0x8007000E), + NoInterface = unchecked((int)0x80004002), + Fail = unchecked((int)0x80004005), + ElementNotFound = unchecked((int)0x80070490), + TypeElementNotFound = unchecked((int)0x8002802B), + NoObject = unchecked((int)0x800401E5), + Win32ErrorCanceled = 1223, + Canceled = unchecked((int)0x800704C7), + ResourceInUse = unchecked((int)0x800700AA), + AccessDenied = unchecked((int)0x80030005) + } + + [ComImportAttribute()] + [GuidAttribute("bcc18b79-ba16-442f-80c4-8a59c30c463b")] + [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] + internal interface IShellItemImageFactory + { + [PreserveSig] + HResult GetImage( + [In, MarshalAs(UnmanagedType.Struct)] NativeSize size, + [In] ThumbnailOptions flags, + [Out] out IntPtr phbm); + } + + [StructLayout(LayoutKind.Sequential)] + internal struct NativeSize + { + private int width; + private int height; + + public int Width { set { width = value; } } + public int Height { set { height = value; } } + }; + + [StructLayout(LayoutKind.Sequential)] + public struct RGBQUAD + { + public byte rgbBlue; + public byte rgbGreen; + public byte rgbRed; + public byte rgbReserved; + } + + public static Bitmap GetThumbnail(string fileName, int width, int height, ThumbnailOptions options) + { + IntPtr hBitmap = GetHBitmap(Path.GetFullPath(fileName), width, height, options); + + try + { + // return a System.Drawing.Bitmap from the hBitmap + return GetBitmapFromHBitmap(hBitmap); + } + finally + { + // delete HBitmap to avoid memory leaks + DeleteObject(hBitmap); + } + } + + public static Bitmap GetBitmapFromHBitmap(IntPtr nativeHBitmap) + { + Bitmap bmp = Bitmap.FromHbitmap(nativeHBitmap); + + if (Bitmap.GetPixelFormatSize(bmp.PixelFormat) < 32) + return bmp; + + return CreateAlphaBitmap(bmp, PixelFormat.Format32bppArgb); + } + + public static Bitmap CreateAlphaBitmap(Bitmap srcBitmap, PixelFormat targetPixelFormat) + { + Bitmap result = new Bitmap(srcBitmap.Width, srcBitmap.Height, targetPixelFormat); + + Rectangle bmpBounds = new Rectangle(0, 0, srcBitmap.Width, srcBitmap.Height); + + BitmapData srcData = srcBitmap.LockBits(bmpBounds, ImageLockMode.ReadOnly, srcBitmap.PixelFormat); + + bool isAlplaBitmap = false; + + try + { + for (int y = 0; y <= srcData.Height - 1; y++) + { + for (int x = 0; x <= srcData.Width - 1; x++) + { + Color pixelColor = Color.FromArgb( + Marshal.ReadInt32(srcData.Scan0, (srcData.Stride * y) + (4 * x))); + + if (pixelColor.A > 0 & pixelColor.A < 255) + { + isAlplaBitmap = true; + } + + result.SetPixel(x, y, pixelColor); + } + } + } + finally + { + srcBitmap.UnlockBits(srcData); + } + + if (isAlplaBitmap) + { + return result; + } + else + { + return srcBitmap; + } + } + + private static IntPtr GetHBitmap(string fileName, int width, int height, ThumbnailOptions options) + { + IShellItem nativeShellItem; + Guid shellItem2Guid = new Guid(IShellItem2Guid); + int retCode = SHCreateItemFromParsingName(fileName, IntPtr.Zero, ref shellItem2Guid, out nativeShellItem); + + if (retCode != 0) + throw Marshal.GetExceptionForHR(retCode); + + NativeSize nativeSize = new NativeSize(); + nativeSize.Width = width; + nativeSize.Height = height; + + IntPtr hBitmap; + HResult hr = ((IShellItemImageFactory)nativeShellItem).GetImage(nativeSize, options, out hBitmap); + + Marshal.ReleaseComObject(nativeShellItem); + + if (hr == HResult.Ok) return hBitmap; + + throw Marshal.GetExceptionForHR((int)hr); + } + } +} \ No newline at end of file diff --git a/RookieStation/WpfFamilyDockPane.xaml b/RookieStation/WpfFamilyDockPane.xaml new file mode 100644 index 0000000..449a9f9 --- /dev/null +++ b/RookieStation/WpfFamilyDockPane.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/RookieStation/WpfFamilyDockPane.xaml.cs b/RookieStation/WpfFamilyDockPane.xaml.cs new file mode 100644 index 0000000..2f303e4 --- /dev/null +++ b/RookieStation/WpfFamilyDockPane.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace RookieStation +{ + /// + /// WpfFamilyDockPane.xaml 的交互逻辑 + /// + public partial class WpfFamilyDockPane : UserControl + { + public WpfFamilyDockPane() + { + InitializeComponent(); + } + } +} diff --git a/RookieStation/WpfFamilyDockablePane.xaml b/RookieStation/WpfFamilyDockablePane.xaml new file mode 100644 index 0000000..42796a2 --- /dev/null +++ b/RookieStation/WpfFamilyDockablePane.xaml @@ -0,0 +1,122 @@ + + + + pack://application:,,,/RookieStation;component/Resources/Fonts/#iconfont + + + + + + + + + + + + + + + + + +