From 52d30a7ad9c9773792909361d872bae028c8e60f Mon Sep 17 00:00:00 2001 From: GG Z <903524121@qq.com> Date: Wed, 23 Jun 2021 12:51:54 +0800 Subject: [PATCH] =?UTF-8?q?LOGO=E6=8C=A4=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RookieStation/CmdLogoExtrusion.cs | 176 ++++++++++++------ RookieStation/CmdPlaceFloorFinishes.cs | 45 +++-- .../Properties/Resources.Designer.cs | 10 + RookieStation/Properties/Resources.resx | 3 + RookieStation/Resources/LogoExtrusion.png | Bin 0 -> 1080 bytes RookieStation/RookieStation.csproj | 1 + RookieStation/RsApp.cs | 8 + RookieStation/WpfFloorFinishes.xaml | 11 +- RookieStation/WpfFloorFinishes.xaml.cs | 10 + 9 files changed, 180 insertions(+), 84 deletions(-) create mode 100644 RookieStation/Resources/LogoExtrusion.png diff --git a/RookieStation/CmdLogoExtrusion.cs b/RookieStation/CmdLogoExtrusion.cs index 7afc808..d2ec25a 100644 --- a/RookieStation/CmdLogoExtrusion.cs +++ b/RookieStation/CmdLogoExtrusion.cs @@ -20,27 +20,56 @@ namespace RookieStation UIDocument uidoc = uiapp.ActiveUIDocument; Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; Document doc = uidoc.Document; - var instances = new FilteredElementCollector(doc).OfClass(typeof(ImportInstance)).Cast(); + //var instances = new FilteredElementCollector(doc).OfClass(typeof(ImportInstance)).Cast(); List curves = new List(); - - var geometryElement = instances.First().get_Geometry(new Options()); - - foreach (var geomObj in geometryElement) + ImportInstance importInstance = null; + string familyfilename = string.Empty; + //var geometryElement = instances.First().get_Geometry(new Options()); + try { - GeometryInstance geometryInstance = geomObj as GeometryInstance; - if (geometryInstance != null) + var importRefer = uidoc.Selection.PickObject(ObjectType.Element, new SelectFilter(), "请选择CAD图块"); + importInstance = doc.GetElement(importRefer) as ImportInstance; + string s = importInstance.Category.Name; + familyfilename = s.Substring(0, s.LastIndexOf(".")); + var geometryElement = importInstance.get_Geometry(new Options()); + foreach (var geomObj in geometryElement) { - foreach (var instObj in geometryInstance.GetSymbolGeometry()) + GeometryInstance geometryInstance = geomObj as GeometryInstance; + if (geometryInstance != null) { - Curve curve = instObj as Curve; - if (curve == null) + foreach (var instObj in geometryInstance.GetSymbolGeometry()) { - continue; + Curve curve = instObj as Curve; + if (curve != null) + { + curves.Add(curve); + } + PolyLine polyLine = instObj as PolyLine; + if (polyLine != null) + { + var points = polyLine.GetCoordinates(); + for (int i = 0; i < points.Count - 1; i++) + { + try + { + Line line = Line.CreateBound(points[i], points[i + 1]); + curves.Add(line); + } + catch (Exception) + { + continue; + } + } + } } - curves.Add(curve); } } } + catch (Autodesk.Revit.Exceptions.OperationCanceledException) + { + return Result.Cancelled; + } + //doc.Invoke(ts => //{ // foreach (var curve in curves) @@ -51,60 +80,80 @@ namespace RookieStation //}); CurveArrArray arrArray = new CurveArrArray(); CurveArray array = new CurveArray(); - - SearchCurveConnected(curves, curves.FirstOrDefault(), array, arrArray); - //do - //{ - // Curve baseCurve = curves.Last(); - // var tempEndXyz = baseCurve.GetEndPoint(1); - // array.Clear(); - // array.Append(baseCurve); - // curves.Remove(baseCurve); - - // for (int j = curves.Count - 1; j >= 0; j--) - // { - // Curve tempCurve = curves[j]; - - // if (tempCurve.GetEndPoint(0).IsAlmostEqualTo(tempEndXyz)) - // { - // baseCurve = tempCurve; - // tempEndXyz = tempCurve.GetEndPoint(1); - // array.Append(tempCurve); - // curves.Remove(tempCurve); - // continue; - // } - // else if (tempCurve.GetEndPoint(1).IsAlmostEqualTo(tempEndXyz)) - // { - // baseCurve = tempCurve; - // tempEndXyz = tempCurve.GetEndPoint(0); - // array.Append(tempCurve); - // curves.Remove(tempCurve); - // continue; - // } - // } - // arrArray.Append(array); - //} while (curves.Count > 0); - - doc.Invoke(ts => + if (curves.Count == 0) { - SketchPlane plane = SketchPlane.Create(doc, Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero)); + return Result.Failed; + } + SearchCurveConnected(curves, curves.FirstOrDefault(), array, arrArray); + string rftPath = app.FamilyTemplatePath + "\\概念体量\\公制体量.rft"; - foreach (CurveArray arr in arrArray) + Document faDoc = app.NewFamilyDocument(rftPath); + + doc.InvokeGroup(tg => + { + faDoc.Invoke(ts => { - var ml = doc.FamilyCreate.NewModelCurveArray(arr, plane); - } - //foreach (CurveArray arr in arrArray) - //{ - // doc.FamilyCreate.NewExtrusion(true, arrArray, plane, 5.0 / 304.8); + SketchPlane plane = SketchPlane.Create(faDoc, Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero)); - // //var ml = doc.FamilyCreate.NewModelCurveArray(arr, plane); - //} + List cls = new List(); + foreach (CurveArray arr in arrArray) + { + ReferenceArray referenceArray = new ReferenceArray(); + foreach (Curve curve in arr) + { + var ml = faDoc.FamilyCreate.NewModelCurve(curve, plane); + referenceArray.Append(ml.GeometryCurve.Reference); + } + + try + { + faDoc.FamilyCreate.NewExtrusionForm(true, referenceArray, new XYZ(0, 0, 10 / 304.8)); + } + catch (Exception) + { + //TaskDialog.Show("温馨提示", "实体无法创建"); + //TaskDialog.Show("温馨提示", ex.Message + "\n\r" + ex.InnerException.ToString()); + continue; + } + + //var ml = doc.FamilyCreate.NewModelCurveArray(arr, plane); + //foreach (ModelCurve c in ml) + //{ + // referenceArray.Append(c.GeometryCurve.Reference); + //} + } + + //foreach (CurveArray arr in arrArray) + //{ + // var ml = doc.FamilyCreate.NewModelCurveArray(arr, plane); + // //doc.FamilyCreate.NewExtrusion(true, arrArray, plane, 5.0 / 304.8); + //} + }); + Family fa = faDoc.LoadFamily(doc); + + faDoc.Close(false); + + doc.Invoke(ts => + { + if (fa != null) + { + FamilySymbol familySymbol = doc.GetElement(fa.GetFamilySymbolIds().FirstOrDefault()) as FamilySymbol; + fa.Name = familyfilename; + familySymbol.Name = familyfilename; + if (familySymbol.IsActive == false) + { + familySymbol.Activate(); + } + doc.Create.NewFamilyInstance(importInstance.GetTransform().Origin, familySymbol, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + } + }); }); + return Result.Succeeded; } /// - /// 找到所有连接在一起的线圈并分好组 + /// 递归找到所有连接在一起的线圈并分好组 /// /// 所有线 /// 用于查找与其连接的初始线 @@ -116,17 +165,21 @@ namespace RookieStation { Curve tempCurve = curves[i]; var baseEndXyz = initcurve.GetEndPoint(0); + //把初始的第一个添加进集合 + if (curveArrArray.Size == 0) + { + curveArrArray.Append(initCurveArray); + } if (tempCurve.GetEndPoint(0).IsAlmostEqualTo(baseEndXyz) || tempCurve.GetEndPoint(1).IsAlmostEqualTo(baseEndXyz)) { initCurveArray.Append(tempCurve); curves.Remove(tempCurve); SearchCurveConnected(curves, tempCurve, initCurveArray, curveArrArray); - - return; } - else if (i == curves.Count() - 1) + //遍历完一个线串时 + if (i == curves.Count() - 1) { - curveArrArray.Append(initCurveArray); + //curveArrArray.Append(initCurveArray); //array.Clear(); initCurveArray = new CurveArray(); SearchCurveConnected(curves, curves.FirstOrDefault(), initCurveArray, curveArrArray); @@ -135,7 +188,6 @@ namespace RookieStation { curveArrArray.Append(initCurveArray); } - return; } } } diff --git a/RookieStation/CmdPlaceFloorFinishes.cs b/RookieStation/CmdPlaceFloorFinishes.cs index 4a02077..571552c 100644 --- a/RookieStation/CmdPlaceFloorFinishes.cs +++ b/RookieStation/CmdPlaceFloorFinishes.cs @@ -28,23 +28,31 @@ namespace RookieStation.Finishes return Result.Failed; } - WpfFloorFinishes floorCovering = CommonUtils.GenerateWindow(); + WpfFloorFinishes floorFinishes = CommonUtils.GenerateWindow(); double length, width, gap, thickness; - - if (floorCovering.DialogResult == true) + bool IsByRoom = false; + if (floorFinishes.DialogResult == true) { - length = floorCovering.PavementLength; - width = floorCovering.PavementWidth; - gap = floorCovering.PavementGap; - thickness = floorCovering.PavementThickness; + length = floorFinishes.PavementLength; + width = floorFinishes.PavementWidth; + gap = floorFinishes.PavementGap; + thickness = floorFinishes.PavementThickness; + IsByRoom = floorFinishes.IsByRoom; } else { return Result.Cancelled; } + if (IsByRoom) + { + CreateCurtainSystemByRoom(uidoc, length, width, gap, thickness); + } + else + { + CreateCurtainSystemByFace(uidoc, length, width, gap, thickness); + } - CreateCurtainSystemByFace(uidoc, doc, length, width, gap, thickness); //CreateCurtainSystemByRoom(uidoc, length, width, gap, thickness); return Result.Succeeded; //ModelCurveArray mca = new ModelCurveArray(); @@ -64,8 +72,9 @@ namespace RookieStation.Finishes //}); } - private static void CreateCurtainSystemByFace(UIDocument uidoc, Document doc, double length, double width, double gap, double thickness) + private static void CreateCurtainSystemByFace(UIDocument uidoc, double length, double width, double gap, double thickness) { + Document doc = uidoc.Document; Reference faceReference = uidoc.Selection.PickObject(ObjectType.Face, "请选择铺贴面"); Element element = doc.GetElement(faceReference); Face face = element.GetGeometryObjectFromReference(faceReference) as Face; @@ -233,16 +242,14 @@ namespace RookieStation.Finishes 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; - } + + 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); + //curtainSystemType.get_Parameter(BuiltInParameter.AUTO_MULLION_BORDER1_GRID1).Set(mullionType.Id); + //curtainSystemType.get_Parameter(BuiltInParameter.AUTO_MULLION_BORDER1_GRID2).Set(mullionType.Id); + //curtainSystemType.get_Parameter(BuiltInParameter.AUTO_MULLION_BORDER2_GRID1).Set(mullionType.Id); + //curtainSystemType.get_Parameter(BuiltInParameter.AUTO_MULLION_BORDER2_GRID2).Set(mullionType.Id); }, "设置参数"); return curtainSystemType; } diff --git a/RookieStation/Properties/Resources.Designer.cs b/RookieStation/Properties/Resources.Designer.cs index 76fe32d..b389ded 100644 --- a/RookieStation/Properties/Resources.Designer.cs +++ b/RookieStation/Properties/Resources.Designer.cs @@ -120,6 +120,16 @@ namespace RookieStation.Properties { } } + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap LogoExtrusion { + get { + object obj = ResourceManager.GetObject("LogoExtrusion", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// diff --git a/RookieStation/Properties/Resources.resx b/RookieStation/Properties/Resources.resx index fcff653..28b6b65 100644 --- a/RookieStation/Properties/Resources.resx +++ b/RookieStation/Properties/Resources.resx @@ -136,6 +136,9 @@ ..\resources\lamp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\resources\logoextrusion.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 diff --git a/RookieStation/Resources/LogoExtrusion.png b/RookieStation/Resources/LogoExtrusion.png new file mode 100644 index 0000000000000000000000000000000000000000..62f137da70b82ca0bd4c5a5cb71be3c5da08460e GIT binary patch literal 1080 zcmV-81jqY{P)KMWtZ3c1yEbt&_q$xh1%L0jmP6&+_&#-eJZsP$mJx5R#)$?h=C9d zz%ZJ<7{j+lqw%4~Ges#Bis$3;#C%&@JF~j_M+hP5!R6&}L@0zPfV#TIPK5B~o*qkh zZ0uY!KS?^BUTklFOA!v=y-!iu1F={vBm_bf08MK!Kd8&~wa;SdY@MF|-gorqU@LF$ zSC);u{MZ5N>NIvPC_*q&41h6=kbQ)JW!cF1V+Y^|Bx)1`SQvh=X@Ro z^Pd0=qwdM&&@e*q22ZKUmX;RE@Ato73@|r0mv;+=ehZ&JKNgvp31~MrH?@42d-o#U zeAP<=(6nX(06zG~5r1bkw@n>6@@|L8Waiuyp<$-KzyGPOuC7=4U89g8wgM$O}yLaz_p`j07E0-7{I73l6do&vTt5l(772rEF zOe5*{Spay2*gHDjyybA5Dm<$)6@Qt@$VS%I7L(-?7ZiMy1Gm4`mNBxHNF=P)YKvA? zRm!-_MeG>kb5bcL6|V`6D|8g+u>LSS%{EV!@Yiy8*?X6V(E-!G-wm0Q?O>)7LQ1TIaz40000 + diff --git a/RookieStation/RsApp.cs b/RookieStation/RsApp.cs index bddd15d..47abff4 100644 --- a/RookieStation/RsApp.cs +++ b/RookieStation/RsApp.cs @@ -73,6 +73,14 @@ namespace RookieStation }; var receptionBtn = (PushButton)receptionAreaPanel.AddItem(receptionLayoutPBD); receptionBtn.AvailabilityClassName = ViewPlanCmdEnabled; + + PushButtonData logoExtrusionPBD = new PushButtonData("标识挤出", "标识挤出", AddInPath, typeof(CmdLogoExtrusion).FullName) + { + LargeImage = ConvertFromBitmap(Properties.Resources.LogoExtrusion), + Image = ConvertFromBitmap(Properties.Resources.LogoExtrusion) + }; + receptionAreaPanel.AddItem(logoExtrusionPBD); + //出入口布置 RibbonPanel packAreaPanel = application.CreateRibbonPanel(TabName, EntranceAndExitGatePanelName); PushButtonData entrancegateLayoutPBD = new PushButtonData("入口布置", "入口闸机", AddInPath, typeof(CmdPlaceEntranceGate).FullName) diff --git a/RookieStation/WpfFloorFinishes.xaml b/RookieStation/WpfFloorFinishes.xaml index 8db96e3..ff518d7 100644 --- a/RookieStation/WpfFloorFinishes.xaml +++ b/RookieStation/WpfFloorFinishes.xaml @@ -79,11 +79,16 @@ TextAlignment="Center" />