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: 

Draw different colored filled circles

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Anonymous
1844 Views, 4 Replies

Draw different colored filled circles

Hello everyone,

I have to draw different colored, filled circles via the Revit API. Does anyone know how to do this?

I managed to create unfilled circles, but I can only change the color of all Circles. So all of my circles alway have the same color.

 

Thank you in advance for your help.

4 REPLIES 4
Message 2 of 5
BenoitE&A
in reply to: Anonymous

Hey,

Have you tried to create a FilledRegion ?

Syntax is FilledRegion.Create() and you can use as an input a CurveLoop, so you can put a Circle in the CurveLoop.

https://www.revitapidocs.com/2020/290f529f-2bc0-fda3-d2ff-7b7e2ef7e29f.htm


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
Message 3 of 5
Anonymous
in reply to: BenoitE&A

Thanks for your suggestion.

I managed creating a circle with a pattern.

But I'm still unable to change the color. 

Also I have changed the filling pattern, but I cant change it to the Pattern "<Solid fill>".

 

Below I've added my code.

 

public void drawCircle(Document doc, XYZ center, double radius)
{
   FilteredElementCollector fillRegionTypes= new FilteredElementCollector(doc).OfClass(typeof(FilledRegionType));

   foreach (FilledRegionType frt in fillRegionTypes)
   {
       List<CurveLoop> profileloops = new List<CurveLoop>();

       double xMax = center.X + radius;
       double xMin = center.X - radius;
double step = Math.PI/8; List<XYZ> pointList = new List<XYZ>(); for (double phi = 0; phi <= (2*Math.PI); phi = phi + step) { double x1 = center.X + radius * Math.Cos(phi); double y1 = center.Y + radius*Math.Sin(phi); pointList.Add(new XYZ(x1, y1, 0)); } pointList.Add(new XYZ(center.X + radius * Math.Cos(0), center.Y + radius*Math.Sin(0), 0)); CurveLoop profileloop = new CurveLoop(); XYZ successor = null; foreach (XYZ point in pointList) { if (successor != null && point != null) { Line line = Line.CreateBound(successor, point); profileloop.Append(line); } successor = point; } profileloops.Add(profileloop); ElementId activeViewId = doc.ActiveView.Id; using (Transaction transaction = new Transaction(doc)) { if (transaction.Start("Create filled region") == TransactionStatus.Started) { FilledRegion filledRegion1 = FilledRegion.Create(doc, frt.Id, activeViewId, profileloops); transaction.Commit(); } } break; } }

 

Tags (1)
Message 4 of 5
BenoitE&A
in reply to: Anonymous

Hey,

I guess you will have to find the Type of your FilledRegion and modify it.

FilledRegion fr;

FilledRegionType type = myDoc.GetElement(fr.GetTypeId()) as FilledRegionType;
type.FillPatternId = myNewFilledRegionPattern.Id;
type.Color = myNewColor.Id;

Again to find the FilledRegionType you will have to filter the model using something looking like this

FilteredElementCollector col = new FilteredElementCollector(myDoc)
.OfClass(typeof(FilledRegionType));

Same for Pattern, Color, etc...


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
Message 5 of 5
Anonymous
in reply to: Anonymous

Many thanks for the help. I finally made it. Below, I added my code.

 

Revit Update has changed the methods a bit. But now everything is working.

 

 

using (Transaction transaction = new Transaction(doc))
   {
       if (transaction.Start("Create filled region") == TransactionStatus.Started)
       {
           filledRegion1 = 
           FilledRegion.Create(doc, frt.Id, activeViewId, profileloops);

           FilledRegionType type = doc.GetElement(filledRegion1.GetTypeId()) as FilledRegionType;
           Color green = new Color(0, 250, 0);
           type.ForegroundPatternColor = green;

           FillPatternElement myFillPattern = new FilteredElementCollector(doc).OfClass(typeof(FillPatternElement)).Cast<FillPatternElement> ().First(a => a.Name.Contains("Solid fill"));
           type.ForegroundPatternId = myFillPattern.Id;

           transaction.Commit();
         }
   }

 

 

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

Post to forums  

Rail Community


Autodesk Design & Make Report