Above code shows bb mid point far away from element categories(windows, electrical fixtures, etc…) which has witness lines or dimension reference lines, how to get BB midpoint of element ignoring these?
@Draxl_Andreas
Not working for element or family instance which has witness lines, I am using Dynamo python script node for this, but how to ignore element witness lines for bounding box midpoint to be on element itself?
First generate a new view, then disable the lines categories in that view. Use that view when pulling the bounding box and it should omit the curves. Once the bounding box is taken you can delete the new view.
# Load the Python Standard and DesignScript Libraries
import clr
import sys
import itertools
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
import System
from System import Array
from System.Collections.Generic import *
clr.AddReference('ProtoGeometry')###REMOVED FOR error, 2 lines only
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
from Revit.Elements import Element
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *
clr.AddReference('DSCoreNodes')
from DSCore.List import Flatten
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = uiapp.ActiveUIDocument
# The inputs to this node will be stored as a list in the IN variables.
inputElements = IN[0]
view1 = doc.ActiveView
opt=Options()
opt.ComputeReferences = False
opt.IncludeNonVisibleObjects = False
#opt.View = view1
def get_bb_mid(ele):
bb1 = None
geo = ele.get_Geometry(opt)
for a in geo:
geoInst = a.GetInstanceGeometry()
for g in geoInst:
if isinstance(g, Solid):
bb1 = g.GetBoundingBox()
if bb1:
break
return bb1
centroid_lst = []
for ele1 in inputElements:
#ele_typ_id = ele.GetType()
ele = UnwrapElement(ele1)
pt1 = get_bb_mid(ele)
centroid_lst.append(pt1)
# Assign your output to the OUT variable.
OUT = centroid_lst
tried above
getting boundingboxXYZ, i need one mid point on element
Sending Rvt file may take time, but i observed that, if I move witness lines near to element, bounding box midpoint is near to element & this may work for me, majority elements are familyInstances which has this issue, how to ignore these witness lines to get element BB midpoint?
Review the C# code previously provided. Or filter out non-solids from the list of geometry, union the remaining solids into a single solid, and pull the bounding box from the single solid.
Hi there,
I recommend using the Archilab Package GetCentroid method; it worked for me when I encountered the same issue.
Edit-
Supplying the model elements directly to this node will do the job and no need to get the bounding box from Element.
i cant answer directly ... i cant find in the API GetCentroid
import clr
import sys
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('System')
from System.Collections.Generic import List
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
#functions
def tolist(x):
if hasattr(x,'__iter__'): return x
else: return [x]
#Preparing input from dynamo to revit
elements = UnwrapElement(tolist(IN[0]))
output = []
for i in elements:
output.append(i.get_Geometry(Options()))
OUT = output
#functions
def tolist(x):
if hasattr(x,'__iter__'): return x
else: return [x]
elements = UnwrapElement(tolist(IN[0]))
output = []
for i in elements:
output.append(i.Centroid)
OUT = output