Possible bug? LinePatternElement.GetLinePattern returns null with a valid ElementId

Possible bug? LinePatternElement.GetLinePattern returns null with a valid ElementId

thomas
Advocate Advocate
998 Views
2 Replies
Message 1 of 3

Possible bug? LinePatternElement.GetLinePattern returns null with a valid ElementId

thomas
Advocate
Advocate

I'm unable to return the LinePattern object from a GraphicStyle which has a valid line pattern Id. Using Revit 2022. 

 

For example the built-in <Insulation Batting Lines> has a line pattern id associated as GetLinePatternId() returns the built in (negative) element id. 

 

When I attempt to retrieve the LinePattern object via LinePatternElement.GetLinePattern(doc, linePatternId) it always returns null. The API documentation states that the linePatternId input can be "The ElementId of the LinePatternElement or the built-in line pattern id."

 

Here is a code snippet in Python to test (I'm doing a quick test in Dynamo): 

 

 

import clr

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument

lineStyle = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines)

lineStyleSubTypes = lineStyle.SubCategories

lineStyleAttributesList = []
for category in lineStyleSubTypes:
	gs = category.GetGraphicsStyle(GraphicsStyleType.Projection)
	
	lineStyleAttributesList.Add(gs)

gs1 = lineStyleAttributesList[0]

cat = gs1.GraphicsStyleCategory 

linePatternId = cat.GetLinePatternId(GraphicsStyleType.Projection)

linePattern = LinePatternElement.GetLinePattern(doc, linePatternId)

OUT = linePattern

 

0 Likes
999 Views
2 Replies
Replies (2)
Message 2 of 3

thomas
Advocate
Advocate

Update: One thing I have discovered is this issue seems to only happen if the built-in Solid line style is applied. However, I would still expect the GetLinePattern to return a LinePattern object, especially based on what the API documentation states. 

 

EDIT: This must be the problem; the LinePatternElement.GetSolidPatternId() remarks state "Note that Solid is special. It isn't a line pattern at all -- it is a special code that tells drawing and export code to use solid lines rather than patterned lines. Solid is visible to the user when selecting line patterns."

 

Given that the Solid line pattern is the only built in line pattern id (I believe) can I request the API documentation for LinePatternElement.GetLinePattern is updated as it is misleading if I'm not mistaken. 

Message 3 of 3

Sean_Page
Collaborator
Collaborator

I am glad I ran across this post, as I am experiencing the same thing, and I was rather confused why a valid Id wasn't returning an actual element.

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect