Revit+对象空间的关系

来源:互联网 发布:gvim python 编辑:程序博客网 时间:2024/06/03 13:35
    UIApplication app = commandData.Application;    Document doc = app.ActiveUIDocument.Document;    Transaction trans = new Transaction(doc, "ExComm");    trans.Start();    Selection sel = app.ActiveUIDocument.Selection;    Reference ref1 = sel.PickObject(ObjectType.Element, "Please pick a beam");    FamilyInstance beam = doc.GetElement(ref1) as FamilyInstance;    //Read the beam's location line    LocationCurve lc = beam.Location as LocationCurve;    Curve curve = lc.Curve;    XYZ ptStart = curve.get_EndPoint(0);    XYZ ptEnd = curve.get_EndPoint(1);    //move the two point a little bit lower, so the ray can go through the wall    XYZ offset = new XYZ(0, 0, 0.01);    ptStart = ptStart - offset;    ptEnd = ptEnd - offset;    View3D view3d = null;    view3d = doc.ActiveView as View3D;    if (view3d == null)    {      TaskDialog.Show("3D view", "current view should be 3D view");      return Result.Failed;    }    double beamLen = curve.Length;    IList<ReferenceWithContext> references = doc.FindReferencesWithContextByDirection(ptStart, (ptEnd - ptStart), view3d);    //ElementSet wallSet = app.Application.Create.NewElementSet();    sel.Elements.Clear();    double tolerate = 0.00001;    foreach (ReferenceWithContext reference in references)    {        Reference ref2 = reference.GetReference();        ElementId id = ref2.ElementId;        Element elem = doc.get_Element(id);        if (elem is Wall)        {            if (reference.Proximity < (beamLen + tolerate))            {                sel.Elements.Add(elem);            }        }    }    trans.Commit();    return Result.Succeeded;




0 0