开发小白 发表于 2017-3-2 12:09:45

如何引用链接文档中的Reference在主文档中创建尺寸标注?


思路:我想通过调用Revit的API。在主文档中的平面视图下选择一面链接文件中的墙,捕获到墙边界的面的Refernce。然后完成尺寸的标注。

问题:通过API获取到链接文档,然后获取到墙在链接文档中的Refernce后,无法引用这些Refernce在当前文档中实现标注。提示错误如下:




代码如下:
      
      
      public class 链接文件墙洞口标注 : IExternalCommand
      {
            public class WallSelectionFilter : ISelectionFilter
            {
                public RevitLinkInstance instance = null;
                public bool AllowElement(Element elem)
                {
                  instance = elem as RevitLinkInstance;
                  if (instance != null)
                  {
                        return true;
                  }


                  return false;
                }
                public bool AllowReference(Reference reference, XYZ position)
                {
                  if (instance == null)
                  {
                        return false;
                  }
                  else
                  {
                        Document linkdocument = instance.GetLinkDocument();
                        Element ent = linkdocument.GetElement(reference.LinkedElementId);
                        return ent is Wall;

                        return false;
                  }
                }
            }

            private void AddCurvesAndSolids(GeometryElement geomElem, CurveArray curves, List<Solid> solids)
            {
                foreach (GeometryObject geomObject in geomElem)
                {

                  Solid solid = geomObject as Solid;
                  if (null != solid)
                  {
                        solids.Add(solid);
                        continue;
                  }
                  //如果GeometryObject 是几何实例,则进行二次遍历
                  GeometryInstance geomInst = geomObject as GeometryInstance;
                  if (null != geomInst)
                  {
                        AddCurvesAndSolids(geomInst.GetSymbolGeometry(geomInst.Transform), curves, solids);
                  }
                }
            }

            public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
            {

                #region 建立revit连接
                UIDocument uiDoc = commandData.Application.ActiveUIDocument;
                Document doc = uiDoc.Document;
                Autodesk.Revit.ApplicationServices.Application app = doc.Application;
                #endregion

                Selection sel = uiDoc.Selection;
                sel.PickElementsByRectangle();
                Reference ref1 = uiDoc.Selection.PickObject(ObjectType.LinkedElement, new WallSelectionFilter(), "Please pick a point on Wall face.");
                RevitLinkInstance linkInstance = doc.GetElement(ref1) as RevitLinkInstance;
                Document lincdoc = linkInstance.GetLinkDocument();
                Element ent = lincdoc.GetElement(ref1.LinkedElementId);
                Wall wallent = null;
                wallent = ent as Wall;
                Transaction trans = new Transaction(doc);
                trans.Start("sta");
                LocationCurve lc = wallent.Location as LocationCurve;
                Curve curve = lc.Curve;
                Line line1 = curve as Line;
                XYZ PTXL = line1.GetEndPoint(0) - line1.GetEndPoint(1);//获取墙的方向向量
                #region 获取lines
                ReferenceArray referenceArray = new ReferenceArray();
                Options opt = doc.Application.Create.NewGeometryOptions();
                opt.ComputeReferences = true;
                opt.View = doc.ActiveView;
                GeometryElement geo = wallent.get_Geometry(opt);
                CurveArray curvearrau = new CurveArray();
                List<Solid> Solids = new List<Solid>();
                AddCurvesAndSolids(geo, curvearrau, Solids);
                jisuanlei JISUAN = new jisuanlei();
                for (int i = 0; i < Solids.Count; i++)
                {
                  Solid solid = Solids;
                  FaceArray faces = solid.Faces;
                  foreach (Face fa in faces)
                  {
                        PlanarFace pf = fa as PlanarFace;
                        if (Math.Abs(pf.Normal.AngleTo(PTXL)) < 0.1)
                        {
                            referenceArray.Append(fa.Reference);
                        }
                        if (Math.Abs(pf.Normal.AngleTo(PTXL) - Math.PI) < 0.1)
                        {
                            referenceArray.Append(fa.Reference);
                        }
                  }
                }


                XYZ pt1 = (line1.GetEndPoint(0).X < line1.GetEndPoint(1).X ? line1.GetEndPoint(0) : line1.GetEndPoint(1));
                XYZ pt2 = (line1.GetEndPoint(0).X > line1.GetEndPoint(1).X ? line1.GetEndPoint(0) : line1.GetEndPoint(1));
                Line newLine2JD = Line.CreateBound(pt1, pt2);
                Dimension newDimensionJD = doc.Create.NewDimension(doc.ActiveView, newLine2JD, referenceArray);
                #endregion
                trans.Commit();
                return Result.Succeeded;

            }

      }求大神告诉我,我该怎样去引用墙的Refernce。才能完成这个标注呢?

书痴 发表于 2017-3-9 08:45:42

你好,请问这个问题现在解决了吗?

开发小白 发表于 2017-3-29 17:10:55

本帖最后由 开发小白 于 2017-4-5 14:56 编辑

哪位大神能解答,麻烦帮忙解决下呢,亟待解决!!!

开发小白 发表于 2017-3-29 20:02:44

书痴 发表于 2017-3-9 08:45
你好,请问这个问题现在解决了吗?

您好,这个问题我还没解决到,亟待解决。请问您能帮忙解答一下吗?

书痴 发表于 2017-3-30 10:16:23

开发小白 发表于 2017-3-29 20:02
您好,这个问题我还没解决到,亟待解决。请问您能帮忙解答一下吗?

嗯,这两天比较忙,找时间帮您看一下

开发小白 发表于 2017-4-5 14:55:51

书痴 发表于 2017-3-30 10:16
嗯,这两天比较忙,找时间帮您看一下

您好,请问最近有空帮我解决一下这个问题吗?

书痴 发表于 2017-4-6 08:54:27

开发小白 发表于 2017-4-5 14:55
您好,请问最近有空帮我解决一下这个问题吗?

这个周末我看一下,这个可能有点复杂

开发小白 发表于 2017-4-6 10:58:37

书痴 发表于 2017-4-6 08:54
这个周末我看一下,这个可能有点复杂

好的,谢谢您

书痴 发表于 2017-4-12 09:03:56

开发小白 发表于 2017-4-6 10:58
好的,谢谢您

看了下,好像没有办法。
页: [1]
查看完整版本: 如何引用链接文档中的Reference在主文档中创建尺寸标注?