Author Topic: Adding more text to layout tabs  (Read 4984 times)

0 Members and 1 Guest are viewing this topic.

krampaul82

  • Guest
Adding more text to layout tabs
« on: February 24, 2011, 04:46:58 PM »
Hello everyone,

I have a drawing template that has 12 layout tabs and each one says acm- sht1,acm- sht2 etc.
the problem is when a job number is assigned I need to re-label the tabs to say acm-10-xxx sht1, acm-10-xxxx, etc.
is there a way to do this in vb(a) or Lisp? :? any help appreciated... 

Mark

fixo

  • Guest
Re: Adding more text to layout tabs
« Reply #1 on: February 24, 2011, 06:08:49 PM »
Try this code
Code: [Select]
Option Explicit
'===============================================================
'require reference to Microsoft VBScript Regular Expressions 5.5
'===============================================================

Sub ahha()
Dim s As String
Dim i As Long
Dim cnt As Integer
Dim newstr As String
Dim num As Double
Dim regex As RegExp
Set regex = New RegExp
regex.IgnoreCase = False
regex.Global = False

newstr = "Boo"

regex.Pattern = "(acm-)(.*?)(-sht)(\d+)"
' Where:
' (acm-)- constant part
' (.*?) -  any charachters you need to replace with 'newstr'
' (-sht)- constant part
' (\d+) - any digits
Dim olayout As AcadLayout
For Each olayout In ThisDrawing.Layouts
If Not olayout.ModelType Then
ThisDrawing.ActiveLayout = olayout

olayout.Name = regex.Replace(olayout.Name, "$1" & newstr & "$3" & "$4")

Debug.Print olayout.Name 'debug only
End If
Next
Set regex = Nothing
ThisDrawing.SetVariable "tilemode", 1

End Sub

krampaul82

  • Guest
Re: Adding more text to layout tabs
« Reply #2 on: February 25, 2011, 09:29:16 AM »

Fixo,
This is what I tried to run from a module, see the red comment where is hangs.  am I doing this right?
any help appreciated, at your convienence......
Mark



'---------------------------------------------------------------------------------------
' Module    : Module1
' DateTime  : 2/25/2011 07:43
' Author    :
' Purpose   :
'---------------------------------------------------------------------------------------
Option Explicit


Sub gtc_tab_rename()

Dim tabrename As String
Dim s As String
Dim i As Long
Dim cnt As Integer
Dim newstr As String
Dim num As Double
Dim regex As RegExp [program stops here. Compile error user-defined type not defined]
Set regex = New RegExp
regex.IgnoreCase = False
regex.Global = False


tabrename = InputBox$("Enter the Project Number : ")    'Sets the project number for the tab.
If tabrename = "" Then End                                       'exits clean if the user hits cancel from the input box

'Confirm the project number

Msg = "You have entered " & tabrename & " is this correct?"    ' Define message.
Style = vbYesNo + vbInformation + vbDefaultButton1              ' Define buttons.
Title = "gtc Confirm Project Number"                              ' Define title.
Ctxt = 1000    ' Define topic
       
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then    ' User chose Yes.

       
Else: gtc_tab_rename  ' User chose No. restart the program for another choice
  End ' Leave The Program
End If


newstr = " & tabrename & "

regex.Pattern = "(acm-)(.*?)(-sht)(\d+)"
' Where:
' (acm-)- constant part
' (.*?) -  any charachters you need to replace with 'newstr'
' (-sht)- constant part
' (\d+) - any digits
Dim olayout As AcadLayout
For Each olayout In ThisDrawing.Layouts
If Not olayout.ModelType Then
ThisDrawing.ActiveLayout = olayout

olayout.Name = regex.Replace(olayout.Name, "$1" & newstr & "$3" & "$4")

Debug.Print olayout.Name 'debug only
End If
Next
Set regex = Nothing
ThisDrawing.SetVariable "tilemode", 1

End Sub

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Adding more text to layout tabs
« Reply #3 on: February 25, 2011, 09:35:21 AM »
Have fun with this.   :-)
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

krampaul82

  • Guest
Re: Adding more text to layout tabs
« Reply #4 on: February 25, 2011, 10:53:06 AM »
Have fun with this.   :-)
Suh-Wheet! Thank you for sharing Matt! I did modify it some, I changed Ucase T Lcase..

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Adding more text to layout tabs
« Reply #5 on: February 25, 2011, 11:20:47 AM »
Have fun with this.   :-)
Suh-Wheet! Thank you for sharing Matt! I did modify it some, I changed Ucase T Lcase..
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

krampaul82

  • Guest
Re: Adding more text to layout tabs
« Reply #6 on: February 25, 2011, 03:10:15 PM »
Is that the IT guy from SNL? I loved that skit... MOVE OVER! :-D

fixo

  • Guest
Re: Adding more text to layout tabs
« Reply #7 on: February 25, 2011, 05:49:17 PM »

Fixo,
This is what I tried to run from a module, see the red comment where is hangs.  am I doing this right?
any help appreciated, at your convienence......
Mark



'---------------------------------------------------------------------------------------
' Module    : Module1
' DateTime  : 2/25/2011 07:43
' Author    :
' Purpose   :
'---------------------------------------------------------------------------------------
Option Explicit


Sub gtc_tab_rename()

Dim tabrename As String
Dim s As String
Dim i As Long
Dim cnt As Integer
Dim newstr As String
Dim num As Double
Dim regex As RegExp [program stops here. Compile error user-defined type not defined]
Set regex = New RegExp
regex.IgnoreCase = False
regex.Global = False


tabrename = InputBox$("Enter the Project Number : ")    'Sets the project number for the tab.
If tabrename = "" Then End                                       'exits clean if the user hits cancel from the input box

'Confirm the project number

Msg = "You have entered " & tabrename & " is this correct?"    ' Define message.
Style = vbYesNo + vbInformation + vbDefaultButton1              ' Define buttons.
Title = "gtc Confirm Project Number"                              ' Define title.
Ctxt = 1000    ' Define topic
       
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then    ' User chose Yes.

       
Else: gtc_tab_rename  ' User chose No. restart the program for another choice
  End ' Leave The Program
End If


newstr = " & tabrename & "

regex.Pattern = "(acm-)(.*?)(-sht)(\d+)"
' Where:
' (acm-)- constant part
' (.*?) -  any charachters you need to replace with 'newstr'
' (-sht)- constant part
' (\d+) - any digits
Dim olayout As AcadLayout
For Each olayout In ThisDrawing.Layouts
If Not olayout.ModelType Then
ThisDrawing.ActiveLayout = olayout

olayout.Name = regex.Replace(olayout.Name, "$1" & newstr & "$3" & "$4")

Debug.Print olayout.Name 'debug only
End If
Next
Set regex = Nothing
ThisDrawing.SetVariable "tilemode", 1

End Sub
Add reference to Microsoft VBScript Reguar Expressions 5.5

krampaul82

  • Guest
Re: Adding more text to layout tabs
« Reply #8 on: March 01, 2011, 10:21:12 AM »

Fixo,
This is what I tried to run from a module, see the red comment where is hangs.  am I doing this right?
any help appreciated, at your convienence......
Mark



'---------------------------------------------------------------------------------------
' Module    : Module1
' DateTime  : 2/25/2011 07:43
' Author    :
' Purpose   :
'---------------------------------------------------------------------------------------
Option Explicit


Sub gtc_tab_rename()

Dim tabrename As String
Dim s As String
Dim i As Long
Dim cnt As Integer
Dim newstr As String
Dim num As Double
Dim regex As RegExp [program stops here. Compile error user-defined type not defined]
Set regex = New RegExp
regex.IgnoreCase = False
regex.Global = False


tabrename = InputBox$("Enter the Project Number : ")    'Sets the project number for the tab.
If tabrename = "" Then End                                       'exits clean if the user hits cancel from the input box

'Confirm the project number

Msg = "You have entered " & tabrename & " is this correct?"    ' Define message.
Style = vbYesNo + vbInformation + vbDefaultButton1              ' Define buttons.
Title = "gtc Confirm Project Number"                              ' Define title.
Ctxt = 1000    ' Define topic
       
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then    ' User chose Yes.

       
Else: gtc_tab_rename  ' User chose No. restart the program for another choice
  End ' Leave The Program
End If


newstr = " & tabrename & "

regex.Pattern = "(acm-)(.*?)(-sht)(\d+)"
' Where:
' (acm-)- constant part
' (.*?) -  any charachters you need to replace with 'newstr'
' (-sht)- constant part
' (\d+) - any digits
Dim olayout As AcadLayout
For Each olayout In ThisDrawing.Layouts
If Not olayout.ModelType Then
ThisDrawing.ActiveLayout = olayout

olayout.Name = regex.Replace(olayout.Name, "$1" & newstr & "$3" & "$4")

Debug.Print olayout.Name 'debug only
End If
Next
Set regex = Nothing
ThisDrawing.SetVariable "tilemode", 1

End Sub
Add reference to Microsoft VBScript Reguar Expressions 5.5
Iadded the reference, the program does not hang but it does not do anything with the tabs....