4 Replies Latest reply on Jun 5, 2017 6:59 AM by Korbi Anis

    Help to translate a macro to VBA

    Korbi Anis

      Hi friends , I have a macro wich is used to divide surface in iso curve and after get and display all intersection points of each lines ! I have some problem to translate this macro to vba . somone can help me plz.thanks in advance

       

      This is the macro :

      using System;

      using System.Collections.Generic;

      using System.Text;

       

      using Autodesk.Revit.Attributes;

      using Autodesk.Revit.DB;

      using Autodesk.Revit.UI;

       

      namespace Revit.SDK.Samples.HelloRevit.CS

      {

       

        [Transaction(TransactionMode.Manual)]

        public class Command : IExternalCommand

        {      

          public Result Execute(ExternalCommandData commandData,

            ref string message,

            ElementSet elements)

          {

            UIDocument uiDoc = commandData.Application.ActiveUIDocument;

       

            using (Transaction trans = new Transaction(uiDoc.Document, "Point"))

            {

              trans.Start();

              // Ensure you select a DividedSurface Element from the model

              foreach (Element ele in uiDoc.Selection.Elements)

              {

                DividedSurface surface = ele as DividedSurface;

                if (null != surface)

                {

                  Options opts =

                    uiDoc.Document.Application.Create.NewGeometryOptions();

                  GeometryElement geoEle = surface.get_Geometry(opts);

                  IEnumerator<GeometryObject> geoElems =

                    geoEle.GetEnumerator();

       

                  while (geoElems.MoveNext())

                  {

                    GeometryObject geoObj =

                      geoElems.Current as GeometryObject;

       

                    Line line = geoObj as Line;

                    if (null != line)

                    {

                      IEnumerator<GeometryObject> geoNestedElems =

                        geoEle.GetEnumerator();

                      while (geoNestedElems.MoveNext())

                      {

                        GeometryObject geoObjNested =

                          geoNestedElems.Current as GeometryObject;

       

                        Line nestedLine = geoObjNested as Line;

                        if (null != nestedLine)

                        {

                          // Ensure that this line is not the same as

                          // main line

                          if (!nestedLine.Equals(line))

                          {

                            // Create container for the

                            // intersection results array

                            IntersectionResultArray resArray =

                              new IntersectionResultArray();

                            // Get the intersection result

                            // array using Intersect()

                            line.Intersect(nestedLine, out resArray);

                            if (null != resArray)

                            {

                              foreach (IntersectionResult res in resArray)

                              {

                                // Create a new reference point

                                // for each intersection point

                                ReferencePoint rp =

                                  uiDoc.Document.FamilyCreate.

                                  NewReferencePoint(res.XYZPoint);

                              }

                            }

                          }

                        }                  

                      }

                    }         

                  }

                }

              }

              trans.Commit();

            }   

            return Result.Succeeded;

          }

        }       

      }