Exemple #1
0
 def addBrepOfSubsetOfFaces_RemoveAt():
     
     rgBrep1 = rgBrep_In.Duplicate()
     
     # Create list of non-extracted faces.
     # This is faster than looping through all faces while testing each.
     idx_rgFaces_ToRemove = list(
             set(range(rgBrep1.Faces.Count)) - set(idxFaces))
     idx_rgFaces_ToRemove.sort(reverse=True)
     
     stopwatch = Stopwatch()
     stopwatch.Start()
     [rgBrep1.Faces.RemoveAt(idx) for idx in idx_rgFaces_ToRemove]
     stopwatch.Stop()
     if bDebug: print "{} seconds for Faces.RemoveAt".format(stopwatch.Elapsed.TotalSeconds)
     
     # Separate any brep shells of modified brep and act based on shell quantity.
     stopwatch.Restart()
     rgBreps_per_shell = rg.Brep.CreateBooleanUnion(
         [rgBrep1], tolerance=0.0, manifoldOnly=False)
     stopwatch.Stop()
     if bDebug:
         print "{} seconds for CreateBooleanUnion".format(
             stopwatch.Elapsed.TotalSeconds)
     if rgBreps_per_shell is None:
         if bDebug: print "Error in attempting to separate brep shells.  No objects have been modified."
         return
     
     rgBrep1.Dispose()
     
     attr = rdBrep_In.Attributes.Duplicate()
     if not bRetainLayer: attr.LayerIndex = sc.doc.Layers.CurrentLayerIndex
     if not bRetainColor: attr.ColorSource = rd.ObjectColorSource.ColorFromLayer
     
     stopwatch.Restart()
     gBreps_1Shell = map(lambda x: sc.doc.Objects.AddBrep(x, attr), rgBreps_per_shell)
     stopwatch.Stop()
     if bDebug: print "{:.1f} seconds for AddBrep".format(stopwatch.Elapsed.TotalSeconds)
     map(lambda x: x.Dispose(), rgBreps_per_shell)
     
     return gBreps_1Shell
Exemple #2
0
log_data = [[time_stamp]]  # timeStamp

if "RVT_QC_PRJ" in os.environ:
    project = os.environ["RVT_QC_PRJ"]
    model_path = os.environ["RVT_QC_PATH"]
    log_dir = os.environ["RVT_LOG_PATH"]

    print('QC_DIR: {}'.format(qc_path))
    print('ROOT_DIR: {}'.format(root_dir))
    print('LOG_DIR: {}'.format(log_dir))
    print('COMMANDS_DIR: {}'.format(commands_dir))

    log_file = op.join(log_dir, project + ".csv")
    log_data = pull_stats(log_data, path, model_path)

    stopwatch.Stop()
    timespan = stopwatch.Elapsed

    # prepend the script run time
    run_time = [[str(timespan)]]
    run_time[0].extend(log_data[0])

    if not op.exists(log_file):
        with open(log_file, "w") as _log:
            _log.write(log_header)

    with open(log_file, "a") as csv_file:
        writer = csv.writer(csv_file, delimiter=';', lineterminator='\n')
        writer.writerows(run_time)

else:
Exemple #3
0
dfs0File = DfsFileFactory.DfsGenericOpen(infile)

# Read times and data
timer = Stopwatch()
timer.Start()
t = []
data = []
for ii in xrange(dfs0File.ItemInfo.Count):
    data.append([])
for it in xrange(dfs0File.FileInfo.TimeAxis.NumberOfTimeSteps):
    for ii in xrange(dfs0File.ItemInfo.Count):
        itemData = dfs0File.ReadItemTimeStep(ii + 1, it)
        if (ii == 0):
            t.append(itemData.Time)
        data[ii].append(itemData.Data[0])
timer.Stop()

dfs0File.Close()

print "Did app. {0} .NET calls per second".format(
    dfs0File.FileInfo.TimeAxis.NumberOfTimeSteps *
    (2 * dfs0File.ItemInfo.Count + 1) / timer.Elapsed.TotalSeconds)

# Calculate average
av = []
for ii in xrange(dfs0File.ItemInfo.Count):
    sum = 0
    for it in xrange(dfs0File.FileInfo.TimeAxis.NumberOfTimeSteps):
        sum = sum + data[ii][it]
    av.append(sum / dfs0File.FileInfo.TimeAxis.NumberOfTimeSteps)
Exemple #4
0

def F():
    a, b = 0, 1
    yield a
    yield b
    while True:
        a, b = b, a + b
        yield b


if __name__ == '__main__':

    sw = Stopwatch()

    fib_calc = Fib()
    f = F()

    sw.Start()
    print fib_calc(18)
    sw.Stop()

    time_taken = sw.ElapsedMilliseconds
    print time_taken

    sw.Start()
    print[f.next() for i in xrange(18)]
    sw.Stop()

    print sw.ElapsedMilliseconds
Exemple #5
0
def addFromSubsetOfFaces(rhBrep, idxFaces, bAddOnlyMonofaces=True, bRetainLayer=True, bRetainColor=True, bDebug=False):
    """
    """
    
    rdBrep_In = coerceBrepObject(rhBrep)
    if rdBrep_In is None: return
    rgBrep_In = rdBrep_In.BrepGeometry
    if not rgBrep_In.IsValid: return
    
    
    def addBrepOfSubsetOfFaces_JoinBreps():
        
        # Duplicate faces to their own breps to be joined.
        rgBreps1 = [] # Faces (breps) to be duplicated.
        
        for i in idxFaces:
            rgFace = rgBrep_In.Faces[i]
            rgBrep_1Face = rgFace.DuplicateFace(True)
            if rgBrep_1Face is None:
                if bDebug: print "Face {} could not be duplicated as a brep!".format(i)
                return None
            rgBreps1.append(rgBrep_1Face)
        
        # Join monoface breps.

        # Using a tight tolerance to rejoin only existing shared edges.
        fTol_Join = 1e-9

        rgBreps_Joined = rg.Brep.JoinBreps(rgBreps1, tolerance=fTol_Join)
        if rgBreps_Joined is None:
                if bDebug: print "Joining breps failed!"
                return
        for rgB in rgBreps_Joined:
            if not rgB.IsValid:
                if bDebug: print "Joined brep not valid.  Exiting..."
                return
        
        if any(b.Faces.Count > 1 for b in rgBreps_Joined):
            # Separate any brep shells of modified brep and act based on shell quantity.
            rgBreps_per_shell = rg.Brep.CreateBooleanUnion(
                rgBreps_Joined, tolerance=0.0, manifoldOnly=False)
            if rgBreps_per_shell is None:
                if bDebug: print "Error in attempting to separate brep shells.  No objects have been modified."
                return
        else:
            # Skipped attempting to Boolean union monoface breps in case any contact are in contact with one another.
            rgBreps_per_shell = rgBreps_Joined[:]
        
        
        attr = rdBrep_In.Attributes.Duplicate()
        if not bRetainLayer: attr.LayerIndex = sc.doc.Layers.CurrentLayerIndex
        if not bRetainColor: attr.ColorSource = rd.ObjectColorSource.ColorFromLayer
        
        
        gBreps_1Shell = map(lambda x: sc.doc.Objects.AddBrep(x, attr), rgBreps_per_shell)
        map(lambda x: x.Dispose(), rgBreps_per_shell)
        
        return gBreps_1Shell
    
    
    def addBrepOfSubsetOfFaces_RemoveAt():
        
        rgBrep1 = rgBrep_In.Duplicate()
        
        # Create list of non-extracted faces.
        # This is faster than looping through all faces while testing each.
        idx_rgFaces_ToRemove = list(
                set(range(rgBrep1.Faces.Count)) - set(idxFaces))
        idx_rgFaces_ToRemove.sort(reverse=True)
        
        stopwatch = Stopwatch()
        stopwatch.Start()
        [rgBrep1.Faces.RemoveAt(idx) for idx in idx_rgFaces_ToRemove]
        stopwatch.Stop()
        if bDebug: print "{} seconds for Faces.RemoveAt".format(stopwatch.Elapsed.TotalSeconds)
        
        # Separate any brep shells of modified brep and act based on shell quantity.
        stopwatch.Restart()
        rgBreps_per_shell = rg.Brep.CreateBooleanUnion(
            [rgBrep1], tolerance=0.0, manifoldOnly=False)
        stopwatch.Stop()
        if bDebug:
            print "{} seconds for CreateBooleanUnion".format(
                stopwatch.Elapsed.TotalSeconds)
        if rgBreps_per_shell is None:
            if bDebug: print "Error in attempting to separate brep shells.  No objects have been modified."
            return
        
        rgBrep1.Dispose()
        
        attr = rdBrep_In.Attributes.Duplicate()
        if not bRetainLayer: attr.LayerIndex = sc.doc.Layers.CurrentLayerIndex
        if not bRetainColor: attr.ColorSource = rd.ObjectColorSource.ColorFromLayer
        
        stopwatch.Restart()
        gBreps_1Shell = map(lambda x: sc.doc.Objects.AddBrep(x, attr), rgBreps_per_shell)
        stopwatch.Stop()
        if bDebug: print "{:.1f} seconds for AddBrep".format(stopwatch.Elapsed.TotalSeconds)
        map(lambda x: x.Dispose(), rgBreps_per_shell)
        
        return gBreps_1Shell
    
    
    nFaces = rgBrep_In.Faces.Count
    
    # If brep has only 1 face, return the brep's GUID.
    if nFaces == 1:
        return [rdBrep_In.Id]
    
    idxFaces = list(set(idxFaces))
    
    if not bAddOnlyMonofaces:
        
        stopwatch = Stopwatch()
        
        # Create brep(s) of extracted faces using method chosen by whether number of
        # extracted faces is less or more than the remaining number of faces.
        if len(idxFaces) < nFaces // 2 :
            stopwatch.Restart()
            gBreps1_Extracted = addBrepOfSubsetOfFaces_JoinBreps()
            stopwatch.Stop()
            if bDebug:
                print "{} seconds for addBrepOfSubsetOfFaces_JoinBreps".format(
                        stopwatch.Elapsed.TotalSeconds)
            if gBreps1_Extracted is not None:
                return gBreps1_Extracted
            if bDebug: print "addBrepOfSubsetOfFaces_JoinBreps returned None."
        # Since addBrepOfSubsetOfFaces_JoinBreps failed, will try RemoveAt instead.
        
        # Either the number of faces to add > half the total number of faces in the brep or addBrepOfSubsetOfFaces_JoinBreps had returned None.
        stopwatch.Restart()
        gBreps1_Extracted = addBrepOfSubsetOfFaces_RemoveAt()
        stopwatch.Stop()
        if bDebug:
            print "{} seconds for addBrepOfSubsetOfFaces_RemoveAt".format(
                    stopwatch.Elapsed.TotalSeconds)
        if gBreps1_Extracted is not None:
            return gBreps1_Extracted
        if bDebug: print "addBrepOfSubsetOfFaces_RemoveAt returned None."
    
    # Add only monoface breps.
    
    attr = rdBrep_In.Attributes.Duplicate()
    if not bRetainLayer: attr.LayerIndex = sc.doc.Layers.CurrentLayerIndex
    if not bRetainColor: attr.ColorSource = rd.ObjectColorSource.ColorFromLayer
    
    gBreps1_Extracted = []
    
    for idx in idxFaces:
        rgFace = rgBrep_In.Faces[idx]
        
        # Duplicate face to its own brep.
        rgBrep1 = rgFace.DuplicateFace(duplicateMeshes=True)
        if not rgBrep1.IsValid:
            gBrep1 = None
        else:
            gBrep1 = sc.doc.Objects.AddBrep(rgBrep1, attr)

        if gBrep1 is None:
            s = "Brep face {} from {} could not be added to document.".format(
                    idx, rdBrep_In.Id)
            print s
            rc = rs.MessageBox(
                s + "\nContinue extracting faces, skipping this one?",
                buttons=4,
                title="xBrepObject.addFromSubsetOfFaces")
            if rc is not None and rc == 6:
                continue
            #if not bDebug: rs.DeleteObjects(gBreps1_Extracted)
            return
        
        gBreps1_Extracted.append(gBrep1)
        rgBrep1.Dispose()
    
    return gBreps1_Extracted