Message 1 of 3
How to Assign line pattern to model line
Not applicable
06-12-2016
08:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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();
