//改变选中实例的颜色(被选中的族实例要已经赋予了材质,这个方法才起作用) private Color changeProfileColor(FamilyInstance familyInstance, ExternalCommandData commandData) { UIDocument uiDoc = commandData.Application.ActiveUIDocument; //取得当前活动文档 //初试颜色 Material materialOrigin = uiDoc.Document.GetElement(familyInstance.GetMaterialIds(false).First()) as Material; Color colorOrigin = materialOrigin.Color; //改变选中实例的线的颜色 OverrideGraphicSettings overrideGraphicSettings = new OverrideGraphicSettings(); overrideGraphicSettings = uiDoc.Document.ActiveView.GetElementOverrides(familyInstance.Id); Color color = new Color(255, 0, 0); overrideGraphicSettings.SetProjectionLineColor(color); //在当前视图下设置,其它视图保持原来的 uiDoc.Document.ActiveView.SetElementOverrides(familyInstance.Id, overrideGraphicSettings); uiDoc.Document.Regenerate(); return(colorOrigin); }
private void Stream( ArrayList data, FamilyInstance famInst ) { data.Add( new Snoop.Data.ClassSeparator( typeof( FamilyInstance ) ) ); data.Add( new Snoop.Data.Object( "Host", famInst.Host ) ); data.Add( new Snoop.Data.Object( "Symbol", famInst.Symbol ) ); data.Add( new Snoop.Data.OriginalInstanceGeometry( "Original Geometry", famInst, m_app.Application ) ); try { data.Add( new Snoop.Data.Enumerable( "Sub components", famInst.GetSubComponentIds(), famInst.Document ) ); } catch( Exception ex ) { data.Add( new Snoop.Data.Exception( "Sub components", ex ) ); } try { data.Add( new Snoop.Data.Object( "Super component", famInst.SuperComponent ) ); } catch( Exception ex ) { data.Add( new Snoop.Data.Exception( "Super component", ex ) ); } try { data.Add( new Snoop.Data.Object( "Room", famInst.Room ) ); } catch( Exception ex ) { data.Add( new Snoop.Data.Exception( "Room", ex ) ); } try { data.Add( new Snoop.Data.Object( "From room", famInst.FromRoom ) ); } catch( Exception ex ) { data.Add( new Snoop.Data.Exception( "From room", ex ) ); } try { data.Add( new Snoop.Data.Object( "To room", famInst.ToRoom ) ); } catch( Exception ex ) { data.Add( new Snoop.Data.Exception( "To room", ex ) ); } data.Add( new Snoop.Data.Enumerable( "Material", famInst.GetMaterialIds( false ), famInst.Document ) ); try { data.Add( new Snoop.Data.Object( "Space", famInst.Space ) ); } catch( Exception ex ) { data.Add( new Snoop.Data.Exception( "Space", ex ) ); } FilteredElementCollector filter = new FilteredElementCollector( famInst.Document ); IList<Element> phases = filter.OfClass( typeof( Phase ) ).ToElements(); foreach( Element e in phases ) { try { data.Add( new Snoop.Data.Object( "get_Space(" + e.Name + ")", famInst.get_Space( e as Phase ) ) ); } catch( Exception ex ) { data.Add( new Snoop.Data.Exception( "get_Space(" + e.Name + ")", ex ) ); } } data.Add( new Snoop.Data.String( "Structural type", famInst.StructuralType.ToString() ) ); // TBD: throws an exception if not the right type! try { data.Add( new Snoop.Data.String( "Structural usage", famInst.StructuralUsage.ToString() ) ); } catch( Exception ex ) { data.Add( new Snoop.Data.Exception( "Structural usage", ex ) ); } data.Add( new Snoop.Data.String( "StructuralMaterialType", famInst.StructuralMaterialType.ToString() ) ); data.Add( new Snoop.Data.ElementId( "StructuralMaterialId", famInst.StructuralMaterialId, famInst.Document ) ); data.Add( new Snoop.Data.Object( "MEP model", famInst.MEPModel ) ); data.Add( new Snoop.Data.Bool( "Can flip facing", famInst.CanFlipFacing ) ); data.Add( new Snoop.Data.Bool( "Facing flipped", famInst.FacingFlipped ) ); data.Add( new Snoop.Data.Bool( "Can flip hand", famInst.CanFlipHand ) ); data.Add( new Snoop.Data.Bool( "Hand flipped", famInst.HandFlipped ) ); data.Add( new Snoop.Data.Bool( "Can rotate", famInst.CanRotate ) ); data.Add( new Snoop.Data.Xyz( "Facing orientation", famInst.FacingOrientation ) ); data.Add( new Snoop.Data.Xyz( "Hand orientation", famInst.HandOrientation ) ); data.Add( new Snoop.Data.Object( "Location", famInst.Location ) ); data.Add( new Snoop.Data.Bool( "Mirrored", famInst.Mirrored ) ); data.Add( new Snoop.Data.Enumerable( "Copings", famInst.GetCopingIds(), famInst.Document ) ); AnnotationSymbol annoSym = famInst as AnnotationSymbol; if( annoSym != null ) { Stream( data, annoSym ); return; } Panel panel = famInst as Panel; if( panel != null ) { Stream( data, panel ); return; } Mullion mullion = famInst as Mullion; if( mullion != null ) { Stream( data, mullion ); return; } }
private List <Curve> GetWindowsDoorCurves(Wall wall, Curve segmentCurve /*alwaysInHost*/, Transform transform) { List <Curve> windowCurves = new List <Curve>(); try { LocationCurve curve = wall.Location as LocationCurve; Curve wallCurve = curve.Curve; XYZ startSegment = segmentCurve.GetEndPoint(0); XYZ endSegment = segmentCurve.GetEndPoint(1); startSegment = transform.Inverse.OfPoint(startSegment); endSegment = transform.Inverse.OfPoint(endSegment); IntersectionResult result = wallCurve.Project(startSegment); double param1 = result.Parameter; result = wallCurve.Project(endSegment); double param2 = result.Parameter; double segStartParam = param1 < param2 ? param1 : param2; double segEndParam = param1 > param2 ? param1 : param2; IList <ElementId> insertedElementIds = (wall as HostObject).FindInserts(true, true, true, true); List <FamilyInstance> instances = new List <FamilyInstance>(); foreach (ElementId elementId in insertedElementIds) { FamilyInstance instance = wall.Document.GetElement(elementId) as FamilyInstance; if (null != instance) { if (instance.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Windows || instance.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Doors) { bool isInsideSegment = false; if (instance.HostParameter > segStartParam && instance.HostParameter < segEndParam) { isInsideSegment = true; } if (isInsideSegment) { if (instance.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Windows) { instances.Add(instance); } else { ICollection <ElementId> materialIds = instance.GetMaterialIds(false); foreach (ElementId matId in materialIds) { Material mat = instance.Document.GetElement(matId) as Material; if (null != mat) { if (mat.Transparency > minTransparency) { instances.Add(instance); break; } } } } } } } } foreach (FamilyInstance instace in instances) { BoundingBoxXYZ bb = instace.get_BoundingBox(null); XYZ minPoint = transform.OfPoint(bb.Min); double startParam = 0; XYZ startPoint = null; result = segmentCurve.Project(minPoint); if (null != result) { startParam = result.Parameter; startPoint = result.XYZPoint; } XYZ maxPoint = transform.OfPoint(bb.Max); double endParam = 0; XYZ endPoint = null; result = segmentCurve.Project(maxPoint); if (null != result) { endParam = result.Parameter; endPoint = result.XYZPoint; } if (startParam != 0 && endParam != 0) { if (startPoint.DistanceTo(endPoint) > tolerance) { Curve windowCurve = Line.CreateBound(startPoint, endPoint); windowCurves.Add(windowCurve); } } } } catch (Exception ex) { string message = ex.Message; } return(windowCurves); }