How to Assign line pattern to model line

How to Assign line pattern to model line

Anonymous
Not applicable
3,253 Views
2 Replies
Message 1 of 3

How to Assign line pattern to model line

Anonymous
Not applicable

Hi,

 

I was able to create my linePattern. I can create the model line. I can assign a color to the line. How do I assign my LinePatternElement to my model line so it shows up dashed?

 

 

public void createGraphicsStyle()
		{
			
			
			Autodesk.Revit.DB.Document doc = this.ActiveUIDocument.Document;
			
			 //create an arc first
			 XYZ end0 = new Autodesk.Revit.DB.XYZ(0, 1, 0);
                XYZ end1 = new Autodesk.Revit.DB.XYZ(0, 2, 0);
                XYZ pointOnArc = new XYZ(.2,.5,0);
                
                 Transaction trans = new Transaction(doc,"create model arc");
                trans.Start();
                
                //try to get existing line style
                string nameOfCategory = "AuditoriumMaker Row Layout Lines";
                string nameOfLinePattern = "AuditoriumMaker Row Layout Line Pattern";
                Color auditoriumMakerRowLayoutLineColor = new Color(238, 132, 63);
                Category myCategory = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines);
                if(myCategory.SubCategories != null)
                {
                	foreach (var element in myCategory.SubCategories)
                	{
                		Category cat = element as Category;
                		if(cat.Name == nameOfCategory)
                		{
                			trans.Commit();
                			return;
                		}
                	}
                }
                
                
                //Make the custom line pattern
                LinePattern myLinePattern = new LinePattern(nameOfLinePattern);
                IList<LinePatternSegment> rowLayoutLinePatternSegmentList = new List<LinePatternSegment>();
                LinePatternSegment lineSeg1 = new LinePatternSegment(LinePatternSegmentType.Dash, .010);
                LinePatternSegment lineSeg2 = new LinePatternSegment(LinePatternSegmentType.Space, .010);
                rowLayoutLinePatternSegmentList.Add(lineSeg1);
                rowLayoutLinePatternSegmentList.Add(lineSeg2);
                rowLayoutLinePatternSegmentList.Add(lineSeg1);
                rowLayoutLinePatternSegmentList.Add(lineSeg2);
                myLinePattern.SetSegments(rowLayoutLinePatternSegmentList);
                LinePatternElement myNewLinePatternElement = LinePatternElement.Create(doc, myLinePattern);
                
                //assign the line pattern to the element
                myNewLinePatternElement.SetLinePattern(myLinePattern);
               
                //create line style
                Category parentCategory = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines);
                myCategory = doc.Settings.Categories.NewSubcategory(parentCategory, nameOfCategory);
                myCategory.LineColor = auditoriumMakerRowLayoutLineColor;
                
                //myCategory.LinePatternElement??????????
                
                
                Plane myPlane = new Plane(new XYZ(0,0,1), new XYZ(0,0,0));
                SketchPlane mySketchPlane = SketchPlane.Create(doc, myPlane);

                Arc arc = Arc.Create(end0, end1, pointOnArc);
                
               
                ModelArc modelArc = doc.Create.NewModelCurve(arc, mySketchPlane) as ModelArc;
                
                //assign the LineStyle to the modelArc
                GraphicsStyle gs = myCategory.GetGraphicsStyle(GraphicsStyleType.Projection);
                modelArc.LineStyle = gs;
                
                
                trans.Commit();
0 Likes
3,254 Views
2 Replies
Replies (2)
Message 2 of 3

Revitalizer
Advisor
Advisor

Hi,

 

in Revit 2017, you can use Category.SetLinePatternId:

http://forums.autodesk.com/t5/revit-api/how-to-set-line-pattern-in-line-style/td-p/3731078

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 3 of 3

JimJia
Alumni
Alumni
Yes, Category.SetLinePatternId is the solution, however, prior to 2017, Revit doesn't support LinePattern modification for category yet.

Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: Jim.Jia@autodesk.com
0 Likes