# pyRevit Script - LineStyle Change

**URL:** <https://forum.dynamobim.com/t/pyrevit-script-linestyle-change/17511>\
**Category:** DesignScript\
**Created:** [December 19, 2017, 12:32am UTC](https://forum.dynamobim.com/t/pyrevit-script-linestyle-change/17511 "2017-12-19T00:32:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andy2](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Andy2](https://forum.dynamobim.com/u/Andy2)\
**Post date:** [December 19, 2017, 12:32am UTC](https://forum.dynamobim.com/t/pyrevit-script-linestyle-change/17511/1 "2017-12-19T00:32:11Z")

</div>

Hi Everyone,

Objective: Change LineStyle

History;  
I’m struggling here with changing the LineStyle of a line that is already drawn. I’m assuming I need to draw the line and than modify the linestyle of the 1 that is drawn.

I found this in the Revit API Documentary - [LineStyle](http://revitapisearch.com.s3-website-us-east-1.amazonaws.com/html/691e64a2-e5ea-b619-4362-1a2c17e23b2f.htm)  
I’m assuming I use the C# and than convert that into what I believe Python will be (Newbie Question - Is there a python dictionary similar to this Revit API C#? or do i just always take a calculated guess on the conversion? I’ve been searching all over the forums/google and haven’t stumbled across a full list yet)

So based on that I believe i’m supposed to use  
Element.LineStyle(get, set.12404)

Attached is my script -.  
[script.py](https://forum.dynamobim.com/uploads/short-url/a742jdyaZYhFRRY8RMTlQmqS1EG.py) (727 Bytes)

I’ve searched all the forums & even tried pulling a piece off this;

[Code Example](https://forum.dynamobim.com/t/creation-of-curves-in-a-drafting-view/845/4)

I’m very green and apologies in advanced for some a newbie question.

Thanks in advanced  
Andy

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [December 19, 2017, 1:41am UTC](https://forum.dynamobim.com/t/pyrevit-script-linestyle-change/17511/2 "2017-12-19T01:41:00Z")

</div>

Not a [pyRevit](https://discourse.pyrevitlabs.io/) solution (then again this isn’t a [pyRevit](https://discourse.pyrevitlabs.io/) forum), but you could do this in Dynamo with all out of the box nodes (the design script in code blocks is just to illustrate the before and after):

 ![Setting Line Style in Dynamo](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/1/e18deb6448f904b5ae03032118167fd0cce89037.png)

---

<div class="post-metadata">

**Author:** ![salvatoredragotta](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/salvatoredragotta/32/10078_2.png) [@salvatoredragotta](https://forum.dynamobim.com/u/salvatoredragotta)\
**Post date:** [December 19, 2017, 3:50am UTC](https://forum.dynamobim.com/t/pyrevit-script-linestyle-change/17511/3 "2017-12-19T03:50:38Z")

</div>

Note sure if this is what you are after.

Save the below code as a py file. it will let you select a detail line and change its line style to “Medium Lines”

Thanks @Konrad_K_Sobon for the code to retrieve the Line styles (_“Get Line Style by Name”_ Node)

```
import clr

# Import RevitAPI
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument

__window__.Close()

reference = uidoc.Selection.PickObject(Selection.ObjectType.Element, "Select Line")

Line = doc.GetElement(reference.ElementId)

cat = Category.GetCategory(doc, BuiltInCategory.OST_Lines)
gs = cat.GetGraphicsStyle(GraphicsStyleType.Projection)
gsCat = gs.GraphicsStyleCategory.SubCategories
lineStyles = [i.GetGraphicsStyle(GraphicsStyleType.Projection) for i in gsCat]

lStyle = []
try:
	lStyle.append(next(i for i in lineStyles if "Medium Lines"==i.Name))
except StopIteration:
	pass

 
t = Transaction(doc, "Change Line Style")
t.Start()

Line.LineStyle=lStyle[0]

t.Commit()
```

---

<div class="post-metadata">

**Author:** ![Andy2](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Andy2](https://forum.dynamobim.com/u/Andy2)\
**Post date:** [December 19, 2017, 4:36am UTC](https://forum.dynamobim.com/t/pyrevit-script-linestyle-change/17511/4 "2017-12-19T04:36:53Z")

</div>

You are awesome, That managed to work with a few minor tweaks. I feel its very complicated tho, is that normal? or is there a simplier way of doing it.

I need to work out how to loop it now, So it does multiple lines next challenge for me…

Thank you heaps 🙂

```
# pyRevit
import clr
import math
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
app = __revit__.Application
view = doc.ActiveView

#----
__doc__ = '0.18 Continuous Line'

#Transaction1
t = Transaction(doc, "Draw Line")
t.Start()
	
#Pick Points
p1 = uidoc.Selection.PickPoint("Click to specify instance location.")
p2 = uidoc.Selection.PickPoint("Click to specify instance location.")
 
#Commands
Line = Line.CreateBound(p1, p2)
NewLine = doc.Create.NewDetailCurve(view,Line)

#Linestyle
gsCat = Category.GetCategory(doc, BuiltInCategory.OST_Lines).GetGraphicsStyle(GraphicsStyleType.Projection).GraphicsStyleCategory.SubCategories
lineStyles = [i.GetGraphicsStyle(GraphicsStyleType.Projection) for i in gsCat]
lStyle = []
try:
	lStyle.append(next(i for i in lineStyles if "Medium Lines"==i.Name))
except StopIteration:
	pass
NewLine.LineStyle=lStyle[0]
		
t.Commit()
```

---

<div class="post-metadata">

**Author:** ![Ewan\_Opie](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ewan_opie/32/77070_2.png) [@Ewan\_Opie](https://forum.dynamobim.com/u/Ewan_Opie)\
**Post date:** [December 19, 2017, 8:22pm UTC](https://forum.dynamobim.com/t/pyrevit-script-linestyle-change/17511/5 "2017-12-19T20:22:05Z")

</div>

Hi @Andy2,

Great to hear you are experimenting further with this to implement looping/multiple element application. 👍

You are correct in assuming simplified solutions exists, here is but one of them.

![Change LineStyle](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/3/535df492b91fc1f3abb2675c8b61dcf282ba62d9.gif)  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/9/3975ca3232e4c0bc476ab2ace56fd1921d408c39.png)  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/f/cf62b154e7f582c07b64554b200d46de4efdea8e.png)
