DWG Layers (Import Instance)

Hi I would like to know if anyone has been able to retrieve import instance layers. I am creating a task dialog for the user to input the layer name and then I would check if it exists. Any help is appreciated. Many thanks

# Step 1: Prompt user to select a dwg file
picked = uidoc.Selection.PickObject(ObjectType.Element, "Select DWG file")
dwg_import_instance = doc.GetElement(picked.ElementId)

# Step 2: Prompt user to enter name of AutoCAD layer
result = forms.ask_for_string(prompt="Enter Layer Name:", title="Layer Name")

if result:
    layer_name = result
    TaskDialog.Show("Result", "The form was cancelled.")

Found a solution if someone encounters this might be useful.

gStyle = doc.GetElement(geometry_object.GraphicsStyleId)
                if gStyle.GraphicsStyleCategory.Name == layer_name:

Also all ImportInstance has it’s own custom Category, where all Sub-categories are the Layers of the DWG

1 Like

I tried initially getting it through the SubCategories but couldnt get it to work.