cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Delete unused pens

ChrisChase
1-Newbie

Delete unused pens

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.

18 REPLIES 18

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

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.

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.

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.

Close, but having problems with the Delete Pen function using a variable. I'll post where I am at this point.

Macro Delete_Unused_Pens

Define p as Integer
Define i as Integer
Define CheckMe as String

Zoom Page
Select None

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

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

Select None

CheckMe = ActiveDoc.Pens[p].Name

Select if Pen is equal to CheckMe

If (Exists (ActiveDoc.FirstSelectedElement) = False) Then
Delete Pen CheckMe
Else
p = p + 1
End If

#Reduce number of overall pens because of pen deletion.
i = ActiveDoc.PenCount

End While

Select None

End Macro

Try this. It looks a little odd, but it works.

Macro Delete_Unused_Pens

Define p as Integer
Define i as Integer
Define CheckMe as String

Zoom Page
Select None

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

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

Select None

CheckMe = ActiveDoc.Pens[p].Name

Select if Pen is equal to CheckMe

If (Exists (ActiveDoc.FirstSelectedElement) = False) Then
Set Active Pen CheckMe
Create Line 0 0 1 1

#Doesn't make sense, but delete pen line fails first time. Error restarts macro and it works the

second time.
On Error Goto Delete_Unused_Pens
Delete Pen CheckMe "$ISO_NOPEN"
Delete Selection
Else
p = p + 1
End If

#Reduce number of overall pens because of pen deletion.
i = ActiveDoc.PenCount

End While

Select None
Zoom Page

End Macro

Wow - fantastic - it works! Thank you very much - I owe you one.

BTW - how did you learn the IsoDraw macro language? I spent many years working with InterCap/Mondello, where I taught myself the language, and could write a macro to make it do just about anything. The software came with a command reference book which listed every command that the system recognized, which was vital to learning the language. Is there any such thing in the IsoDraw universe?

Glad it works for you.

In regards to learning, the best thing is playing around. In 7.0 there is a separate macro guide available through the Help dropdown. In 7.1 they actually combined it with the main Help Topics. I'd recommend using the 7.1 version even if you only have 7.0. There were a number of features that various members discovered in 7.0 that weren't documented. They're covered in the 7.1 documentation and are actually noted when they worked in 7.0.

In my specific case, we had bought IsoDraw and it sat for about six months with most of the department not knowing it was there. We went to use it and we were starting at ground zero. Only one guy had used the software in the past (about 10-15 years ago I believe). I needed to replace some interactive documents on-line and had to figure out how to do it with the software. Necessity sparked the fire. While working on my stuff I found that we could simplify a lot of tasks such as importing and saving. Over 40 macros (and multiple revisions of each) later and you start to grasp the idea.

A piece of advise, with IML, be patient. Often you run into roadblocks when programming, but in IML it seems like a slightly higher frequency. In this case I had to implement the drawing of the line to delete a line. Couldn't just delete it. Maybe a bug, maybe me...

Thanks for the advice - that's pretty much the same way I learned the InterCap macro language.

One more question about this macro: I just noticed that it is leaving a couple of short line segments at the bottom left corner of the drawing 'page'. Not a big deal, but is there a way to have it get rid of those as well?

Macro Delete_Unused_Pens

Define p as Integer
Define i as Integer
Define CheckMe as String
Define E1 as Element

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

CheckMe = ActiveDoc.Pens[p].Name

Select if Pen is equal to CheckMe

If (Exists (ActiveDoc.FirstSelectedElement) = False) Then
Set Active Pen CheckMe
Create Line 0 0 1 1
E1 = ActiveDoc.FirstSelectedElement
Create object_info E1
E1.Info.Name = "Delete_Me"

On Error Goto WhoCares
Delete Pen CheckMe "$ISO_NOPEN"

Else
p = p + 1
End If

#Reduce number of overall pens because of pen deletion.
i = ActiveDoc.PenCount

End While

Select None
Select if Object_Name is Equal to 'Delete_Me'
Delete Selection
Select None
Zoom Page

End Macro

SubMacro WhoCares
End Submacro

Truely, a work of art. I can't thank you enough.

Chris

p.s. Here's a small view of what I was dealing with:

Unused-pens.jpg

Hi Trevor, is they have a way to incorporate someting in this macro to not delete line who is lock or invisible???

Thanks a lot, this macro is awsome!!!

Thanks!!!

You could reference the attributes of the layer prior to the delete. I'd recommend looking at the ActiveDoc.layers[LayerName].State verbiage in the macro help section. You should be able to check if a layer is locked or invisible and just skip the delete if either of those are true.

If you need help, let me know.

I'm new in macro so... not to good! if you could help me on this expression, it will be much appreciated!!!

Many thanks!!!

I apologize. I confused your question and was thinking 'layers'.

In regards to your request, I guess I don't understand. The macro deletes unused pens. You can't lock or hide a pen, just layers. If a pen is on a locked or hidden layer it won't be deleted.

I'm hoping this addresses your question. If it doesn't, can you give more explanation of your situation?

Sorry for my explaination it was not clear....

When a run the macro:

Macro Delete_Unused_Pens

it take my frame who is on:

Layer 181 Frames (Locked) with a pen called frames 0.004 thick

Screen color pink

hue 200

sat 240

lum180

red 255

green 128

blue255

with color fill white

And it change into no pen???

you can test with the same file attached into post (How to select only projected text in macro??? (post 2 with file attached).

In the same time, into in our frame file, we have some custom pens (all the one in exemple file) then we whant to keep is it possible incorporate someting into the macro to keep those one untouch???

Thanks a lot!

Are the custom pens you are trying to preserve in your preference file? Or do you have to set them each time manually or via macro?

We dont have to set manualy or by macro those pens because we start all the time new illustration by using our std frame who already have the custom pens added, but when we insert detail created from 3D in catia or other software, they have many pens transfer to isodraw, those pens are usefull to rework them for selted group by color or else, but at the end we need to delete them to keep clean illustration.

Top Tags