Create Grid from Auto cad

from pyrevit import revit, DB
from Autodesk.Revit.DB import ImportInstance, Options, Line

# Get the active document and user interface document
uidoc = revit.uidoc
doc = revit.doc

# Get the active view (where detail lines will be created)
active_view = doc.ActiveView

# Get all ImportInstance elements (CAD links) in the project
CAD_links = DB.FilteredElementCollector(doc).OfClass(ImportInstance).ToElements()

# Initialize an empty set to store layer names
layer_names = set()

# Initialize a counter for bound curves
bound_curve_count = 0

# Start a transaction to modify the Revit document
t = DB.Transaction(doc, "Create Detail Lines from CAD Curves")
t.Start()

# Iterate through all the CAD links
for link in CAD_links:
    link_cat = link.Category
    link_sub_cats = link_cat.SubCategories

    # Iterate through all the subcategories
    for sub_cat in link_sub_cats:
        options = Options()
        options.IncludeNonVisibleObjects = False  # Exclude non-visible objects if needed

        # Check if the subcategory name matches "Grid" (adjust as needed)
        if "Grid" in sub_cat.Name:
        
            # Get the geometry of the subcategory
            geometry = link.get_Geometry(options)

            # Add the subcategory name to the set
            layer_names.add(sub_cat.Name)

            # Iterate through the geometry objects
            if geometry is not None:
                for geom_obj in geometry:
                    # If geometry is a GeometryInstance (symbol)
                    if isinstance(geom_obj, DB.GeometryInstance):
                        instance_geometry = geom_obj.GetSymbolGeometry()
                        for inst_geom_obj in instance_geometry:
                            if isinstance(inst_geom_obj, DB.Curve):
                                # Skip unbound curves
                                if inst_geom_obj.IsBound:
                                    
                                
                                    # Create a Revit detail line from the curve in the active view
                                    detail_line = doc.Create.NewDetailCurve(active_view, inst_geom_obj)
                                    bound_curve_count += 1

                    # If geometry is a Curve (line)
                    elif isinstance(geom_obj, DB.Curve):
                        # Skip unbound curves
                        if geom_obj.IsBound:
                            
                        
                            # Create a Revit detail line from the curve in the active view
                            detail_line = doc.Create.NewDetailCurve(active_view, geom_obj)
                            bound_curve_count += 1

# Commit the transaction
t.Commit()

# Output the unique layer names
print("Layer Names: {}".format(layer_names))

# Output the total count of bound curves
print("Total number of bound curves: {}".format(bound_curve_count))

apply this script to create grid from cad link , but not create grid line.

any one have idea…

@shuvro.arc ,

i can just share a dynamo issue that i solved partly with python. You can migrate some ideas to clean python…

1 Like