示例#1
0
def link_method_ifc():
    files_filter = "IFC files (*.ifc)|*.ifc"
    files = pick_files(files_filter)
    for f in files:
        t = Transaction(doc)
        t.Start(__title__)
        f_cache = f + ".rvt"
        recreate = not os.path.exists(f_cache)
        logger.debug("Recreate ifc %s = %s" % (f, recreate))
        # try:
        o = RevitLinkOptions(False)
        # create empty doc
        if recreate:
            doc_ifc = HOST_APP.app.OpenIFCDocument(f)
            save_options = SaveAsOptions()
            save_options.OverwriteExistingFile = True
            doc_ifc.SaveAs(f_cache, save_options)
            doc_ifc.Close()

        link_load_results = RevitLinkType.CreateFromIFC(doc, f, f_cache, False, o)
        # TODO log results http://www.revitapidocs.com/2019/11b095e1-24d9-91b9-ae2e-004f67c94d6e.htm
        logger.debug(link_load_results.LoadResult)
        instance = RevitLinkInstance.Create(doc, link_load_results.ElementId)
        status = True
        # except Exception as e:
        #     logger.error("Unable to import IFC")
        #     logger.error(e)
        #     status = False
        #     instance = None

        if status:
            instance.Pinned = True
            t.Commit()
        else:
            t.RollBack()
示例#2
0
文件: script.py 项目: Melca-G/Aeolus
def SaveCloudModelandChangeName(document, filePath, Name):
    worksharingOptions = WorksharingSaveAsOptions()
    worksharingOptions.SaveAsCentral = True
    saveOpt = SaveAsOptions()
    saveOpt.SetWorksharingOptions(worksharingOptions)
    saveOpt.OverwriteExistingFile = True
    saveOpt.Compact = True
    document.SaveAs(filePath + Name + ".rvt", saveOpt)
    document.Close()
示例#3
0
def main():
    pile_width = int(ff.values['pile_width'])
    piles_along_length = int(ff.values['piles_along_length'])
    piles_along_width = int(ff.values['piles_along_width'])
    pile_spacing_along_length = float(ff.values['pile_spacing_along_length'])
    pile_spacing_along_width = float(ff.values['pile_spacing_along_width'])
    length_cover = float(ff.values['length_cover'])
    width_cover = float(ff.values['width_cover'])
    thickness = float(ff.values['thickness'])
    pile_cutoff = float(ff.values['pile_cutoff'])

    foundation = rpw.db.Element.from_id(ff.values['foundation_id'])
    pile = rpw.db.Element.from_id(ff.values['pile_id'])
    foundation_famdoc = doc.EditFamily(foundation.unwrap())
    pile_famdoc = doc.EditFamily(pile.unwrap())

    saveas_path = os.path.expanduser('~')
    save_options = SaveAsOptions()
    save_options.OverwriteExistingFile = True

    pile_famdoc.SaveAs(os.path.join(saveas_path, '{}'.format(pile_famdoc.Title)), save_options)

    with rpw.db.Transaction('Load pile into foundation', doc=foundation_famdoc):
        foundation_famdoc.LoadFamily(pile_famdoc.PathName)

    pile_famdoc.Close(False)

    with rpw.db.Transaction('Activate pile family symbol', doc=foundation_famdoc):
        pile_family_symbol = rpw.db.Collector(of_class='FamilySymbol',
                                              doc=foundation_famdoc,
                                              where=lambda x: x.FamilyName==pile.Name)[0]
        # http://thebuildingcoder.typepad.com/blog/2014/08/activate-your-family-symbol-before-using-it.html
        if not pile_family_symbol.IsActive:
            pile_family_symbol.Activate()

    ### Place piles
    first_x = -pile_spacing_along_length*(piles_along_length-1)/2
    first_y = -pile_spacing_along_width*(piles_along_width-1)/2
    z = pile_cutoff - thickness
    pile_locations = []
    for i in range(piles_along_length):
        for j in range(piles_along_width):
            x = first_x + i * pile_spacing_along_length
            y = first_y + j * pile_spacing_along_width
            pile_locations.append((x, y, z))
    with rpw.db.Transaction('Insert pile instances', doc=foundation_famdoc):
        for x, y, z in pile_locations:
            x = x / 304.8
            y = y / 304.8
            z = z / 304.8
            foundation_famdoc.FamilyCreate.NewFamilyInstance(rpw.DB.XYZ(x,y,z),
                                                            pile_family_symbol,
                                                            rpw.DB.Structure.StructuralType.NonStructural)

    created_piles = list(rpw.db.Collector(of_category='OST_StructuralFoundation',
                                        of_class='FamilyInstance',
                                        doc=foundation_famdoc))
    parameters = ['Number of pile segments', 'D', 'L1', 'L2', 'L3', 'L4', 'L5', 'L6', 'L7']
    for pile in created_piles:
        for param_name in parameters:
            associate_family_parameter(foundation_famdoc, pile, param_name)


    length_param = get_family_parameter(foundation_famdoc, 'Length')
    width_param = get_family_parameter(foundation_famdoc, 'Width')
    thickness_param = get_family_parameter(foundation_famdoc, 'Foundation Thickness')
    length = pile_spacing_along_length*(piles_along_length-1) + 2 * length_cover
    width = pile_spacing_along_length*(piles_along_width-1) + 2 * width_cover
    set_family_parameter_value(foundation_famdoc, length_param, length / 304.8)
    set_family_parameter_value(foundation_famdoc, width_param, width / 304.8)
    set_family_parameter_value(foundation_famdoc, thickness_param, thickness / 304.8)
    set_family_parameter_value(foundation_famdoc, get_family_parameter(foundation_famdoc, 'D'), pile_width/304.8)

    new_filename = ff.values['new_foundation_family_name'] or 'new_{}'.format(foundation_famdoc.Title)
    foundation_famdoc.SaveAs(os.path.join(saveas_path, '{}.rfa'.format(new_filename)),
                            save_options)
    foundation_rfa_path = foundation_famdoc.PathName
    foundation_famdoc.Close(False)

    rpw.ui.forms.Alert('Finished creating foundation, saved at {}'.format(foundation_rfa_path))
    os.startfile(foundation_rfa_path)
app = uiapp.Application

# argument assigned the IN port
new_projects = IN[0]  # list of new projects
template = IN[1]  # single template or list of templates

# wrap input inside a list (if not a list)
if not isinstance(new_projects, list):
    new_projects = [new_projects]

# instantiate error log
error_log = None

# save as options
option = SaveAsOptions()
option.OverwriteExistingFile = True


# single template definition
def single_template():
    for new_project in new_projects:
        t = app.NewProjectDocument(template)
        t.SaveAs(new_project, option)
        t.Close(False)


# multiple template definition
def multiple_template(xx=[]):
    for new_project, temp in zip(new_projects, template):
        new_projects.pop(0)
        template.pop(0)
        if filtered_params:
            trans = Transaction(family_doc, 'ChangeGroup')
            trans.Start()
            fam_report = []
            fam_report.append(family_doc.Title)

            for i in range(len(filtered_params)):
                parse_pg = parse_to_builtInParameterGroup(param_groups[i])
                MoveParameterToGroup(family_doc, filtered_params[i], parse_pg,
                                     "temp{}".format(i))
                fam_report.append("ОК. {} изменен".format(
                    filtered_params[i].Definition.Name))

            report.append(fam_report)
            trans.Commit()
            trans.Dispose()
        else:
            report.append("Нет таких параметров. Файл {}".format(
                family_doc.Title))

        optS = SaveAsOptions()
        optS.OverwriteExistingFile = True
        optS.Compact = True
        optS.MaximumBackups = 1
        family_doc.SaveAs(filepath, optS)
        family_doc.Close(False)

    OUT = report
else:
    OUT = "Нет такой директории"
    new_target_path = model_path + upgrade_suffix
    rvt_path = FilePath(model_path)
    rvt_model_path = ModelPathUtils.ConvertUserVisiblePathToModelPath(
        model_path)
    print("currently processing: {}".format(model_path))

    ws_conf = WorksetConfiguration(WorksetConfigurationOption.CloseAllWorksets)
    open_opt = OpenOptions()
    open_opt.Audit = True
    open_opt.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets
    open_opt.SetOpenWorksetsConfiguration(ws_conf)

    save_opt = SaveAsOptions()
    if os.path.exists(new_target_path):
        print("warning! overwriting: {}".format(new_target_path))
        save_opt.OverwriteExistingFile = True

    model_doc = app.OpenDocumentFile(rvt_path, open_opt)
    if model_doc.IsWorkshared:
        ws_opt = WorksharingSaveAsOptions()
        ws_opt.SaveAsCentral = True
        if TransmissionData.IsDocumentTransmitted(rvt_model_path):
            print("removing transmit   : {}".format(model_path))
            ws_opt.ClearTransmitted = True
        save_opt.SetWorksharingOptions(ws_opt)

    print("opened              : {}".format(model_path))
    model_doc.SaveAs(new_target_path, save_opt)
    print("saved as            : {}".format(new_target_path))
    model_doc.Close()
    print("closed")
# argument assigned the IN port
path = IN[0]
families = IN[1]
sub_folder = IN[2]
boolean = IN[3]

# wrap input inside a list (if not a list)
if not isinstance(families, list):
    families = [families]

# unwrap Dynamo elements
families = list(UnwrapElement(families))

# Overwrite option
overwrite = SaveAsOptions()
overwrite.OverwriteExistingFile = boolean

# Close all transactions
TransactionManager.Instance.ForceCloseTransaction()


# build paths
def path_builder(path, category, sub_folder):
    if sub_folder:
        new_path = path + '\\' + category
        Directory.CreateDirectory(new_path)
        return new_path
    else:
        return path