Skip to content

Commit

Permalink
v0.0.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Malcolm authored and Chris Malcolm committed Apr 14, 2017
1 parent 90dc6ad commit 55cbc40
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 37 deletions.
54 changes: 35 additions & 19 deletions DYNAMO/170207_renumber_views_on_sheet.dyn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Workspace Version="1.2.1.3083" X="-115.063747564348" Y="204.739231343081" zoom="0.857942222587846" Name="Home" Description="" RunType="Automatic" RunPeriod="1000" HasRunWithoutCrash="True">
<Workspace Version="1.3.0.875" X="-154.490417458428" Y="272.745465281981" zoom="0.910486800477928" ScaleFactor="1" Name="Home" Description="" RunType="Manual" RunPeriod="1000" HasRunWithoutCrash="True">
<NamespaceResolutionMap />
<Elements>
<PythonNodeModels.PythonNode guid="499e624a-dab1-4b0a-bb15-cadd1d30cad0" type="PythonNodeModels.PythonNode" nickname="Python Script" x="465.25857884504" y="158.021666897352" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="False" IsFrozen="false" isPinned="false" inputcount="1">
<PythonNodeModels.PythonNode guid="499e624a-dab1-4b0a-bb15-cadd1d30cad0" type="PythonNodeModels.PythonNode" nickname="Python Script" x="490.264369246434" y="-17.0188659123992" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="False" IsFrozen="false" isPinned="false" inputcount="1">
<PortInfo index="0" default="False" />
<Script># these commands get executed in the current scope

Expand Down Expand Up @@ -222,6 +222,11 @@ def getNewDetailViewNumber(pts,offsetX, offsetY, stepX, stepY,gridPtsDic):
"newPtsPts":newPtsPts
}

#ensure the bounds are always top left to bottom right
def fixBoundsLine(MIN, MAX):
firstPt = XYZ(min(MIN.X,MAX.X), max(MIN.Y,MAX.Y),0)
secondPt = XYZ(max(MIN.X,MAX.X), min(MIN.Y,MAX.Y),0)
return (firstPt,secondPt)

def getDataFromTitleBlock():
global SHEET
Expand All @@ -245,9 +250,12 @@ def getDataFromTitleBlock():

if retData['detailGrid_bounds']==None:
retData['detailGrid_bounds'] = getParam(tb, "detailGrid_bounds")

#parse bouunds
boundOffsets = None
if retData['detailGrid_matrix']==None:
retData['detailGrid_matrix'] = getParam(tb, "detailGrid_matrix")

#parse bouunds
boundOffsets = None
if retData['detailGrid_bounds'] != None:
if json is not None:
try:
boundsOffsets = json.loads(retData['detailGrid_bounds'])
Expand All @@ -261,15 +269,15 @@ def getDataFromTitleBlock():
if boundsOffsets is not None:
retData["detailGrid_endPts"] = [ [bb.Min.X+boundsOffsets[0][0],bb.Max.Y-boundsOffsets[0][1],0],[bb.Max.X-boundsOffsets[1][0],bb.Min.Y+boundsOffsets[1][1],0]]

#parse matrix
if retData['detailGrid_matrix']==None:
if json is not None:
try:
retData['detailGrid_matrix'] = json.loads(getParam(tb, "detailGrid_matrix"))
except:
log(["error when parsing detailGrid_matrix from titleblock..invalid json?",e])
else:
retData['detailGrid_matrix'] = parseMatrixWithoutJSON(getParam(tb, "detailGrid_matrix"))
#parse matrix
if retData['detailGrid_matrix'] !=None:
if json is not None:
try:
retData['detailGrid_matrix'] = json.loads(retData['detailGrid_matrix'])
except:
log(["error when parsing detailGrid_matrix from titleblock..invalid json?",e])
else:
retData['detailGrid_matrix'] = parseMatrixWithoutJSON(retData['detailGrid_matrix'])


log(["detailGrid data found from title block:",retData])
Expand Down Expand Up @@ -331,8 +339,11 @@ def getPtGrid():
#else we can ask for user to select diagonal bounds line
bbCrvRef = pickObject()
bbCrv = elementFromReference(bbCrvRef).GeometryCurve
startPt = bbCrv.GetEndPoint(0)
endPt = bbCrv.GetEndPoint(1)
#fix the diagonal line
endPts = fixBoundsLine(bbCrv.GetEndPoint(0),bbCrv.GetEndPoint(1))
startPt = endPts[0]
endPt = endPts[1]

log("drawnLineCrv:",[startPt,endPt])


Expand Down Expand Up @@ -369,7 +380,7 @@ def getPtGrid():
"stepX": stepX,
"stepY": stepY
}

def getDetailNumFromPt(pt,gridPtsDic):
return gridPtsDic[",".join(map(lambda x: str(x), pt))]

Expand Down Expand Up @@ -431,7 +442,10 @@ def getBuiltInParam(el, builtInParamEnum, asParamObject=False):

def getParam(el, paramName, asParamObject=False):
params = getParameters(el, asParamObject)
return params[paramName]
if paramName in params:
return params[paramName]
else:
return None


def merge_two_dicts(x, y):
Expand Down Expand Up @@ -496,7 +510,9 @@ def highlightDuplicates(pts):
createDetailLine(pt, [pt[0]+100,pt[1]+100,0])

def pickObject():
TaskDialog.Show ("Select Bounds Line", "Select the diagonal line (drawn from top left to bottom right) representing the grid bounds after closing this dialog.")

#__window__.Hide()
TaskDialog.Show ("Select Bounds Line", "Select the diagonal line representing the grid bounds after closing this dialog.")
picked = uidoc.Selection.PickObject(ObjectType.Element)
#__window__.Topmost = True
#__window__.Show()
Expand Down
63 changes: 45 additions & 18 deletions REVIT PYTHON SHELL/170217_renumber_views_on_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

#constants
LOGFILE = "T:\Malcolm-Chris\REVIT\PYTHON REVIT SHELL\log.txt"
LOG_ACTIVE = False
LOG_ACTIVE = False

def log(textArr,is_raw=False):
global LOGFILE,LOG_ACTIVE
Expand Down Expand Up @@ -170,6 +170,12 @@ def getNewDetailViewNumber(pts,offsetX, offsetY, stepX, stepY,gridPtsDic):
"newPtsPts":newPtsPts
}

#ensure the bounds are always top left to bottom right
def fixBoundsLine(MIN, MAX):
firstPt = XYZ(min(MIN.X,MAX.X), max(MIN.Y,MAX.Y),0)
secondPt = XYZ(max(MIN.X,MAX.X), min(MIN.Y,MAX.Y),0)
return (firstPt,secondPt)


def getDataFromTitleBlock():
global SHEET
Expand All @@ -193,19 +199,35 @@ def getDataFromTitleBlock():

if retData['detailGrid_bounds']==None:
retData['detailGrid_bounds'] = getParam(tb, "detailGrid_bounds")
try:
boundsOffsets = json.loads(retData['detailGrid_bounds'])
log(["json data from bounds:",boundsOffsets])
retData["detailGrid_endPts"] = [ [bb.Min.X+boundsOffsets[0][0],bb.Max.Y-boundsOffsets[0][1],0],[bb.Max.X-boundsOffsets[1][0],bb.Min.Y+boundsOffsets[1][1],0]]
#createDetailLine(retData["detailGrid_endPts"][0], retData["detailGrid_endPts"][1])
except:
log(["error when parsing detailGrid_bounds from titleblock..invalid json?"])
if retData['detailGrid_matrix']==None:
try:
retData['detailGrid_matrix'] = getParam(tb, "detailGrid_matrix")

#parse bouunds
boundOffsets = None
if retData['detailGrid_bounds'] != None:
if json is not None:
try:
boundsOffsets = json.loads(retData['detailGrid_bounds'])
retData['detailGrid_matrix'] = json.loads(getParam(tb, "detailGrid_matrix"))
except:
log(["error when parsing detailGrid_matrix from titleblock..invalid json?"])
log(["json data from bounds:",boundsOffsets])
except:
log(["error when parsing detailGrid_bounds from titleblock..invalid json?"])
else:
boundsOffsets = parseBoundsWithoutJSON(retData['detailGrid_bounds'])


if boundsOffsets is not None:
retData["detailGrid_endPts"] = [ [bb.Min.X+boundsOffsets[0][0],bb.Max.Y-boundsOffsets[0][1],0],[bb.Max.X-boundsOffsets[1][0],bb.Min.Y+boundsOffsets[1][1],0]]

#parse matrix
if retData['detailGrid_matrix'] !=None:
if json is not None:
try:
retData['detailGrid_matrix'] = json.loads(retData['detailGrid_matrix'])
except:
log(["error when parsing detailGrid_matrix from titleblock..invalid json?",e])
else:
retData['detailGrid_matrix'] = parseMatrixWithoutJSON(retData['detailGrid_matrix'])


log(["detailGrid data found from title block:",retData])
return retData
Expand All @@ -228,8 +250,11 @@ def getPtGrid():
#else we can ask for user to select diagonal bounds line
bbCrvRef = pickObject()
bbCrv = elementFromReference(bbCrvRef).GeometryCurve
startPt = bbCrv.GetEndPoint(0)
endPt = bbCrv.GetEndPoint(1)
#fix the diagonal line
endPts = fixBoundsLine(bbCrv.GetEndPoint(0),bbCrv.GetEndPoint(1))
startPt = endPts[0]
endPt = endPts[1]

log("drawnLineCrv:",[startPt,endPt])


Expand Down Expand Up @@ -329,8 +354,10 @@ def getBuiltInParam(el, builtInParamEnum, asParamObject=False):

def getParam(el, paramName, asParamObject=False):
params = getParameters(el, asParamObject)
#log(["params for ",el," :",params])
return params[paramName]
if paramName in params:
return params[paramName]
else:
return None

def merge_two_dicts(x, y):
"""Given two dicts, merge them into a new dict as a shallow copy."""
Expand Down Expand Up @@ -380,11 +407,11 @@ def createDetailLine(pt1, pt2):
doc.Create.NewDetailCurve(SHEET, geomLine)

def getPointsFromViewports(viewport):
outline = viewport.GetBoxOutline()
outline = viewport.GetLabelOutline()
PT = [outline.MaximumPoint.X,outline.MinimumPoint.Y,0]
#createDetailLine(outline.MaximumPoint, outline.MinimumPoint)
return PT

def highlightDuplicates(pts):
if (len(pts)>0):
TaskDialog.Show ("Views share same cell", "Success! But "+str(len(pts))+" view(s) shared the same cell, they have been highlighted with a line for you to double check.")
Expand Down

0 comments on commit 55cbc40

Please sign in to comment.