Skip to main content
1-Visitor
November 29, 2010
Question

Delete unused pens

  • November 29, 2010
  • 2 replies
  • 7879 views

Is it possible to write a macro to delete all unused pens? We are converting files with (sometimes) hundreds of unused pens that need to be deleted. The only way to delete them currently is one by one - which takes forever.

    2 replies

    12-Amethyst
    November 29, 2010

    Here is a start for a macro I just rolled out to our group today. It's not exactly what you're looking for, but helped us out. We generally have 5-15 miscellaneous lines come through when we import. We didn't need to go as far as an auto-completing macro. Note that this checks the pen name to see if the first character is a zero, if so it prompts for the replacement. The replacement integer is simply the number of the pen.

    If you want to do this automatically, my recommendation is to add a FWrite command in to note what pens you are replacing with what. Run it manually on some files until you have a good basis for replacement. Once you have your groupings you could add checks to say if a line is solid, and between x and y thick, replace with the "Thick" pen.

    Hope this helps.

    Macro Pen_Replacement

    Define p as Integer

    Define i as Integer
    Define GoodPens as String
    Define BadPen as String
    Define Replacement as Integer
    Define NewPen as String

    Zoom Page
    Select None
    Wait Timer 1

    #Sets values of variables.
    i = ActiveDoc.PenCount
    p = 1

    #Starts loop that goes through all existing pens.
    While ((p <> i + 1) = True)

    Select None
    Wait Timer 1

    If (Left(ActiveDoc.Pens[p].Name, 1) = "0") then
    BadPen = ActiveDoc.Pens[p].Name
    Select if Pen is equal to BadPen
    Replacement = Get Integer "Replace selected lines with:" + $NewLine + GoodPens
    NewPen = ActiveDoc.Pens[Replacement].Name
    Delete Pen BadPen NewPen

    #Reduce number of overall pens because of pen deletion.
    i = ActiveDoc.PenCount
    Else
    p = p + 1
    End If

    End While

    Select None

    End Macro

    12-Amethyst
    November 29, 2010

    Actually, looking again, I see you said "unused". Are they actually appearing in italics? If so, just loop through them, select lines that match. If no matches, delete the pen.

    1-Visitor
    November 29, 2010

    Yes, all the unused pens are italicized. I guess I should also add that I am not exactly fluent with the IsoDraw macro language. My original question should have said: "Is there an existing macro that I could steal . . . "

    We have a macro to delete all empty layers that is as simple as this:

    Macro Delete All Empty Layers
    DELETE ALL EMPTY LAYERS
    end macro

    I was hoping there would be something equally simple for deleting pens.

    12-Amethyst
    November 29, 2010

    I have a project I need to finish in the next few hours, but I should be able to get a simple one done for you. Give me about 2-1/2 hours and I'll try to have something posted.