iLogic to replace a piece of file name during export

iLogic to replace a piece of file name during export

To_Efficiency_and_Beyond
Enthusiast Enthusiast
550 Views
2 Replies
Message 1 of 3

iLogic to replace a piece of file name during export

To_Efficiency_and_Beyond
Enthusiast
Enthusiast

Hello!

I am running a rule that exports PDFs intelligently to a new location. Currently the rule won't work on drawings with multiple sheets.. I am looking to fix that 😋

 

Drawing file name: XX.XX.XXXX-S1S2S3S4RX MODELNAME PART NAME.dwg

 

I would like to know how to isolate the entire portion in red so that I can replace it with the proper sheet number. aka For Each sheet, output a pdf with the right sheet number in the file name. This should always replace everything between "-" and "R" with S#.

 

Output PDF names:

XX.XX.XXXX-S1RX MODELNAME PART NAME.pdf

XX.XX.XXXX-S2RX MODELNAME PART NAME.pdf

XX.XX.XXXX-S3RX MODELNAME PART NAME.pdf

XX.XX.XXXX-S4RX MODELNAME PART NAME.pdf

 

Side Note, I found this snippet and it seems like a good way to go for the numbering

Dim CurrentSheet As Integer

Dim strSheetName As String
strSheetName = oDocument.ActiveSheet.Name

If InStr(strSheetName, ":") Then
' Extract the sheet number from the name.
GetSheetNumber = CInt(Right$(strSheetName, Len(strSheetName) - InStrRev(strSheetName, ":")))
Else
'This sheet is not numbered so returnzero.
GetSheetNumber = 0
End If

CurrentSheet = "S" & GetSheetNumber

0 Likes
Accepted solutions (1)
551 Views
2 Replies
Replies (2)
Message 2 of 3

pball
Mentor
Mentor
Accepted solution

Using some string functions should be the most simple way to accomplish this, with some assumptions about the filename. If the dash before the first S section is always the first dash and the R after the S section is the first R in the file name, this should always work.

 

Dim fname As String = "XX.XX.XXXX-S1S2S3S4RX MODELNAME PART NAME.dwg"

beforedash = Left(fname, fname.IndexOf("-") + 1)

afterR = Mid(fname, fname.IndexOf("R")+1,fname.Length - 4 - fname.IndexOf("R"))

MsgBox("before dash: " & beforedash & vbNewLine & "after R: " & afterR)

 This returns "XX.XX.XXXX-" and "RX MODELNAME PART NAME"

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Message 3 of 3

To_Efficiency_and_Beyond
Enthusiast
Enthusiast

You nailed it! 🙂 Thank you so much for help!

0 Likes