Fill Pattern Style

Fill Pattern Style

Anonymous
Not applicable
2,811 Views
4 Replies
Message 1 of 5

Fill Pattern Style

Anonymous
Not applicable

I can change the color but I can not change the solid fill style, as I show in the images. Help with this, thank you very much. 

this is my code

 

trans.Start();
ogs.SetProjectionFillPatternId(wall.Id);
ogs.SetProjectionFillPatternVisible(true);
ogs.SetProjectionFillColor(new Color(255, 0, 255));
uiDoc.ActiveView.SetElementOverrides(wall.Id, ogs);
trans.Commit();

 

Capturasss.PNGCapturassss2.PNG

0 Likes
Accepted solutions (1)
2,812 Views
4 Replies
Replies (4)
Message 2 of 5

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Anonymous ,

In the code

ogs.SetProjectionFillPatternId(wall.Id);

To set the projectFillpatternId you need to pass the ID of the fillpatternelement not the Id of the wall.

Filter for the fillpattern you want and pass the id for overriding the graphics settings.

 

I hope that the below code helps you to achieve this.

FilteredElementCollector Collector = new FilteredElementCollector(doc).OfClass(typeof(FillPatternElement));
                IList<Element> FPES = Collector.ToElements() as IList<Element>;               
                FillPatternElement fpe = null;
                foreach(Element e in FPES)
                {
                    if(e.Name.Contains("Your Fill pattern element name"))
                    {
                        fpe = e as FillPatternElement;
                    }
                }
                OverrideGraphicSettings ORGS = new OverrideGraphicSettings();
                ORGS.SetProjectionFillPatternId(fpe.Id);
                doc.ActiveView.SetElementOverrides(wall.Id, ORGS);

If this helped solve your problem please mark it as solution, so other users can get this solutions as well Smiley Happy

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 5

Anonymous
Not applicable

Thank you for your answer, I was trying to find the solution but I still have not resolved, the sales code error and I can not find the FillPatternElement.  I would appreciate if someone could help me with this 

 

Regards,

0 Likes
Message 4 of 5

so-chong
Advocate
Advocate
Accepted solution

Hi,

 

As Naveen pointed out you have to pass the Id of the fillpatternelement(fpe).


To set the solid fill style (surface pattern style) you can use the GetFillPattern() method to get the FillPattern associated to this element.


For example, below the inserted code (macro) i choose to set the pattern style to "Crosshatch".


Change whatever pattern style you want to use; only those who are currently available in the project document.

 

Did you try this something like this?
I hope this is useful for you.

 

    public void FillPatternWalls()
    {
        UIDocument uidoc = this.ActiveUIDocument;
        Document doc = this.ActiveUIDocument.Document;
            
        var patternCollector = new FilteredElementCollector(doc);
        patternCollector.OfClass(typeof(FillPatternElement));
        
        // replace "Crosshatch" with another fill pattern style you want
        FillPatternElement fpe = patternCollector.ToElements().Cast<FillPatternElement>().First(x => x.GetFillPattern().Name == "Crosshatch");    
        
        OverrideGraphicSettings ogs = new OverrideGraphicSettings();
        ogs.SetProjectionFillPatternId(fpe.Id);
        ogs.SetProjectionFillPatternVisible(true);
        ogs.SetProjectionFillColor(new Color(2550255));    
            
        using (Transaction t = new Transaction(doc, "Set Fill Pattern Walls"))
        {
            t.Start();
                            
                foreach (Element wall in new FilteredElementCollector(doc,doc.ActiveView.Id).OfClass(typeof(Wall)))
                {            
                    doc.ActiveView.SetElementOverrides(wall.Id, ogs);                        
                }
        
            t.Commit();
        }                    
        uidoc.RefreshActiveView();
    } 
Message 5 of 5

Anonymous
Not applicable

Thank you very much for your answer @so-chong

 

Greetings,

0 Likes