Copy dimensions from a View to another

Copy dimensions from a View to another

t.galland
Contributor Contributor
7,773 Views
20 Replies
Message 1 of 21

Copy dimensions from a View to another

t.galland
Contributor
Contributor

Hello,

 

I'm trying to create a new plug-in on Revit 2016/2017 with the API. The idea is to copy a set of element from small revit file to a central one to compile them.

Here is the code I'm using :

UIDocument mainUiDoc;
Document mainDoc;
string mainPath;
UIDocument secUiDoc;
Document secDoc;

try
{
    mainUiDoc = app.ActiveUIDocument;
    mainDoc = mainUiDoc.Document;
    ViewPlan mainView = (ViewPlan)mainDoc.ActiveView;
    mainPath = mainDoc.PathName;


    XYZ extremitePoint;



    Selection sel = mainUiDoc.Selection;
    extremitePoint = sel.PickPoint("Selectionner le coin sup. gauche de la feuille");
    secUiDoc = app.OpenAndActivateDocument(((RevitFile)Main._roomData["revit"]).Path);
    secDoc = secUiDoc.Document;

    FilteredElementCollector collector = new FilteredElementCollector(secDoc);
    ViewPlan secView = collector.OfClass(typeof(ViewPlan)).Cast<ViewPlan>().First(
        x => x.ViewType == ViewType.FloorPlan &&
        x.IsTemplate == false &&
        x.Name.Contains(((RevitFile)Main._roomData["revit"]).Typology, StringComparison.OrdinalIgnoreCase));

    secUiDoc.ActiveView = secView;

    FilterableValueProvider provider = new ParameterValueProvider(new ElementId(BuiltInParameter.ALL_MODEL_TYPE_NAME));
    FilterRule rule = new FilterStringRule(provider, new FilterStringContains(), "BY_GO", false);
    ElementParameterFilter epf = new ElementParameterFilter(rule, true);
    ICollection<ElementId> npText = new FilteredElementCollector(secDoc, secView.Id).WherePasses(epf).ToElementIds();
    using (TransactionGroup tx = new TransactionGroup(mainDoc, "Insert"))
    {
        ICollection<ElementId> pastedElements;
        tx.Start();
        using (Transaction tr = new Transaction(mainDoc, "Copy elements"))
        {
            tr.Start();
            FailureHandlingOptions failOpt = tr.GetFailureHandlingOptions();
            failOpt.SetFailuresPreprocessor(new WarningSwallower());
            tr.SetFailureHandlingOptions(failOpt);


            pastedElements = ElementTransformUtils.CopyElements(secView, npText, mainView,null, new CopyPasteOptions());
            mainDoc.Regenerate();
            tr.Commit();
        }
        using (Transaction tr = new Transaction(mainDoc, "translate elements"))
        {
            tr.Start();
            pastedElements = new FilteredElementCollector(mainDoc, pastedElements).WherePasses(epf).ToElementIds();
            BoundingBoxXYZ floor = new FilteredElementCollector(mainDoc, pastedElements).OfClass(typeof(Floor)).First().get_BoundingBox(null);
            XYZ originePoint = floor.Min;
            XYZ translation = extremitePoint - originePoint;
            translation = new XYZ(translation.X, translation.Y, 0);
            ElementTransformUtils.MoveElements(mainDoc, pastedElements, translation);
            tr.Commit();
        }
        using (Transaction tr = new Transaction(mainDoc, "rotate elements"))
        {
            tr.Start();
            BoundingBoxXYZ floor = new FilteredElementCollector(mainDoc, pastedElements).OfClass(typeof(Floor)).First().get_BoundingBox(null);
            XYZ originePoint = floor.Min;
            Line rotation = Line.CreateBound(extremitePoint, new XYZ(extremitePoint.X, extremitePoint.Y, extremitePoint.Z+10));
            ElementTransformUtils.RotateElements(mainDoc, pastedElements, rotation, - (double)Main._roomData["rotation"] * Math.PI / 180);
            tr.Commit();
        }
        using (Transaction tr = new Transaction(mainDoc, "miror elements"))
        {
            tr.Start();
            pastedElements = new FilteredElementCollector(mainDoc, pastedElements).WherePasses(epf).ToElementIds();
            BoundingBoxXYZ floor = new FilteredElementCollector(mainDoc, pastedElements).OfClass(typeof(Floor)).First().get_BoundingBox(null);
            Plane mirror = null;
            switch ((string)Main._roomData["Symétries"])
            {
                case "nulle":
                    break;
                case "horizontale":
                    mirror = new Plane(new XYZ(1, 0, 0), new XYZ((floor.Max.X + floor.Min.X) / 2, (floor.Max.Y + floor.Min.Y) / 2, 0));
                    ElementTransformUtils.MirrorElements(mainDoc, pastedElements, mirror, false);
                    break;
                case "verticale":
                    mirror = new Plane(new XYZ(0, 1, 0), new XYZ((floor.Max.X + floor.Min.X) / 2, (floor.Max.Y + floor.Min.Y) / 2, 0));
                    ElementTransformUtils.MirrorElements(mainDoc, pastedElements, mirror, false);
                    break;
                default:
                    break;
            }
            tr.Commit();
        }
        tx.Assimilate();
    }

When I use it, everything is good except the dimensions. They are inside the new document (I can get them with there id and RevitLookup) but they are hidden. If I select on of them and add a witness line the dimension is now visible again. I tried to close and reopen Revit and place the vien on a sheet bt nothing.

Any idea ?

Thank you !

0 Likes
Accepted solutions (1)
7,774 Views
20 Replies
Replies (20)
Message 21 of 21

Joris.vd.Meulen
Collaborator
Collaborator

@Admin I copy pasted my post in order to keep forum clean

 

Guys,

 

I've created a dimension which isn't visible in my view. 

 

Read this topic: https://forums.autodesk.com/t5/revit-api-forum/newdimension-dimension-created-but-not-visible/m-p/63... where people too have this matter.

 

Any clues how come?

I do can select the dimension.

 

Is there any way I can debug it?

- I checked my get_Geometry(opt) ... true etc.

- References are parralel

- line

 

Like: is the dimension isn't visible, but placing another dimension, select of in entire project gives me 2 dimensions instead of 1, ... where is it placed?

 

Snooping that dim gives me:

- the dimension's ID I can't see

- it referers to surfaces of a mullion

- that mullion ID:

- I select in Revit and that gives me a mullion which isn't in my project???? So like a ghost mullion.

 

Screencast:

 

https://autode.sk/2qGnjCk

love python coding
0 Likes