public bool LoadSocketsFamilies(Document doc) { Assembly a = Assembly.GetExecutingAssembly(); string rootFolder = Path.GetDirectoryName(a.Location); foreach (string socketName in autoSocketsNames) { string DoorPath = rootFolder + "\\" + socketName + ".rfa"; if (!Helper.LoadFamily(doc, socketName, DoorPath, out Family socketFam)) { TaskDialog.Show("错误", "部分默认门族丢失,请重新安装插件"); return(false); } AutoSocketFamilies.Add(socketFam); } return(true); }
public bool DoCreateSockets() { this.LoadSocketsFamilies(ActiveDoc); Document doc = this.ActiveDoc; List <A_Socket> allSockets = CurrentHouse.Floors .SelectMany(f => f.Socket) .ToList(); List <A_Wall> allWalls = CurrentHouse.Floors .SelectMany(f => f.Walls) .ToList(); if (allSockets.Count() == 0) { return(false); } foreach (A_Socket soc in allSockets) { XYZ centerPt = new XYZ (soc.X, soc.Y, soc.Z + BaseLevel.Elevation); XYZ dirPt = new XYZ (0 - soc.Orientation.Y, soc.Orientation.X, 0); ///Get all the face of the host wall. Wall hostWall = allWalls .First(w => w.Uid == soc.Related.Uid).Wall; List <Reference> sideFaces = HostObjectUtils.GetSideFaces (hostWall, ShellLayerType.Exterior) .ToList(); sideFaces.AddRange( HostObjectUtils.GetSideFaces (hostWall, ShellLayerType.Interior) .ToList()); ///Find the face where the socket is located. Reference hostFace = sideFaces .OrderBy(f => centerPt.DistanceTo ((doc.GetElement(f) .GetGeometryObjectFromReference(f) as Face) .Project(centerPt).XYZPoint)) .First(); if (hostFace == null) { continue; } ///Choose the type. Family socFam; switch (soc.Tag) { case "五孔": socFam = AutoSocketFamilies .First(s => (s.Name.Contains("五孔")) && (!s.Name.Contains("防水"))); break; case "五孔防水": socFam = AutoSocketFamilies .First(s => s.Name.Contains("五孔防水")); break; case "网络电视": socFam = AutoSocketFamilies .First(s => s.Name.Contains("网络电视")); break; default: socFam = AutoSocketFamilies .First(s => s.Name.Contains(soc.Tag)); break; } FamilySymbol socSymbol = doc.GetElement (socFam.GetFamilySymbolIds().First()) as FamilySymbol; socSymbol.Activate(); soc.Instance = doc.Create .NewFamilyInstance (hostFace, centerPt, dirPt, socSymbol); ActiveForm.UpdateProgress(socketWorkLoad); } return(true); }