Setting active line style

Setting active line style

stanleypaseur
Contributor Contributor
3,134 Views
4 Replies
Message 1 of 5

Setting active line style

stanleypaseur
Contributor
Contributor

I have a revit file that has several different line styles. I am trying to write a C# routine that will create a large schedule. The schedule is in a detail view so all elements are detail lines and text. I searched the API help file and found "public Element LineStyle { get; set; }". I see that is a member of the  "CurvedElement" class. I am beginning to learn C# and the API calls. Can someone show me a couple of lines of how to call the appropriate method to set the active line style. I have line style "LineWt2" and "LineWt6". I want to the active line style to be "LineWt6" when the detail line is drawn. Your help greatly appreciated.

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

Anonymous
Not applicable

Another great resource to help while you're learning is the building coder github here:

https://github.com/jeremytammik/the_building_coder_samples

 

Searching for linestyle results in a code sample of exactly what I believe you're looking for

// Find existing linestyle.  Can also opt to
      // create one with LinePatternElement.Create()

      FilteredElementCollector fec 
        = new FilteredElementCollector( doc )
          .OfClass( typeof( LinePatternElement ) );

      LinePatternElement linePatternElem = fec
        .Cast<LinePatternElement>()
        .First<LinePatternElement>( linePattern 
          => linePattern.Name == "Long Dash" );
0 Likes
Message 3 of 5

stanleypaseur
Contributor
Contributor
Thanks for the information. I do not think this will solve the issue. I know what linestyles are available in the project. I have linestyles "Solid-wt-2", "Solid-wt-3", "Solid-wt-4" and "Solid-wt-6". I am trying to create a schedule and to make it easier to read I would like to have every 5th line "Solid-wt-6". So I need to be able to set the linestyle before creating the line. I am using the following method to create the line.

Line lineOne = line.CreateBound(double point1, double point2);

Stanley Paseur
stanleyp@sdg-structure.com

Structural Design Group
220 Great Circle Road
Suite 106
Nashville, Tennessee 37228
p. 615.255.5537
f. 615.255.1486
www.sdg-structure.com
0 Likes
Message 4 of 5

FAIR59
Advisor
Advisor
Accepted solution

there isn't a method to set the linestyle beforehand. Just make the line and set the linestyle for that line.

 

                XYZ pt1=new XYZ(0,0,0);
                XYZ pt2 = new XYZ(2,0,0);
                Line lineOne = Line.CreateBound(pt1, pt2);
            Autodesk.Revit.DB.View detailView = doc.ActiveView;
            Category LinesCat = doc.Settings.Categories.get_Item( BuiltInCategory.OST_Lines);
            Category SolidW6 = LinesCat.SubCategories.get_Item("solid-wt-6");
            GraphicsStyle solid_wt_6 = SolidW6.GetGraphicsStyle( GraphicsStyleType.Projection)  ;
            using (Transaction t = new Transaction(doc, "place line"))
            {
                t.Start();
                DetailCurve detailLine = doc.Create.NewDetailCurve(detailView, lineOne);
                detailLine.LineStyle = solid_wt_6;
                t.Commit();
            }

 

 

Message 5 of 5

stanleypaseur
Contributor
Contributor
Thanks very much for the help. I do not think I would have every thought use "Category". Still learning ( just started about a month ago).

Stanley Paseur
stanleyp@sdg-structure.com

Structural Design Group
220 Great Circle Road
Suite 106
Nashville, Tennessee 37228
p. 615.255.5537
f. 615.255.1486
www.sdg-structure.com
0 Likes