So recently, i tried playing around with connector creation in a family document and the ultimate goal is to create a connector on each nested family extrusion.
Here comes the issue, my connector is always at the origin of my family document, do any of you know why??
below is the entire code in python and the familydoc, and dynamo file:
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Import RevitAPI
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Mechanical import *
from Autodesk.Revit.DB.Plumbing import *
from Autodesk.Revit.DB.ExternalService import *
from Autodesk.Revit.DB.ExtensibleStorage import *
# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Import ToProtoType, ToRevitType geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)
# Import DSCore nodes in Dynamo
clr.AddReference('DSCoreNodes')
import DSCore
from DSCore import *
# Import python library
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
import os
import shutil
import math
# Import math library
from math import *
#Import Data and Time
from datetime import datetime
now = datetime.now()
#Import System Library
import System
from System.Collections.Generic import *
from System.IO import Directory, Path
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
geoOptions = app.Create.NewGeometryOptions();
geoOptions.View = doc.ActiveView;
geoOptions.ComputeReferences = True;
def GetFacesOfElement(ele):
result = list()
geoElement = ele.get_Geometry(geoOptions)
for geoObject in geoElement:
geoInstances = geoObject.GetInstanceGeometry()
for sol in geoInstances:
if sol.Faces.Size > 0:
result.extend(sol.Faces)
return [r for r in result if type(r) == PlanarFace]
#Preparing input from dynamo to revit
pvp = ParameterValueProvider(ElementId(BuiltInParameter.IS_VISIBLE_PARAM))
fr = FilterIntegerRule(pvp, FilterNumericEquals(), 1)
epf = ElementParameterFilter(fr)
pvp1 = ParameterValueProvider(ElementId(BuiltInParameter.SYMBOL_NAME_PARAM))
fr1 = FilterStringRule(pvp1, FilterStringContains(), "Connector", False)
epf1 = ElementParameterFilter(fr1)
replica_Conns = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).WhereElementIsNotElementType().WherePasses(LogicalAndFilter(epf,epf1)).ToElements()
testing = list()
TransactionManager.Instance.EnsureInTransaction(doc)
famManager = doc.FamilyManager
for replica_Conn in replica_Conns:
faces = GetFacesOfElement(replica_Conn)
_reference = faces[0].Reference
conEle = ConnectorElement.CreateDuctConnector(doc, DuctSystemType.SupplyAir, ConnectorProfileType.Round, _reference)
testing.append(conEle)
TransactionManager.Instance.TransactionTaskDone()
#Final output
OUT = testing
ConnectorCreation.dyn (17.3 KB) TESTAHU.rfa (408 KB)
Any help is much appreciated