I got it, using weird names and for sure not the cleanest way:
Iām at a conference this week so I canāt fix up anything on this topic myself, but I think this link can provide some clarity for now: https://pythonsimplified.com/comprehensive-guide-to-python-list-comprehensions/
Thanks Jacob, this is very helpfull and now i know what this is about
I tried to use this in my script but i didĀ“nt get expected results. I donĀ“t really know where i can use this method. No big deal as long as the code works, but if someone ever wants to help me to clean some things up, IĀ“m in.
But for now there are some problems i have to deal with:
- This datum plane doesnāt support bubble operations. -or- This DatumPlane doesnāt have bubbles shown the view.
There are grids in my project that canĀ“t have a bubble activated. DonĀ“t ask me why. The problem is my āSet Bubblesā code will not work if one of sayd grids is in the view. Is there any way to let me check if bubble can be set so i can modify the code so these grids will just be skipped? Or any other way to make the code work for all the other grids?
- A segmented gridline will give 2 curves and will be treated like 2 curves:
I have to check if a grid consists of more than one curve and then treat this segmented grids in another way.
@gerhard.p Fantastic work! Learning so much just reading this thread. Thanks
please look at this topic , i am stuck in this
https://forum.dynamobim.com/t/set-grids-design/82060/4
Thanks
Hello @Luffy11
Hmm, your picture looks good, the horizontal grid extens got set correct, didnĀ“t they?
Do you mean that multi segment grids? The code does not work for them, better filter them out.
What bothers me is that the code does not work if the whole grid is out of the cropbox. But your case should work.
@gerhard.p @c.poupin Thanks a lot. With your help, I can make a code.
04.View&Dimension 20230324.dyn (155.7 KB)
I used the script from above and eliminated all the dimensioning.
I am left with the Python and setting all datum extends within a detail view.
As I donāt know any Python I could use some help here.
I want to set all extends ON the cropbox EXCEPT for the grids that have their bubble active. Those sides I want to offset another -7mm (so the bubble is also within the cropbox)
Is this easily done?
Below is the code that I extracted from the script
import clr
import System
clr.AddReference('ProtoGeometry')
import Autodesk.DesignScript.Geometry as DSGeo
from Autodesk.DesignScript.Geometry import *
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
clr.AddReference('System')
from System.Collections.Generic import List
#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
uidoc = uiapp.ActiveUIDocument
app = uiapp.Application
sdkNumber = int(app.VersionNumber)
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
def createDatumLine(boundLines, crv):
gridLine = None
curveG = crv
vectGrid = curveG.Direction
lstPtToLine = []
for lineBound in boundLines:
rayc = DB.Line.CreateUnbound(XYZ(curveG.Origin.X, curveG.Origin.Y, curveG.Origin.Z) , vectGrid)
dummy = None
outInterR:IntersectionResultArray
result, outInterR = rayc.Intersect(lineBound, dummy)
print("////Result :", result, outInterR)
if result == SetComparisonResult.Overlap:
interResult = outInterR
lstPtToLine.append(interResult[0].XYZPoint)
print("////lstPtToLine : ", lstPtToLine)
if len(lstPtToLine) == 2:
gridLine = Autodesk.Revit.DB.Line.CreateBound(lstPtToLine[0], lstPtToLine[1])
#new line ģ ė°©ķ„ģ źø°ģ”“ line ź³¼ ź°ėė” sorting
#get direction of pt
vecNewLine = gridLine.Direction # direction to pt[0] to pt[1]
vecPrevLine = curveG.Direction
if abs(vecNewLine.AngleTo(vecPrevLine)) > 0.005:
gridLine = gridLine.CreateReversed()
return gridLine
toList = lambda x : x if isinstance(x, list) else [x]
lstView = toList(UnwrapElement(IN[0]))
offset_number = IN[1]
unit = doc.GetUnits()
lengthFormatId = unit.GetFormatOptions(SpecTypeId.Length).GetUnitTypeId()
TransactionManager.Instance.EnsureInTransaction(doc)
#
for activView in lstView:
activView.CropBoxVisible = True
doc.Regenerate()
#cropBox = activView.CropBox
offset_number_conv = UnitUtils.ConvertToInternalUnits(offset_number*activView.Scale, lengthFormatId)
fecMultiGrids_Ids = [id for m in FilteredElementCollector(doc).OfClass(MultiSegmentGrid).WhereElementIsNotElementType() for id in m.GetGridIds()]
fecGrids = FilteredElementCollector(doc, activView.Id).OfClass(DatumPlane).ToElements()
cutOffset = fecGrids[0].GetCurvesInView(DatumExtentType.ViewSpecific, activView)[0].GetEndPoint(0).Z
fecGrids = [x for x in fecGrids if isinstance(x, DB.Grid) and x.Id not in fecMultiGrids_Ids] # MultiSegment Gridė„¼ filtering
levels = FilteredElementCollector(doc, activView.Id).OfClass(Level).WhereElementIsNotElementType().ToElements()
shpManager = activView.GetCropRegionShapeManager()
boundLines = shpManager.GetCropShape()[0]
boundLines = CurveLoop.CreateViaOffset(boundLines, offset_number_conv, activView.ViewDirection.Negate())
if activView.ViewDirection.IsAlmostEqualTo(XYZ(0,0,1)):
# for plan
# get Current Elevation of boundLines
currentZ = list(boundLines)[0].GetEndPoint(0).Z
# transform boundLines CurveLoop
tf = Transform.CreateTranslation(XYZ(0,0, cutOffset - currentZ))
boundLines = CurveLoop.CreateViaTransform(boundLines, tf)
for grid in fecGrids:
newGLine = createDatumLine(boundLines, grid.GetCurvesInView(DatumExtentType.ViewSpecific, activView)[0])
if newGLine is not None:
grid.SetCurveInView(DatumExtentType.ViewSpecific, activView, newGLine)
else:
# for elevation
for grid in fecGrids:
newGLine = createDatumLine(boundLines, grid.GetCurvesInView(DatumExtentType.ViewSpecific, activView)[0])
if newGLine is not None:
grid.SetCurveInView(DatumExtentType.ViewSpecific, activView, newGLine)
for level in levels:
newLevLine = createDatumLine(boundLines, level.GetCurvesInView(DatumExtentType.ViewSpecific, activView)[0])
if newLevLine is not None:
level.SetCurveInView(DatumExtentType.ViewSpecific, activView, newLevLine)
TransactionManager.Instance.TransactionTaskDone()
OUT = lstView
@Yong-sung.choi i recent saw a video ( [Dynamo Test]Pre-cast Structure element Modeling (V1) - YouTube) i would like to know with you culd share this routine. thanks