Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Copying ViewSection between documents ViewSection Line and extent are inverted.

4 REPLIES 4
Reply
Message 1 of 5
philbugmen
241 Views, 4 Replies

Copying ViewSection between documents ViewSection Line and extent are inverted.

I am trying to take a ViewSection instance from a source Document

 and recreate it in a Target Document, I can achieve this by getting the bounding box of the source ViewSection instance and creating a new targetBox BoundingBox instance with the min max points set to match. However the resulting view has the section line where the sectionBox extent is and the view is facing back in the other direction. I tried a rotation transform however i get an argument exception. If you know why this is occuring I would appreciate advice.

 

                    BoundingBoxXYZ sourceBox = viewSectionSource.get_BoundingBox(viewSectionSource);
                    BoundingBoxXYZ targetBox = CreateBoundingBoxByTransformOfPoint(sourceBox);
        private static BoundingBoxXYZ CreateBoundingBoxByTransformOfPoint(BoundingBoxXYZ sourceBox)
        {
            BoundingBoxXYZ targetBox = new BoundingBoxXYZ();

            // Apply the transformation to the Min and Max points of the BoundingBoxXYZ
            Transform transform = Transform.Identity;
            targetBox.Min = transform.OfPoint(sourceBox.Min);
            targetBox.Max = transform.OfPoint(sourceBox.Max);

            // Set the Transform of the target BoundingBoxXYZ to the source BoundingBoxXYZ's Transform
            targetBox.Transform = sourceBox.Transform;

            return targetBox;
        }
                    newView = ViewSection.CreateSection(targetDoc, viewFamilyTypeId, targetBox);

 

 

Tags (1)
4 REPLIES 4
Message 2 of 5
jeremy_tammik
in reply to: philbugmen

The definition of you method CreateBoundingBoxByTransformOfPoint seems a bit weird to me, because it does next to nothing. It sets the transform to identity, then transforms the two point (by identity, i.e., not). Can you explain the purpose of that, or am I misunderstanding something? After all, I am not a computer, or a .NET compiler, so I may be getting it completely wrong...

   

Jeremy Tammik, Developer Advocacy and Support, The Building Coder, Autodesk Developer Network, ADN Open
Message 3 of 5
philbugmen
in reply to: philbugmen

Thanx Jeremy, I will investigate if this is redundant and report.

Message 4 of 5
philbugmen
in reply to: philbugmen

So I tested and it was not required. I could just set the max and min to the source to create the target. the section view still remains flipped to the opposite side and facing the opposite direction. Other than generating the view from a an .RTE document file into a new project that are identical, the view section must not be respecting the original bounding box. 

Message 5 of 5
philbugmen
in reply to: philbugmen

        private static BoundingBoxXYZ CreateViewSectionByTransform(BoundingBoxXYZ sourceBox, ViewSection viewSource)
        {
            Parameter farClipParamSource = viewSource.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR);
            if (farClipParamSource == null) return null;
            double offset = farClipParamSource.AsDouble();

            double w = sourceBox.Max.X - sourceBox.Min.X;
            double d = sourceBox.Max.Y - sourceBox.Min.Y;
            double h = sourceBox.Max.Z - sourceBox.Min.Z;

            XYZ minPoint = new XYZ(-w, sourceBox.Min.Z - offset, -offset);
            XYZ maxPoint = new XYZ(0, 0, w);
         
            BoundingBoxXYZ targetBox = new BoundingBoxXYZ
            {
                Enabled = true,
                Min = minPoint,
                Max = maxPoint,
            };

            Transform transform = Transform.Identity;
            transform.Origin = sourceBox.Max;
            transform.BasisX = XYZ.BasisY;
            transform.BasisY = XYZ.BasisZ;
            transform.BasisZ = XYZ.BasisX;

            targetBox.Transform = transform;
            return targetBox;
        }

 

using the above code, I have some success recreating a view secton instance in a new document matching the source document view section, however the origin of the viewsections are very close together i think by a factor 0f 50-200x perhaps and if i use a transform such as this after the view is generated, i can get the view sections closer by using this code to move the sectionboxes, however the back section line is not at the start of the view section box and is somewhere closer to the middle, so the section becomes corrupt. here is the code that moves the new views in the new document but leaves them looking like an elevation, see below. My question is do i need to apply some sort of scaling or another coordinate transform to get the new section view to the same origin in model space?

        private static BoundingBoxXYZ GetNewCropboxByOffsetOfMinAndMaxTheDifferenceFromSourceBoxToNewBox(ViewSection viewSource, ViewSection newView)
        {
            XYZ offset = viewSource.CropBox.Transform.Origin - newView.CropBox.Transform.Origin;

            BoundingBoxXYZ newBox = new BoundingBoxXYZ
            {
                Min = viewSource.CropBox.Min + offset,
                Max = viewSource.CropBox.Max + offset,
                Transform = viewSource.CropBox.Transform
            };

            return newBox;
        }

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community