Resize Elevation Crop Region

Resize Elevation Crop Region

inouizi
Participant Participant
1,046 Views
3 Replies
Message 1 of 4

Resize Elevation Crop Region

inouizi
Participant
Participant

Hello,

Apologies if the format of the post is not up to standards or if the topic has already been addressed somewhere.

I did do a lot of searches both here and on The Building Coder pages and couldn't find a solution or an explanation.

I am not really sure how to ask this but here it goes:

 

I want to be able to resize the elevation crop region based on locations of grids and levels on the view. 

I seem to make the south/north elevations (elev-A) work pretty well, but I am not able to make the east elevation (elev-B) work.

 

plan.jpg

elev-A

elev-A.jpg

elev-B

elev-B.jpg

 

 

 

For elev-B, I end up with a 1' long crop region. The top and bottom are correct but the left and right extents are not.

 

This is the python code I am using on the elev-A which is working perfectly:

-----------------------------------------------------------------------------------------

aview = doc.ActiveView                                    

#find visible grids on current view
gridsonview = []
for g in grids:
    if g.CanBeVisibleInView(aview):
        gridsonview.append(g)
                                            
cborg = aview.CropBox.Transform.Origin

if aview.ViewDirection.Y == -1:
    #find grid x coordinates
    gridmins = [gm.GetCurvesInView(DB.DatumExtentType.Model, aview)[0] \
                                    .GetEndPoint(0).X for gm in gridsonview]
    gridsbymmin = dict(zip(gridmins, gridsonview))
    #grids on view ordered by coordinates
    sorted = [gridsbymmin[vminvalue] for vminvalue in sorted(gridmins)]

    tz = Transaction(doc, "South facing view crop box")
    tz.Start()

    aview.CropBoxActive = False

    #left grid X
    lgx = sorted[0].GetCurvesInView(DB.DatumExtentType.Model, aview)[0] \
                    .GetEndPoint(0)
    
    #right grid X
    rgx = sorted[-1].GetCurvesInView(DB.DatumExtentType.Model, aview)[0] \
                    .GetEndPoint(0)
    
    #grid top Z
    tgy = sorted[0].GetCurvesInView(DB.DatumExtentType.Model, aview)[0] \
                    .GetEndPoint(1)
    
    #grid bottom Z
    bgy = sorted[0].GetCurvesInView(DB.DatumExtentType.Model, aview)[0] \
                    .GetEndPoint(0)
    

    min = XYZ(lgx.X - cborg.X - offset, bgy.Z - cborg.Z - 1, 0)
    

    max = XYZ(rgx.X - cborg.X + offset, tgy.Z - cborg.Z + 1 + (bubblesize * aview.Scale), 0)
    

    nsb = BoundingBoxXYZ()
    nsb.Min = min
    nsb.Max = max

    aview.CropBox = nsb
    aview.CropBoxVisible = True
    aview.CropBoxActive = True

    tz.Commit()

-----------------------------------------------------------------------------------------

With this logic.. what should the nsb BoundingBox coordinates be for elev-B so that I get the correct crop region?

 

Thank you in advance! 

0 Likes
1,047 Views
3 Replies
Replies (3)
Message 2 of 4

inouizi
Participant
Participant

no takers? 😞

0 Likes
Message 3 of 4

mhannonQ65N2
Collaborator
Collaborator

Have you tried replacing 'X' with 'Y' for elevation B?

0 Likes
Message 4 of 4

inouizi
Participant
Participant

Yes I did @mhannonQ65N2 , that didn't work.

What did work, is using ViewCropRegionShapeManager

https://www.revitapidocs.com/2019/2610cb66-5dae-9fc8-4e83-7dfe88085abb.htm

 

Still wrapping my head around it, but I think I'm starting to see the light at the end of the tunnel! 

 

Thanks! 

0 Likes