I've been looking for a while and managed to find 2 VBA scripts for replacing values in a title block. However one errors out on the line that is supposed to do the replacing and the other works off an ID number which isn't consistent.
I'm a proficient scripter but not in this language, so I have a general idea of how these scripts are working but not the intricacies of them. Which Is exactly what I think is needed to get either of them working.
Function Test_UpdateTitleBlock() Dim oDoc As DrawingDocument Set oDoc = ThisApplication.ActiveDocument Dim oTitleBlock As TitleBlock Dim oTextBox As TextBox Dim oSheet As Sheet For Each oSheet In oDoc.Sheets Set oTitleBlock = oSheet.TitleBlock For Each oTextBox In oTitleBlock.Definition.Sketch.TextBoxes If oTextBox.Text = "<FILENAME AND PATH>" Then ' Errors here and doesn't replace text Call oTitleBlock.SetPromptResultText(oTextBox, "New Value") End If Next Next End Function
This throws an error on the line I have marked.
Function Remove_Filepath() Dim oDrawDoc As DrawingDocument Set oDrawDoc = ThisApplication.ActiveDocument ' Create the new title block defintion. Dim oTitleBlockDef As TitleBlockDefinition Set oTitleBlockDef = oDrawDoc.ActiveSheet.TitleBlock.Definition Dim oSketch As DrawingSketch Call oTitleBlockDef.Edit(oSketch) oSketch.TextBoxes.Item(20).Text = " " Call oTitleBlockDef.ExitEdit End Function
This one works great, except that it does a "dumb" replace because it looks for the Xth textbox and edits that. The problem is in a detail drawing I want to edit textbox 20 but in assembly drawings I don't want to edit any textbox. So if someone could get this to loop through the textboxes and compare the text to what I want to replace that would be awesome.
Thanks for any help.
Sorry for the double post but it seems either you can't edit posts or at least opening posts.
It always seems like I manage to get something working after I asking somewhere for help and I always like to share to what I figured out.
Function Remove_FilePath() On Error GoTo ErrMsg Dim oDrawDoc As DrawingDocument Set oDrawDoc = ThisApplication.ActiveDocument ' Create the new title block defintion. Dim oTitleBlockDef As TitleBlockDefinition Set oTitleBlockDef = oDrawDoc.ActiveSheet.TitleBlock.Definition Dim oSketch As DrawingSketch Call oTitleBlockDef.Edit(oSketch) Dim count As Integer count = 1 While oSketch.TextBoxes.Item(count).Text <> vbNullString If oSketch.TextBoxes.Item(count).Text = "<FILENAME AND PATH>" Then oSketch.TextBoxes.Item(count).Text = " " End If count = count + 1 Wend ErrMsg: Call oTitleBlockDef.ExitEdit End Function
This function just "removes" the filepath from the title block. It doesn't seem to like substituting in "" but a space works just fine. I take no credit for most of the script, just a bit of credit for hacking it some. It loops through all the textboxes inside of the title block and when it matches the text it replaces it.
Access a broad range of knowledge to help get the most out of your products and services.
Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.
Upgrading to a 2015 product? Make sure to check these out 1st!