@piac @AndersDeleuran @diff-arch
I have tried different ways of compiling it, this one is the last one. The Python code is working but after compiling (after making the plugin) the list of values returning are zeros. The code is done for view analysis. Is it because i used ghcomp?
"""Provides percentage of visibility to the surface from the road.
Inputs:
site_brep: input the site brep geometry
vantage: input brep or geometry to watch
analysisgridsize: inut analysis grid size (a number)
vis_dis: input visibility distance (a number)
pointstopdistance: input the distance between the viewers alighing on path (a number)
context: input any obstacles as brep or geometry representing buildings or any
road: inut curve/s depicting the road or passage to mark the vantage points
Output:
viewPerc: Get the percentage of visibility from the road
vbreps: Get the analysis grid brep
eyepts: Get viewing points along the path
eyeViewPerc: Get the percentage of view received by the viewer of the vantage
disEyeViewPerc: Get the display circle geometry representing the percetage of views enjoyed to the vantage from path """
from ghpythonlib.componentbase import executingcomponent as component
import Grasshopper, GhPython
import System
import Rhino as r
import rhinoscriptsyntax as rs
import Rhino.Geometry as rg
import scriptcontext as sc
import Grasshopper as gh
import ghpythonlib.components as ghcomp
import math
__author__ = "VIJESH"
__version__ = "2023.06.04"
def contextBrep(site_brep, vantage, context):
contextbrep = []
contextbrep.append(site_brep)
for i in range(len(vantage)):
contextbrep.append(vantage[i])
if context:
for j in range(len(context)):
contextbrep.append(context[j])
return contextbrep
def eyePts(road, pointstopdistance):
pts = []
for i in range(len(road)):
pt = ghcomp.DivideDistance(road[i], pointstopdistance)[0] #at 1m distance between view pts from road
for j in range(len(pt)):
pts.append(pt[j])
eyepts = ghcomp.Move(pts, rg.Vector3d(0,0,1.63))[0]
return eyepts
def vantagePoints(vantage, ags):
pts = []
breps = []
vbreps = []
for i in range(len(vantage)):
brep = ghcomp.DeconstructBrep(vantage[i])[0]
for j in range(len(brep)):
breps.append(brep[j])
for j in range(len(breps)):
g = ghcomp.Dimensions(breps[j])
gx = math.ceil(g[0]/ags)
gy = math.ceil(g[1]/ags)
D = ghcomp.DivideDomain2(breps[j], gx,gy)
sbreps = ghcomp.Isotrim(breps[j], D)
for k in range(len(sbreps)):
vbreps.append(sbreps[k])
vpts = ghcomp.Area(vbreps)[1]
return vbreps, vpts
def evCount(vbreps, eyepts, vpts, vis_dis, contextbrep):
ecount = [0 for i in range(0,len(eyepts))]
vcount = [0 for i in range(0,len(vpts))]
degs = []
for i in range(len(vbreps)):
ln = ghcomp.Line(eyepts, vpts[i])
erpts = ghcomp.IsoVistRay(ln, vis_dis, contextbrep)[0] #end ray points
for j in range(len(eyepts)):
bt = rg.Brep.ClosestPoint(vbreps[i],erpts[j],0.001)[0]
angle = (rg.Vector3d.VectorAngle(rg.Vector3d.ZAxis, ln[j].Direction))*180/math.pi
if 0<angle<180:
if bt:
vcount[i] = vcount[i] + 1
ecount[j] = ecount[j] + 1
return vcount, ecount
def vpRun(eyepts, vbreps, vcount, ecount):
viewPerc = []
eyeViewPerc = []
disEyeViewPerc = []
neye = len(eyepts)
nvbreps = len(vbreps)
for m in range(len(vcount)):
viewPerc.append(vcount[m]/neye)
for n in range(len(ecount)):
eyeViewPerc.append(ecount[n]/nvbreps)
disEyeViewPerc.append(rg.Circle(eyepts[n],eyeViewPerc[n]))
return viewPerc, eyeViewPerc, disEyeViewPerc
contextbrep = contextBrep(site_brep, vantage, context)
eyepts = eyePts(road, pointstopdistance)
vbreps, vpts = vantagePoints(vantage, analysisgridsize)
vcount, ecount = evCount(vbreps, eyepts, vpts, vis_dis, contextbrep)
viewPerc, eyeViewPerc, disEyeViewPerc = vpRun(eyepts, vbreps, vcount, ecount)
Thank in advance.
Vijesh