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: 

How can I get the coordinates of the endpoints for a section marker line segment

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
skeletank
1818 Views, 10 Replies

How can I get the coordinates of the endpoints for a section marker line segment

I have a section marker for which I would like to do a rotation around one of the endpoints of the line segment leader but I haven't been able to figure out how to get the coordinates of the endpoint.  I'm able to get the bounding box of the overall section marker but not these specific coordinates.  How can I do this?

 

Section Marker Coordinates.png

10 REPLIES 10
Message 2 of 11
jeremytammik
in reply to: skeletank

Dear Skeletank,

 

I am checking with the development team for you... hang on...

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 11
skeletank
in reply to: jeremytammik

Hi Jeremy,

 

Have you heard anything back from the development team?  My bigger problem involves reversing the effects of the built-in "Mirror Project" tool and part of that includes reference section markers inside of another section that has been flipped.  I would like to fix their orientation by rotating 180 degrees around the endpoint.

 

Thanks

Message 4 of 11
jeremytammik
in reply to: skeletank

Yes.

 

They say:

 

1. The section marker element is not exposed as a specific element type so I don’t think this position can be read at this time. 

 

2. Regarding “Mirror Project”:  I don’t have good ideas to add.

 

Sorry for not being of more help!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 5 of 11
skeletank
in reply to: jeremytammik

I was assuming that would be the response but thank you very much Jeremy for checking with the development team for me.

Message 6 of 11
FAIR59
in reply to: skeletank

I've found a workaround for your question

 

A transaction needs to be active when you call the method, as the method hides the section tag and viewer_reference_label_text temporarily.

 

        private Line GetSectionLine(Element _section, Autodesk.Revit.DB.View _view)
        {
            const double _correction = 21.130014403 / 304.8;
            if (_section.Category == null) return null;
            if ((BuiltInCategory)_section.Category.Id.IntegerValue != BuiltInCategory.OST_Viewers) return null;

            List<Autodesk.Revit.DB.View> _views = new FilteredElementCollector(_section.Document)
                .OfClass(typeof(Autodesk.Revit.DB.View))
                .Cast<Autodesk.Revit.DB.View>()
                .ToList();
            Autodesk.Revit.DB.View _viewFromSection = null;
            foreach (var v in _views)
            {
                if (_section.Name == v.Name && _section.GetTypeId() == v.GetTypeId()) _viewFromSection = v;
            }
            if (_viewFromSection == null) return null;
            ViewFamilyType _vType = _section.Document.GetElement(_section.GetTypeId()) as ViewFamilyType;
            BoundingBoxXYZ _bb1 = null;
            using (SubTransaction st1 = new SubTransaction(_section.Document))
            {
                st1.Start();
                Parameter par = _vType.get_Parameter(BuiltInParameter.SECTION_TAG);
                par.Set(ElementId.InvalidElementId);
                par = _vType.get_Parameter(BuiltInParameter.VIEWER_REFERENCE_LABEL_TEXT);
                par.Set(string.Empty);
                _view.Scale = 1;
                _section.Document.Regenerate();
                _bb1 = _section.get_BoundingBox(_view);
                st1.RollBack();
            }
            BoundingBoxXYZ _ViewBB = _viewFromSection.get_BoundingBox(_viewFromSection);
            BoundingBoxXYZ _bb = _section.get_BoundingBox(_view);
            XYZ pt1 = _bb.Min;
            XYZ pt2 = _bb.Max;
            if (_bb1 != null)
            {
                pt1 = _bb1.Min;
                pt2 = _bb1.Max;
            }
            XYZ Origin = _viewFromSection.Origin;
            XYZ ViewBasisX = _viewFromSection.RightDirection;
            XYZ ViewBasisY = _viewFromSection.ViewDirection;
            if (ViewBasisX.X < 0 ^ ViewBasisX.Y < 0)
            {
                double _d = pt1.Y;
                pt1 = new XYZ(pt1.X, pt2.Y, pt1.Z);
                pt2 = new XYZ(pt2.X, _d, pt2.Z);
            }
            XYZ ToPlane1 = pt1.Add(ViewBasisY.Multiply(ViewBasisY.DotProduct(Origin.Subtract(pt1))));
            XYZ ToPlane2 = pt2.Subtract(ViewBasisY.Multiply(ViewBasisY.DotProduct(pt2.Subtract(Origin))));
            XYZ _correctionVector = ToPlane2.Subtract(ToPlane1).Normalize().Multiply(_correction);
            XYZ endPoint0 = ToPlane1.Add(_correctionVector);
            XYZ endPoint1 = ToPlane2.Subtract(_correctionVector);

            return Line.CreateBound(endPoint0, endPoint1);
        }
Message 7 of 11
jeremytammik
in reply to: FAIR59

Beautiful sample!

 

Especially after the development team said 'no hope'  🙂

 

Thank you, and congratulations!

 

Definitive blog post material, if I may...

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 8 of 11
skeletank
in reply to: FAIR59

FAIR59,

 

Thanks for the response.  I have a few questions:

 

  1. Where did you come up with the "const double _correction = 21.130014403 / 304.8;" value?
  2. How do you distinguish between section vs. callout markers since they are both of category OST_VIEWERS?
  3. Would this work for section markers that are only references (such as ones that reference drafting views)?
  4. How do you know which endpoint is associated with the tail and which one is associated with the head?
Message 9 of 11
FAIR59
in reply to: skeletank

@jeremytammik : feel free to use my contributions for your blog

 

@skeletank:

 

answer 1.

the boundingbox of a sectionline is the result of a number of elements

  1. the line
  2. the section head
  3. the reference label text
  4. the cycle symbol 

BoundingBox.PNG

 

in the method I "hide" 2 and 3. You can't hide the cycle symbol, so the result is to large. I simply added the resulting line without the correction to the project  and measured the surplus length. After checking that it is always the same, I implemented the constant  _correction = 21.130014403 / 304.8

 

answer 2.

I didn't distinguish between section vs. callout markers, I merely presumed you had a section marker. There are 2 ways to test

  1. if (_vType.FamilyName == "Section")

  2. if (_viewFromSection.GetType()== typeof(ViewSection))

callouts are PlanViews or Elevations, as far as I know.

 

answer 3.

I don't know

 

answer 4.

i'm afraid that is truly hidden. The Section Head and Tail stay in the same position when flipping the section, but the viewDirection and RightDirection changes.

The most you can get is a line in the View.RightDirection

 

            XYZ _direction = ToPlane2.Subtract(ToPlane1).Normalize();
            return _direction.IsAlmostEqualTo(ViewBasisX) ? Line.CreateBound(endPoint0, endPoint1) : Line.CreateBound(endPoint1, endPoint0);

 

  

 

 

Message 10 of 11
jeremytammik
in reply to: FAIR59

Cool solution, cool answers!

 

Preserved by The Building Coder for posterity here:

 

http://thebuildingcoder.typepad.com/blog/2017/03/ttt-to-obtain-section-marker-endpoint.html

 

Thank you!

 

 Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 11 of 11

Amazing work. I would have just used Section.Line.StartPoint.X. Please, it's a joke...

The question: Where did you come up with the "const double _correction = 21.130014403 / 304.8;" value?

Am I understanding correctly that this value (21.1300 etc.) will be dependant on the size and scale of the section marker circle? If so, a custom one would be a different value, correct? Thanks for posting this very helpful code. Regards, Dale




______________
Yes, I'm Satoshi.

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community