Change generic annotation category color

Change generic annotation category color

MiguelGT17
Advocate Advocate
321 Views
3 Replies
Message 1 of 4

Change generic annotation category color

MiguelGT17
Advocate
Advocate

Hello everybody,

 

hope this message find you well. The main concern of this topic is the fact that API is not letting me change the annotation generic graphic style color:

 

curve1 = fdoc.FamilyCreate.NewDetailCurve(drawView, l1);
GraphicsStyle gs = curve1.LineStyle as GraphicsStyle;
gs.GraphicsStyleCategory.LineColor = new Color(255,0,0);

 

I also wanna bring this post up: https://adndevblog.typepad.com/aec/2015/06/revitiapi-how-to-create-a-colored-detail-line-in-family.h...

which propose a workaround for this matter which is to generate a new category and set new color from there. The problem is that afterwards I will need to loop through every single Curve generated in my family document and set the linestyle property value and considering the extension of the code, it'll increase the computation.

 

Any insights on why the approach showed above do not change lineStyle color at all?

 

All the Best,

Miguel Gutierrez

0 Likes
322 Views
3 Replies
Replies (3)
Message 2 of 4

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @MiguelGT17 ,

 

First, the code you mentioned works fine and I was able to change the Line-color of the detail line.

If there are some other detail lines in the document, the color of those detail lines changes too.

 

XYZ p1 = new XYZ(0, 0, 0);
XYZ p2 = new XYZ(50, 50, 0);
Line l1 = Line.CreateBound(p1, p2);
               
Transaction actrans = new Transaction(doc);
actrans.Start("Change Line Color");
DetailCurve dCurve = doc.FamilyCreate.NewDetailCurve(doc.ActiveView, l1);
GraphicsStyle gs =dCurve.LineStyle as GraphicsStyle;
gs.GraphicsStyleCategory.LineColor = new Autodesk.Revit.DB.Color(255, 0, 0);
actrans.Commit();

 

Please take a look at the attached screenshots.

Could you please tell me the details of the Revit version you are using?


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 3 of 4

MiguelGT17
Advocate
Advocate

Hi naveen, thanks for replying me and sorry for the late response

 

Thanks for confirming that the code structure is ok. The revit version I used to run it up was revit 2022

 

all the best,

Miguel G.

0 Likes
Message 4 of 4

RPTHOMAS108
Mentor
Mentor

You need a subcategory for every different line colour/thickness and pattern variation just as is the case in the UI. It's an example of the API not being able to do something the UI can't.

 

There is no real benefit of changing the colour that way over creating/finding a subcategory and assigning it. What you should really be doing is working out the permutations required then creating them if they don't exist and then assigning them. Otherwise you are just changing the same object multiple times (as noted above) or trying to create something that was previously created (causing exceptions).

0 Likes