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: 

Filled Region Line Styles

16 REPLIES 16
Reply
Message 1 of 17
danny.bentley
3040 Views, 16 Replies

Filled Region Line Styles

Is it possible to access the lines within a filled region? I can see the lines in the Subcategory.  I have written code that accesses the FilledRegion, but I don't see a way to get the boundary line name.

 

public void EditFilledRegionInActiveViews(Document doc)
        {
            FilteredElementCollector fillRegions = new FilteredElementCollector(doc, doc.ActiveView.Id).OfClass(typeof(FilledRegion));

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Move all Filled Regions");
                List<FilledRegion> ListFilledRegion = new List<FilledRegion>();
                foreach (FilledRegion filledRegion in fillRegions)
                {
                    //TODO look up line styles in "Filled Region". 
                }

                tx.Commit();
            }
        }

FilledRegion.JPG

 

 

16 REPLIES 16
Message 2 of 17
Revitalizer
in reply to: danny.bentley

Hi,

 

there is an unsupported element relation between a sketch-based element and its sketch:

http://thebuildingcoder.typepad.com/blog/2011/09/filledregion-corrdinates.html

 

Once created a FilledRegion 3194965, there is a Sketch 3194964.

The ElementIds may not be consecutive, the interval may vary.

 

In the Sketch's profile property you can find the geometry curves of the line elements you are seaching for.

 

After that, search for all CurveElements whose coordinates fit the profile curves' ones.

As far as I know, those curve elements are of type ModelCurve. You may compare the CurveElementType, too.

 

If that would function, you would have the relating ModelCurves for setting the GraphicsStyle.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 3 of 17
danny.bentley
in reply to: Revitalizer

I gave this a try today, however, unfortunately the GraphicStyle doesn't have the XYZ coordinates that I need to match it. 

 

        private List<XYZ> _xyz = new List<XYZ>();
        private List<XYZ> AllCurveList = new List<XYZ>();
        private List<XYZ> SelectedCurveList = new List<XYZ>();
        private List<GraphicsStyle> ElementList = new List<GraphicsStyle>();

        public void EditFilledRegionInActiveViews(Document doc)
        {
            FilteredElementCollector fillRegions = new FilteredElementCollector(doc, doc.ActiveView.Id).OfClass(typeof(FilledRegion));

            //Collect line styles to compare and delete. 
            foreach (var filledRegion in fillRegions)
            {
                ElementId id = new ElementId(filledRegion.Id.IntegerValue -1);
                Sketch boundary = doc.GetElement(id) as Sketch;
                if (null != boundary)
                {
                    CurveArray curBoundary = boundary.Profile.get_Item(0);

                    if(null != curBoundary)
                    {
                        foreach (Curve curve in curBoundary)
                        {
                            XYZ corner = curve.GetEndPoint(0);
                            _xyz.Add(corner);
                            
                        }
                    }
                }
            }

        public void searchCurveElements(Document doc)
        {
            FilteredElementCollector curveElements = new FilteredElementCollector(doc).OfClass(typeof(CurveElement));
            
            try
            {
                foreach (Element e in curveElements)
            {
                CurveElement ln = e as CurveElement;

                XYZ xyz = ln.GeometryCurve.GetEndPoint(0);
                AllCurveList.Add(xyz);

                GraphicsStyle GraphStyl = ln.LineStyle as GraphicsStyle;

                ElementList.Add(GraphStyl); // Missing Link of coordinates
                count++;
                }
            }

            catch { }

//TODO this doesn't work without the GraphicsStyle coordinates. //try //{ //foreach (XYZ XYZcurvElemt in AllCurveList) //{ //foreach (XYZ xyz in _xyz) //{ //if (XYZcurvElemt == xyz) //{ SelectedCurveList.Add(XYZcurvElemt); //} //} //} } catch { } }

 

Message 4 of 17
Revitalizer
in reply to: danny.bentley

Hi,

 

in fact, there are some things to point out.

 

As mentioned above, the interval may be greater than 1,

so you need to adjust this part to get the next matching element if id-1 fails:

ElementId id = new ElementId(filledRegion.Id.IntegerValue -1);

 

Next, you should store the FilledRegion-ID/List<XYZ> relation in a dictionary instead of plain lists.

Better store a FilledRegion-ID/List<Curve> relation since you may have arcs and straight lines which share common end points.

 

The lists do not store the relation you need.

 

After doing so, get the CurveElements.

 

Iterate the FilledRegion-ID/List<Curve> relation to get the FilledRegion.Id for each CurveElement.

You need to compare the curve geometry, e.g. by comparing three points on each curve (c.Eval(0, 0.5 and 1))

Create a dictionary of FilledRegion-ID/List<CurveElement>.

 

After that, you may adjust the LineStyle property of each CurveElement belonging to a specific FilledRegion.

 

 

Revitalizer

 

 

 




Rudolf Honke
Software Developer
Mensch und Maschine





Message 5 of 17
Revitalizer
in reply to: danny.bentley

Hi,

 

there is a ExporterIFCUtils.IsCurveFromOtherElementSketch(CurveElement) method which may help you to filter the project's CurveElements.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 6 of 17
danny.bentley
in reply to: Revitalizer

I wanted to follow up with this.  I was able to get it to work.  I need to clean up the code and finish off my program.  I thought I would add my solution incase someone else is looking for this in the future.  

 

Thank you for your help. 

 

public Dictionary<ElementId, ElementId> DictionaryFilledRegions()
{
Dictionary<ElementId, ElementId> dictionary = new Dictionary<ElementId, ElementId>();

return dictionary;
}

public void ListBoundaryCorners(Document doc) { FilteredElementCollector fillRegions = new FilteredElementCollector(doc, doc.ActiveView.Id).OfClass(typeof(FilledRegion)); var dictionary = DictionaryFilledRegions(); foreach (var filledRegion in fillRegions) { ElementId id = new ElementId(filledRegion.Id.IntegerValue - 1); Sketch boundary = doc.GetElement(id) as Sketch; if (null != boundary) { CurveArray curBoundary = boundary.Profile.get_Item(0); if (null != curBoundary) { foreach (Curve curve in curBoundary) { dictionary.Add(curve.Reference.ElementId, id); } searchCurveElements(doc, dictionary); } } } } public void searchCurveElements(Document doc, Dictionary <ElementId, ElementId> dictionary) { FilteredElementCollector curveElements = new FilteredElementCollector(doc).OfClass(typeof(CurveElement)); //var dictionary = DictionaryFilledRegions(); try { foreach (Element e in curveElements) { CurveElement ln = e as CurveElement; detailLineNameList.Add(ln.LineStyle.Name); if (dictionary.ContainsKey(ln.Id)) { CurveElement curveElement = ln; curveElementList.Add(curveElement); } } } catch { } }

 

 

Message 7 of 17
Revitalizer
in reply to: danny.bentley

Hi,

 

may it be that you have cleaned up the code a little too much ?

 

In this state, it will not work.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 8 of 17
danny.bentley
in reply to: Revitalizer

Sorry. I've been working between drafting and putting together this code has left me with a little bit of time.  I will add a working version soon.  I just didn't want you to think I hadn't looked at it.  The suggestion was exactly what I needed to do and I think it works well.  Its part of a larger addin that I'm working on but I will add the solution incase anyone else runs into this problem as soon as I get a chance.  Thank you for your help. 

Message 9 of 17

Hi Danny,

 

Thank you in advance for the working solution, Looking forward to check it out and maybe blog about it.

 

Cheers,



Jaime Rosales D.
Sr. Developer Consultant
Twitter | AEC ADN DevBlog
Message 10 of 17

In our office we’ve been importing lots of AutoCAD files. We’ve also changed the standards last year causing a lot of confusion in line styles.  Or list quickly became overwhelming and hard to figure out what was the right line style to choose.   I had been working on an add-in to translate, delete and edit filled regions lines. I was able to come up with a working solution that reads an Excel file and compares the project line weights to the new standards and changes them. It’s still a work in progress. 

 

I had the issue of finding the line styles within a filled region with the help of the Revitalizer I was able to find filter and change the lines. 

 

One last issue I have is line with in a group.  I was able to swap out the group (using something Jeremey wrote), however, this has become a problem when you want to do it on an entire project.

 

I will place my solution on the Git Hub in case anyone is interested in seeing the code.

https://github.com/dannysbentley/Delete-Change-Line-Styles

 

Delete-Change-Line-Styles.JPG

 

If you have any feed back or ideas please let me know.  I’m still a CS student and learning the API so I’m always looking to improve. 

 

-Danny Bentley.

Message 11 of 17

Dear Danny,

 

Thank you very much for the sample GitHub repo.

 

Looks very cool. 

 

Congratulations, considering you say "I’m still a CS student and learning the API".

 

I would say you are seting a great example!

 

Thank you!

 

 

It also looks as if some cleanup could be made, e.g.

 

  • README.md coud be significantly simplified and cleaned up.
  • App.cs is never used and could be removed completely.

 

Would you like to flesh out the description a teeny weeny little bit, e.g.

 

  • Add an introduction explaining the problem, the task, the solution.
  • Provide an test example. e.g a simple Revit model and Excel file to run it with, exact steps to install and execute.
  • Description of situation before running, what is needed.
  • Description of situation after running, what has changed.

That would be enough for me to highlight it in a new post on The Building Coder blog, if you like.

 

Thank you!

 

Cheers,

 

Jeremy.



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

Message 12 of 17
Revitalizer
in reply to: danny.bentley

Hi Danny,

 

in your GitHub sample, the is a line which may fail in some cases:

 

ElementId id = new ElementId(filledRegion.Id.IntegerValue - 1);

 

As I've written above, the interval may be greater than 1.

 

So you could put it in a loop, decreasing the id until you've found a Sketch object.

 

 

Regards,

Revitalizer

 

 




Rudolf Honke
Software Developer
Mensch und Maschine





Message 13 of 17
danny.bentley
in reply to: Revitalizer

Revitalizer, 

I've added a for loop for the sketch.  In the condition I made the number test till it fell below 1000.  I'm unsure what could cause the the sketch id number to fall so far below the filled region id.  Maybe I haven't thought of the many possiblities of copying cuting pasting editing etc... I will have to test it with some of my large project to see if it continues to find all the filled regions or if some have been modified so often that the id is largely different.  

 

for (int i = filledRegionId - 1; filledRegionId - 1000 < i; i--)
                {
                    ElementId id = new ElementId(i);
                    Sketch boundary = doc.GetElement(id) as Sketch;
                    if (null != boundary)
                    {
                        CurveArray curBoundary = boundary.Profile.get_Item(0);

                        if (null != curBoundary)
                        {
                            foreach (Curve curve in curBoundary)
                            {
                                dictionary.Add(curve.Reference.ElementId, id);
                            }

                            searchCurveElements(doc, dictionary);
                        }
                    }
                }

 

Jeremey, 

 

Yes over the weekend I will do this.  I will clarify the Readme file.   I've removed the App.cs from my project. I will include a the Excel file and a Revit file example of how it works.  I can include a description as well the project before and after running the add in.  

Message 14 of 17
tjhogan2
in reply to: danny.bentley

Danny,  this is really awesome.  I have been trying to replicate this same process in python as a set of Dynamo nodes.  I have a had some pretty promising results that I can't wait to share, but I have one question.  In translating this to python I have had to make some changes and what not, and I ran across the filledregion method .SetLineStyleId() and it seems like this would do what you wanted it to do in the first place.  Is there a reason that this wasn't used?  Was it not meeting your needs, or maybe it wasn't stable?  I know on the Dynamo end, it's causing me some issues that I wasn't having with your method, but I wanted to ask and see what your thoughts were.

Message 15 of 17
danny.bentley
in reply to: tjhogan2

Hi tjhogan2, 

I had some real problems trying to set the lines in the filled regions.  The API wouldn't allow me to go into the edit sketch mode and look at the indvidual lines.  I took this route because I was unfamiliar how to get the lines within a filled region and how to check them against a list then set the new lines.  

 

I'm reworking the filled region method this month and will try the SetLineStyleId().  If I discover anything promising I will uploaded it to my git hub https://github.com/dannysbentley.

 

I'd really like to see the Dynamo package. If you could share it that would be great 🙂     

 

DB. 

Message 16 of 17
gbardales
in reply to: danny.bentley

Hi Danny/Everyone,

I tried to build the add-in for changing the line types in filled regions, But I could not build it. It gave me some error.

Does anyone has it build that would be willing to share it? I would appreciate it a lot.

 

Thank you,

Message 17 of 17
danny.bentley
in reply to: gbardales

What is the error? When is the error occurring?  Have you set a stop point to debug? 

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