<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic python - get family type name from value in comments parameter in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/python-get-family-type-name-from-value-in-comments-parameter/m-p/11913130#M12492</link>
    <description>&lt;LI-CODE lang="general"&gt;# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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 *
from Autodesk.Revit.UI.Selection import *
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import TaskDialog

import random
import string

doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
selection = uidoc.Selection
comments_structural_framing = IN[0]
structural_framing_family = IN[1]

# Get the selected detail item family
ref = selection.PickObject(ObjectType.Element, "Select a detail item family")
detail_item_family = doc.GetElement(ref)

# Start a transaction
TransactionManager.Instance.EnsureInTransaction(doc)

text_parameters = [p for p in detail_item_family.Parameters if p.StorageType == StorageType.String]

# Get the parameter with the specified name
parameter = None
for p in text_parameters:
    if p.Definition.Name == comments_structural_framing:
        parameter = p
        break
      
if parameter is not None and parameter.StorageType == StorageType.ElementId:
    family_id = parameter.AsElementId()
    family = doc.GetElement(family_id)
    if family.Category.Id.IntegerValue == (int) (BuiltInCategory.OST_StructuralFraming):
        OUT = family.Name
    else:
        OUT = "The value of the specified parameter does not correspond to a structural framing family."
else:
    OUT = "Parameter not found or has invalid type"

# Commit the transaction
TransactionManager.Instance.TransactionTaskDone()

# Display a message
TaskDialog.Show("Success", "The name of the structural framing family is: {}".format(OUT))# &lt;/LI-CODE&gt;&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in this script i'm trying &lt;SPAN&gt;to pick a detail item family.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if the &lt;STRONG&gt;text_parameter&lt;/STRONG&gt; name of the detail item is &lt;STRONG&gt;p.Definition.Name == comments_structural_framing&lt;/STRONG&gt; i need to find&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;the type name of the corresponding structural framing family. i then need to write this type name to the value of the text parameter in the detail item family.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;apparently is not finding any&lt;STRONG&gt;&amp;nbsp;p.Definition.Name == comments_structural_framing&amp;nbsp;&lt;/STRONG&gt;so it skip to&amp;nbsp;&lt;STRONG&gt;"Parameter not found or has invalid type".&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I know it's a little crazy but i hope you can help!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 21 Apr 2023 16:16:24 GMT</pubDate>
    <dc:creator>ellliaz</dc:creator>
    <dc:date>2023-04-21T16:16:24Z</dc:date>
    <item>
      <title>python - get family type name from value in comments parameter</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/python-get-family-type-name-from-value-in-comments-parameter/m-p/11913130#M12492</link>
      <description>&lt;LI-CODE lang="general"&gt;# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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 *
from Autodesk.Revit.UI.Selection import *
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import TaskDialog

import random
import string

doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
selection = uidoc.Selection
comments_structural_framing = IN[0]
structural_framing_family = IN[1]

# Get the selected detail item family
ref = selection.PickObject(ObjectType.Element, "Select a detail item family")
detail_item_family = doc.GetElement(ref)

# Start a transaction
TransactionManager.Instance.EnsureInTransaction(doc)

text_parameters = [p for p in detail_item_family.Parameters if p.StorageType == StorageType.String]

# Get the parameter with the specified name
parameter = None
for p in text_parameters:
    if p.Definition.Name == comments_structural_framing:
        parameter = p
        break
      
if parameter is not None and parameter.StorageType == StorageType.ElementId:
    family_id = parameter.AsElementId()
    family = doc.GetElement(family_id)
    if family.Category.Id.IntegerValue == (int) (BuiltInCategory.OST_StructuralFraming):
        OUT = family.Name
    else:
        OUT = "The value of the specified parameter does not correspond to a structural framing family."
else:
    OUT = "Parameter not found or has invalid type"

# Commit the transaction
TransactionManager.Instance.TransactionTaskDone()

# Display a message
TaskDialog.Show("Success", "The name of the structural framing family is: {}".format(OUT))# &lt;/LI-CODE&gt;&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in this script i'm trying &lt;SPAN&gt;to pick a detail item family.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if the &lt;STRONG&gt;text_parameter&lt;/STRONG&gt; name of the detail item is &lt;STRONG&gt;p.Definition.Name == comments_structural_framing&lt;/STRONG&gt; i need to find&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;the type name of the corresponding structural framing family. i then need to write this type name to the value of the text parameter in the detail item family.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;apparently is not finding any&lt;STRONG&gt;&amp;nbsp;p.Definition.Name == comments_structural_framing&amp;nbsp;&lt;/STRONG&gt;so it skip to&amp;nbsp;&lt;STRONG&gt;"Parameter not found or has invalid type".&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I know it's a little crazy but i hope you can help!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 16:16:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/python-get-family-type-name-from-value-in-comments-parameter/m-p/11913130#M12492</guid>
      <dc:creator>ellliaz</dc:creator>
      <dc:date>2023-04-21T16:16:24Z</dc:date>
    </item>
    <item>
      <title>Re: python - get family type name from value in comments parameter</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/python-get-family-type-name-from-value-in-comments-parameter/m-p/11913203#M12493</link>
      <description>&lt;P&gt;&lt;SPAN&gt;"i need to find&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;the type name of the corresponding structural framing family"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if i understand well, you want to find the type in the class OST_StructuralFraming with the corresponding name of a detail family?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 16:42:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/python-get-family-type-name-from-value-in-comments-parameter/m-p/11913203#M12493</guid>
      <dc:creator>Yien_Chao</dc:creator>
      <dc:date>2023-04-21T16:42:30Z</dc:date>
    </item>
    <item>
      <title>Re: python - get family type name from value in comments parameter</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/python-get-family-type-name-from-value-in-comments-parameter/m-p/11913217#M12494</link>
      <description>&lt;P&gt;Yes. Where the parameters&amp;nbsp;&lt;SPAN&gt;name of the detail family are equal to the comments parameters of the structural framing family.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 16:52:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/python-get-family-type-name-from-value-in-comments-parameter/m-p/11913217#M12494</guid>
      <dc:creator>ellliaz</dc:creator>
      <dc:date>2023-04-21T16:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: python - get family type name from value in comments parameter</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/python-get-family-type-name-from-value-in-comments-parameter/m-p/11913249#M12495</link>
      <description>&lt;P&gt;i suggest to create a dictionary.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;get your detail element names.&lt;/P&gt;&lt;P&gt;then create a dictionary of your&amp;nbsp;&lt;SPAN&gt;OST_StructuralFraming, comments : name of type&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;then create&amp;nbsp; loop on your detail item's name and search in the dictionary.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;hope that might help.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 17:01:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/python-get-family-type-name-from-value-in-comments-parameter/m-p/11913249#M12495</guid>
      <dc:creator>Yien_Chao</dc:creator>
      <dc:date>2023-04-21T17:01:43Z</dc:date>
    </item>
    <item>
      <title>Re: python - get family type name from value in comments parameter</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/python-get-family-type-name-from-value-in-comments-parameter/m-p/11913335#M12496</link>
      <description>&lt;P&gt;smart! i'll try that, thanks &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 17:28:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/python-get-family-type-name-from-value-in-comments-parameter/m-p/11913335#M12496</guid>
      <dc:creator>ellliaz</dc:creator>
      <dc:date>2023-04-21T17:28:33Z</dc:date>
    </item>
    <item>
      <title>Re: python - get family type name from value in comments parameter</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/python-get-family-type-name-from-value-in-comments-parameter/m-p/11917891#M12497</link>
      <description>&lt;P&gt;and it worked! thanks&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import clr # import Common Language Runtime

from Autodesk.Revit.DB import *
from Autodesk.Revit.UI.Selection import *

doc = DocumentManager.Instance.CurrentDBDocument

# Get all Structural Framing elements
structural_framing_collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralFraming).WhereElementIsNotElementType()

# Create an empty dictionary to store the comments and names of the Structural Framing elements
structural_framing_dict = {}

# Loop through each Structural Framing element and add its comments and name to the dictionary
for element in structural_framing_collector:
    comments = element.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).AsString()
    name = element.Name
    if comments and comments != "":
        structural_framing_dict[comments] = name

# Get all Detail Item elements
detail_item_collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_DetailComponents).WhereElementIsNotElementType()

# Start a transaction
TransactionManager.Instance.EnsureInTransaction(doc)

# Loop through each Detail Item element and compare its text parameters with the names in the dictionary
for element in detail_item_collector:
    for key in structural_framing_dict.keys():
        param = element.LookupParameter(key)
        if param and param.StorageType == StorageType.String:
            param.Set(structural_framing_dict[key])

# Commit the transaction
TransactionManager.Instance.TransactionTaskDone()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 14:07:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/python-get-family-type-name-from-value-in-comments-parameter/m-p/11917891#M12497</guid>
      <dc:creator>ellliaz</dc:creator>
      <dc:date>2023-04-24T14:07:37Z</dc:date>
    </item>
  </channel>
</rss>

