Hi,
Iâm trying to create a dimension from the columnâs bare lines to the centerline (I came up short in ootb).
So I tried with the API and Python, same problem.
I tried with the center of the column, it only partially works.
I donât understand why itâs not working. I have the references (is the way to get them the right one?) in both cases.
Does this come from 2024?
The Python codes arenât great (normal, Iâm still feeling my way).
import sys
import clr
import math
import System
from System.Collections.Generic import List
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
def findgrid(te):
stock=[]
a=te.replace("-","*")
b=a.replace("(","*")
c=b.replace(")","*")
d=c.split("*")
for e in d:
if "." in e or len(e)==0:
""
else:
stock.append(e)
return stock
columns=UnwrapElement(IN[0])
v=UnwrapElement(IN[1])
lgrid=FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Grids).WhereElementIsNotElementType().ToElements()
def createdimcol(c,lgrid):
gridHn=findgrid(c.LookupParameter("Marque d'emplacement du poteau").AsString())[0]
gridVn=findgrid(c.LookupParameter("Marque d'emplacement du poteau").AsString())[1]
gridH=Reference([i for i in lgrid if i.Name==gridHn][0])
gridV=Reference([i for i in lgrid if i.Name==gridVn][0])
opt=Options()
opt.ComputeReferences = True
geoe=c.get_Geometry(opt)
sol=[g for g in geoe][0].GetInstanceGeometry()
solid=[i for i in sol][1]
print(solid.Volume)
fah=[f for f in solid.Faces if f.FaceNormal.Y==1 or f.FaceNormal.Y==-1]
fav=[f for f in solid.Faces if math.fabs(f.ComputeNormal(UV.Zero).X)==1]
refarrayH=ReferenceArray()
refarrayH.Append(gridH)
refarrayH.Append(c.GetReferences(FamilyInstanceReferenceType.CenterFrontBack)[0])
refarrayH.Append(fah[1].Reference)
refarrayH.Append(fah[0].Reference)
ploc=c.Location.Point
liny=Line.CreateBound(XYZ((ploc.X)+1,ploc.Y,ploc.Z),XYZ((ploc.X)+1,(ploc.Y)+1,ploc.Z))
dimensionv = doc.Create.NewDimension(v, liny, refarrayH)
doc.Regenerate()
return dimensionv,len(fah),gridH.ElementId,fah[0].Reference.ElementId,fah[1].Reference.ElementId
TransactionManager.Instance.EnsureInTransaction(doc)
dimsV = [createdimcol(c,lgrid) for c in columns]
TransactionManager.Instance.TransactionTaskDone()
OUT = dimsV
rep 30 mai N2.dyn (67.1 KB)
edit:
I get the value between the two faces (after conversion) but the dimension is not represented and the distance via the grid is anarchic (I really donât understand anythingâŚ)
If I donât put the reference of the center of the family, no dimension is represented but 1 value out of 2 is correct.
Sincerely,
christian.stan