<?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 Re: Problem using Python script in Dynamo to change multiple family files in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/problem-using-python-script-in-dynamo-to-change-multiple-family/m-p/13092049#M2506</link>
    <description>&lt;P&gt;Thanks Jeremy, the redirection was a big help and I got it resolved on that site&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 17 Oct 2024 21:38:51 GMT</pubDate>
    <dc:creator>SDL-chris</dc:creator>
    <dc:date>2024-10-17T21:38:51Z</dc:date>
    <item>
      <title>Problem using Python script in Dynamo to change multiple family files</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/problem-using-python-script-in-dynamo-to-change-multiple-family/m-p/13087041#M2504</link>
      <description>&lt;P&gt;Thanks for your time viewing this. My first foray into API development (not even sure if the terms I'm using are correct) so please forgive any ignorance of Forum etiquette I might not be aware of (first post here too I think). Cheers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to build a macro to take a bunch of families in a folder, open each file and remove any line pattern definitions that match provided criteria (I'll add further clean-up duties to the script later hopefully). I ended up using Dynamo to generate the list of files and search criteria as that seemed easy to do, but decided it was best to then pass that info to a Python script to process the files (open, make changes, close, repeat). I can get different parts of the macro to work on their own, but having trouble putting it all together. I don't have the experience to understand what I'm doing wrong and am hoping it will be obvious to someone here.&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

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument
app = doc.Application

# The inputs to this node will be stored as a list in the IN variables.

input_paths = IN[0]
input_patterns = IN[1]

open_options = OpenOptions() #Creating a new OpenOptions object

#Creating an empty list to contain output
removed = []
for path in input_paths: #Iterating through each filepath string
	filepath = FilePath(path) #Creating a Revit FilePath object from this
	family_doc = app.OpenDocumentFile(filepath, open_options) #Telling the Revit application to open the file we specify)
	line_patterns = FilteredElementCollector(family_doc).OfClass(LinePatternElement).ToElements()
	
	#create list of line patterns to delete
	nameIdDict = {}
	#keylist = [IN[1]] #keylist is a list of pattern names to be deleted if existing
	#removed = []
	removed.append("file {}".format(path))
	for i in line_patterns:
		if i.Name in input_patterns:
			nameIdDict[i.Name] = i.Id
	
	removed.append("Found {} line patterns to delete".format(len(nameIdDict)))
	
	#remove line patterns from document
	TransactionManager.Instance.EnsureInTransaction(family_doc)
	
	for name, id in nameIdDict.items():
		removed.append("Will delete line pattern {}, ".format(name))
		removed.append("with ID {}".format(id))
		family_doc.Delete(id)
		
	TransactionManager.Instance.TransactionTaskDone()
		
	family_doc.Close(False)
	#Finally, closing the document (False = without saving)
	
OUT = removed #Outputting the list of patterns deleted&lt;/LI-CODE&gt;&lt;P&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SDLchris_1-1729051718645.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1421955i30A6AA7E8C59B5FF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SDLchris_1-1729051718645.png" alt="SDLchris_1-1729051718645.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2024 04:23:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/problem-using-python-script-in-dynamo-to-change-multiple-family/m-p/13087041#M2504</guid>
      <dc:creator>SDL-chris</dc:creator>
      <dc:date>2024-10-16T04:23:04Z</dc:date>
    </item>
    <item>
      <title>Re: Problem using Python script in Dynamo to change multiple family files</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/problem-using-python-script-in-dynamo-to-change-multiple-family/m-p/13087185#M2505</link>
      <description>&lt;P&gt;Dear Chris,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Welcome to the Revit API and congratulations on getting all your bits and pieces to work individually.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your script looks fine to me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, unfortunately, it is hard for me to say anything about why it might not work, since I am not conversant in Python or Dynamo. This forum is dedicated to the pure .NET Revit API. Dynamo provides a wrapper around that. To discuss Dynamo-specific questions, you will probably be better of raising this in the Dynamo forum:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://forum.dynamobim.com" target="_blank"&gt;https://forum.dynamobim.com&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2024 06:20:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/problem-using-python-script-in-dynamo-to-change-multiple-family/m-p/13087185#M2505</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2024-10-16T06:20:51Z</dc:date>
    </item>
    <item>
      <title>Re: Problem using Python script in Dynamo to change multiple family files</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/problem-using-python-script-in-dynamo-to-change-multiple-family/m-p/13092049#M2506</link>
      <description>&lt;P&gt;Thanks Jeremy, the redirection was a big help and I got it resolved on that site&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2024 21:38:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/problem-using-python-script-in-dynamo-to-change-multiple-family/m-p/13092049#M2506</guid>
      <dc:creator>SDL-chris</dc:creator>
      <dc:date>2024-10-17T21:38:51Z</dc:date>
    </item>
  </channel>
</rss>

