Set Grid Extents and Bubbles

I got it, using weird names and for sure not the cleanest way:

image

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/

1 Like

Thanks Jacob, this is very helpfull and now i know what this is about :slight_smile:
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:

  1. 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?

  1. 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.
2 Likes

@gerhard.p Fantastic work! Learning so much just reading this thread. Thanks

2 Likes

please look at this topic , i am stuck in this
https://forum.dynamobim.com/t/set-grids-design/82060/4

Thanks

@gerhard.p Hi, I tried your python script and it worked well except one case which is if the grids donā€™t cross the crop region (as shown in the screenshot). Can you have me with this case?

Hello @Luffy11 :slight_smile:
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 Hi, yes the code will not work if the grids are out of the crop box (like the grids in red marked area I showed in the above screenshot). It will work with this case as shown in the image below (one side of the grids cross the crop box).

@gerhard.p @c.poupin Thanks a lot. With your help, I can make a code.


04.View&Dimension 20230324.dyn (155.7 KB)

3 Likes

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