[Python] ezdxf python - How can I set the plot transparency configuration in the plotsettings...

Discussão em 'Python' iniciado por Stack, Novembro 29, 2024.

  1. Stack

    Stack Membro Participativo

    I have a code that plots a layout created with ezdxf, but I have trouble setting my plot transparency option, because I have a external reference with an image that I want to be 40% transparent.

    This is the code I use for plotting the whole dxf file, but I dont know how to set the transparency option to True in the plot options, I cant find the docs for this references.

    Also it would be very nice if when I create my layout in the ezdxf, I could set all this plotting options for each layout.

    doc = ezdxf.readfile(dxf_path)
    layout = doc.layouts.new(name='layout_name')
    layout.applyPlotOptions(papersize="ISO_full_bleed_A1_(841.00_x_594.00_MM)", plotsytle table='style.ctb', plottransparency=0.6, etc)


    I would very much appreciatte any help on this.

    Chelo.

    def plot_layouts(dwg_path, ctb_file_path, output_folder):

    if not os.path.exists(output_folder):
    os.mkdir(output_folder)


    # Initialize AutoCAD
    acad = win32com.client.Dispatch("AutoCAD.Application")
    acad.Visible = False # Set to False if you don't want to show AutoCAD

    # Open the DWG file
    doc = acad.Documents.Open(dwg_path)

    # Loop through all layouts
    for i in range(doc.Layouts.Count):
    print(i)
    time.sleep(5)
    layout = doc.Layouts.Item(i + 1) # Indexing starts from 1 in COM

    # Set the layout as active
    doc.ActiveLayout = layout

    # Configure the plot settings
    doc.ActiveLayout.ConfigName = "DWG To PDF.pc3" #se puede cambiar a cualquier pc3 configurado
    doc.ActiveLayout.StyleSheet = ctb_file_path
    # doc.ActiveLayout.CanonicalMediaName = "ISO_expand_A4_(210.00_x_297.00_MM)" #debe coincidir exctamente el nombre
    doc.ActiveLayout.CanonicalMediaName = "ISO_full_bleed_A1_(841.00_x_594.00_MM)" #debe coincidir exctamente el nombre


    # Set the output file path
    output_file_path = f"{output_folder}/{layout.Name}.pdf"

    # Plot the layout
    doc.Plot.PlotToFile(output_file_path)
    time.sleep(5)

    # Close the document without saving changes
    doc.Close(SaveChanges=True)

    # Quit AutoCAD
    acad.Quit()

    Continue reading...

Compartilhe esta Página