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

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Mapkey for making a change to all pages of a drawing

slapha
15-Moonstone

Mapkey for making a change to all pages of a drawing

 

Has anyone had any luck creating a mapkey to make changes to each page of a drawing?

Case I'm working with is putting a new symbol on each and every page using Creo 2.0. Typically an older legacy drawing, or one that has already been created. Symbol also has options which is another battle but one step at a time. 

 

I want the mapkey to essentally go to page 1, make change, go to page 2, make change... etc until each page is changed. In programming it would be a loop until it reaches the last page then stop. Ideally this lends itself to JLink or Toolkit, which I may get to that point, but I'm starting out with mapkeys.

 

So far this is what I have is something like this where it just keeps iterating until some predetermined maximum page count.

 

 

mapkey changepages @MAPKEY_LABEL Change Pages;\
mapkey(continued) ~ Command `ProCmdDwgGotoSheet`;\
mapkey(continued) ~ Update `gotosheet` `InpPagenum` `1`;\
mapkey(continued) ~ FocusOut `gotosheet` `InpPagenum`;\
mapkey(continued) ~ Activate `gotosheet` `Goto`;\
mapkey(continued) ~ %InsertSymbol;\
mapkey(continued) ~ Update `gotosheet` `InpPagenum` `2`;\
mapkey(continued) ~ FocusOut `gotosheet` `InpPagenum`;\
mapkey(continued) ~ Activate `gotosheet` `Goto`;\
mapkey(continued) ~ %InsertSymbol;\
mapkey(continued) ~ Update `gotosheet` `InpPagenum` `3`;\
mapkey(continued) ~ FocusOut `gotosheet` `InpPagenum`;\
mapkey(continued) ~ Activate `gotosheet` `Goto`;\
mapkey(continued) ~ %InsertSymbol;\
...
mapkey(continued) ~ Update `gotosheet` `InpPagenum` `99`;\
mapkey(continued) ~ FocusOut `gotosheet` `InpPagenum`;\
mapkey(continued) ~ Activate `gotosheet` `Goto`;\
mapkey(continued) ~ %InsertSymbol;\
mapkey(continued) ~ Activate `gotosheet` `Close`;

It will throw errors for the pages that don't exist, but doesn't seem to cause harm...yet. Of course the second you make a 99 page mapkey someone will find a 100 page drawing, and then a 101 page drawing ... and so on.

 

I also tried using the "next" button but then you get caught changing pages that were already changed and still stuck to some pre-determined limit. So that would depend on what kind of change is being done if you can loop over existing pages.

 

 

Anyone have any better luck or ideas? Time to break out JLink/Toolkit (and learn it)?

1 REPLY 1
dschenken
21-Topaz I
(To:slapha)

I'd look at AutoIt or AutoHotKey first, but if those aren't available, I've used VBA out of Excel to dynamically generate mapkeys.

 

I create a prototype of each section mapkey and then reformat them as PRINT statements in the VBA editor. Then I add whatever loop structure is needed around the PRINT statements and break the strings in the print statements to inject/replace the original references with ones generated by the VBA statements.

 

The PRINT statements will go to a file, and that file can be given some useful name. I find it best to include in that file a section that reloads the file when the mapkey is run, so that it gets the latest version of itself first.

 

So the VBA would be something like:

 

Sub maketrail()

Open "e:\FILENAME.txt" For Output As #1
Dim pagecount As Integer
pagecount = 10

Print #1, "mapkey changepages @MAPKEY_LABEL Change Pages;\"
Print #1, "mapkey(continued) ~ Command `ProCmdDwgGotoSheet`;\"

For i = 1 To pagecount
Print #1, "mapkey(continued) ~ Update `gotosheet` `InpPagenum` `"; CStr(i); "`;\"
Print #1, "mapkey(continued) ~ FocusOut `gotosheet` `InpPagenum`;\"
Print #1, "mapkey(continued) ~ Activate `gotosheet` `Goto`;\"
Print #1, "mapkey(continued) ~ %InsertSymbol;\"
Next
Close #1
End Sub

 

If you want fancy, you can have it pop up a dialog box that asks how many pages or fill in a worksheet cell and get the number/other data from there.

 

One of the first programs I wrote (no longer working there so no longer have a copy) took the mapkey file and prefixed and suffixed the whole of it with PRINT #1, " and suffixed it with "s to save time when developing from the mapkeys. Saves a lot of fumble fingered errors on bulk mapkey contents.

 

Note the use of CStr to prevent VBA from padding around the number with space characters.

Top Tags