Is there any method to change the linepattern of one element with Revit 2018 API

Is there any method to change the linepattern of one element with Revit 2018 API

1120415118
Enthusiast Enthusiast
2,408 Views
13 Replies
Message 1 of 14

Is there any method to change the linepattern of one element with Revit 2018 API

1120415118
Enthusiast
Enthusiast

Hi,

I have a demand that is to change the line pattern of one element in the view for distinguishing with other elements. I know how to change the line pattern of one category in UI, but with API, I have no idea. I am also not sure whether the line pattern of one element can be changed alone using API. Is there anyone can help? Thanks.

0 Likes
2,409 Views
13 Replies
Replies (13)
Message 2 of 14

jeremytammik
Autodesk
Autodesk

You can probably find out for yourself:

 

  • Examine the element parameters with RevitLookup before modifying it.
  • Perform the desired modification manually in the user interface.
  • Examine the resulting parameter changes with RevitLookup.

 

That will probably show you what you need to do programmatically.

 

Here are more hints:

 

http://thebuildingcoder.typepad.com/blog/2017/01/virtues-of-reproduction-research-mep-settings-ontol...

 

Cheers,

 

Jeremy

 



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

0 Likes
Message 3 of 14

1120415118
Enthusiast
Enthusiast

Thanks, Jeremy,

I am sorry for that question, but this question was really proposed after some efforts of searching the parameter with Revit Lookup with a result of failing.

So apologize for that again. I will search further following the steps you have given to me.

0 Likes
Message 4 of 14

stever66
Advisor
Advisor
0 Likes
Message 5 of 14

1120415118
Enthusiast
Enthusiast

Hi, stever66,

Thanks for your bother as well.

0 Likes
Message 6 of 14

stever66
Advisor
Advisor

To get the available line pattern so you set one, one of these links might help:

 

https://adndevblog.typepad.com/aec/2015/03/revitapi-how-to-get-line-style-names-only-for-creating-de...

 

https://forum.dynamobim.com/t/get-all-project-line-styles-and-attributes/5147/7

 

 Did you try checking the samples in the Revit developers SDK?  It seems like there would be examples of this somewhere.

 

 

 

 

0 Likes
Message 7 of 14

1120415118
Enthusiast
Enthusiast

Thanks, stever66,

I am so happy for your reply again.  Fortunately, I haven't slept yet although it's the time of 02: 16 in my country. I got in touch with Revit API just in September of this year, and with the tight deadline given by my teacher, I have to Learn by doing. As you say, I didn't check the samples in the Revit developers SDK carefully, so I feel so sorry for bothering you helping me solve such a simple problem. Thank you again.

0 Likes
Message 8 of 14

stever66
Advisor
Advisor

Don't worry about bothering me.  I wouldn't be responding if I wasn't interested in the answer also.

 

It looks like you can get the graphicslinestyles from an existing category.  But it needs a "graphicsstyletype" argument, and I don't know what that is.  For example:

 

 

 Category myCategory = doc.Settings.Categories.get_Item(BuiltInCategory.OST_ElectricalFixtures);
            LinePattern myPattern = myCategory.GetLinePatternId(??graphicstyletype??);

 

I came up with yet link, but I haven't had time to look at it or try it:

 

https://stackoverflow.com/questions/24329204/create-a-new-subcategory-linestyle-in-revit

 

 

 

0 Likes
Message 9 of 14

1120415118
Enthusiast
Enthusiast

 

Category myCategory = doc.Settings.Categories.get_Item(BuiltInCategory.OST_StructuralFraming);
ElementId myPatternid = myCategory.GetLinePatternId(GraphicsStyleType.Projection);

I changed the projection linestyle of structuralframing in the UI, use the code upside to get its patternid, when I use

string patternname = doc.GetElement(myPatternid).Name;

to check whether the id is what I set before, it failed because patternname is null, but myPatternid is not null with the value of 

-3000010

. Then, I use the myPatternid to override other element 

 

 

OverrideGraphicSettings ogsred = new OverrideGraphicSettings();
ogsred.SetProjectionLinePatternId(new ElementId(-3000010));
view.SetElementOverrides(elemid, ogsred);

It failed again, so sad!

 

 

 

 

0 Likes
Message 10 of 14

jeremytammik
Autodesk
Autodesk

You need to be aware of the numerous different groupings and hierarchy levels in the BIM that may affect an individual element's graphical settings. Many settings can be overridden in so many ways:

 

https://thebuildingcoder.typepad.com/blog/2013/08/attributes-relationships-and-other-stuff.html#6

 

You seem to be interested in just the most low-level setting affecting one single element...

 

My 2c...

 

Cheers,

 

Jeremy

 



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

0 Likes
Message 11 of 14

1120415118
Enthusiast
Enthusiast

Hi Jeremy,

Thanks for your idea. It really helps me a lot. When using the override method, I run into another question that it is hard to filter the needed linepatternid such as dashed line, dotted-dashed line and so on after reading this articlehttps://adndevblog.typepad.com/aec/2015/03/revitapi-how-to-get-line-style-names-only-for-creating-de....

0 Likes
Message 12 of 14

jeremytammik
Autodesk
Autodesk

The Building Coder samples includes one little snippet of code showing how to use  view.SetElementOverrides to modify the colour of individual elements in a view:

 

    void SetModelCurvesColor(
      ModelCurveArray modelCurves,
      View view,
      Color color )
    {
      foreach( var curve in modelCurves
        .Cast<ModelCurve>() )
      {
        var overrides = view.GetElementOverrides(
          curve.Id );

        overrides.SetProjectionLineColor( color );

        view.SetElementOverrides( curve.Id, overrides );
      }
    }

 

A very similar method might work for the line pattern as well.

 

Cheers,

 

Jeremy

 



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

0 Likes
Message 13 of 14

Anonymous
Not applicable
-3000010 is subCategory id ,you can use linePatternElement id instead
0 Likes
Message 14 of 14

Anonymous
Not applicable

-3000010 is subCategory id ,you can use linePatternElement id instead

0 Likes