Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.

Revit API Forum

Reply
Post 1 of 11
Accepted Solution

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

190 Views, 10 Replies
02-14-2017 12:07 PM

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

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

Post 2 of 11

Re: How can I get the coordinates of the endpoints for a section marker line seg

02-15-2017 02:54 AM 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

Post 3 of 11

Re: How can I get the coordinates of the endpoints for a section marker line seg

03-03-2017 12:28 PM 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

Post 4 of 11

Re: How can I get the coordinates of the endpoints for a section marker line seg

03-06-2017 09:12 AM 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

Post 5 of 11

Re: How can I get the coordinates of the endpoints for a section marker line seg

03-07-2017 11:10 AM 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.

Highlighted
Post 6 of 11

Re: How can I get the coordinates of the endpoints for a section marker line seg

03-07-2017 04:42 PM 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);
        }
Post 7 of 11

Re: How can I get the coordinates of the endpoints for a section marker line seg

03-08-2017 07:16 AM 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

Post 8 of 11

Re: How can I get the coordinates of the endpoints for a section marker line seg

03-09-2017 07:48 AM 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?
Post 9 of 11

Re: How can I get the coordinates of the endpoints for a section marker line seg

03-09-2017 12:05 PM 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);

 

  

 

 

Post 10 of 11

Re: How can I get the coordinates of the endpoints for a section marker line seg

03-20-2017 03:09 AM 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

Post 11 of 11

Re: How can I get the coordinates of the endpoints for a section marker line seg

03-20-2017 03:44 AM in reply to: jeremytammik

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.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post

Revit Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Revit helps you achieve greater speed, accuracy, and automation from concept to manufacturing.