0 return value after compiling it in the GHPython

hi @piac

Am trying to develop a plugin using Python code. I was able to successfully deploy ArchEval. In the current plugin I am developing using python is returning the value and working properly as desired, but after compiling it am getting values as 0 (check with ViewPerc). Files are attached for your reference. it is actually a working a file, eventhough I am sharing it here.

ErrorReturning.gh (34.3 KB)

Thanks in advance.

The python code is working properly, but after compiling it am getting 0 values. I tried doing it in other ways but the error persists. Any thread on this kind of error on compiling?

Thanks in advance.

@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

I haven’t experimented with compiling GHPython components much, but using ghpythonlib.components and rhinoscriptsyntax have certainly been known to cause issues that may be avoided be using RhinoCommon directly. I’d give that a go and see what happens :eyes:

I also haven’t tried compiling GHPython components yet. It at least used to be not possible to do this on macOS and on Windows compiled components also used to not work here. I don’t know about the current situation.
If code obfuscation is your goal, I wouldn’t bother since decompiling is rather easy.

Right. I will try that right away and get back. Thank you @AndersDeleuran @diff-arch .

1 Like

I have tried but in vain. Please check where the error is,

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
import random

__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 = []
    eyepts = []
    for i in range(len(road)):
        t = rg.Curve.DivideByLength(road[i], pointstopdistance, True)
        for j in range(len(t)):
            pts.append(rg.Curve.PointAtLength(road[i],t[j]))
    for k in range(len(pts)):
        eyepts.append(pts[k] + rg.Vector3d(0,0,1.63))
    return eyepts

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))]
    
    erpts = []
    for i in range(len(vbreps)):
        erpts = []
        dirv = []
        for p in range(len(eyepts)):
            dirv.append(rg.Vector3d(vpts[i] - eyepts[p]))
            ray= rg.Ray3d(eyepts[p], dirv[len(dirv)-1])
            pt = rg.Intersect.Intersection.RayShoot(ray, contextbrep, 1)
            erpts.append(pt[0])
        for j in range(len(eyepts)):
            try:
                bt = rg.Brep.ClosestPoint(vbreps[i],erpts[j],0.001)[0]
                angle = (rg.Vector3d.VectorAngle(rg.Vector3d.ZAxis, dirv[j]))*180/math.pi
                if 30<angle<165:
                    if bt:
                        vcount[i] = vcount[i] + 1
                        ecount[j] = ecount[j] + 1
            except:
                pass
        
    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)
vcount, ecount = evCount(vbreps, eyepts, vpts, vis_dis, contextbrep)
viewPerc, eyeViewPerc, disEyeViewPerc = vpRun(eyepts, vbreps, vcount, ecount)

Requesting help

Finally i found where the error is lying. it is in the below code block, which I segregated from the above.

def vpRun(eyepts, vbreps, vcount, ecount):
            neye = len(eyepts)
            nvbreps = len(vbreps)
            
            vp =[]
            evp = []
            devp = []
            
            for m in range(len(vcount)):
                vp.append(vcount[m]/neye)
            
            for n in range(len(ecount)):
                evp.append(ecount[n]/nvbreps)
                devp.append(rg.Circle(eyepts[n],evp[n]))
            return vp, evp, devp
        
        viewPerc, eyeViewPerc, disEyeViewPerc = vpRun(eyepts, vbreps, vcount, ecount)

The output look like this,


I am getting invalid circles after compiling it, all other values as zero.

requesting for help.

I have tried again and failed to understand where the error is, he is the definition and GH file. Looking forward to get a hand in solving and understanding the real problem.

@eirannejad @diff-arch @AndersDeleuran @piac any thoughts to go forward?

ErrorWhileCompiling.gh (13.1 KB)
GhPythonScript_cd240c34c8db431295c78733989c84a4t_DEL105.ghpy (30 KB)