VBA looping through titleblocks & borders

VBA looping through titleblocks & borders

NachoShaw
Advisor Advisor
1,056 Views
6 Replies
Message 1 of 7

VBA looping through titleblocks & borders

NachoShaw
Advisor
Advisor

Hi All,

 

Im trying to make a small tool that i can share with other users that allows at the click of a button, a form to give options for titles & borders. Im pretty good with VBA but new to Inventor objects. The tool itself will change all of the borders & titleblocks in multiple sheets to the selects ones on the form in one go.

 

I have the code set up to loop through the sheets and delete / replace all borders & titleblocks and this works great. Im trying to find how i can loop through the borders & titleblocks so that i can get them into a combo box for each. I cant find anything about this on the internet.

 

Could someone please give a little bit of advice or direction?

 

 

Thanks

 

 

 

Nidge

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
1,057 Views
6 Replies
Replies (6)
Message 2 of 7

ekinsb
Alumni
Alumni

By "loop through the borders & titleblocks so that i can get them into a combo box" do you mean you want to get a list of the available borders and title blocks in the drawing?  If so you want to look in the API for TitleBlockDefinitions and BorderDefinitions.  These collections are available directly from the DrawingDocument object and provide access to the same list you see in the browser. 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 3 of 7

NachoShaw
Advisor
Advisor
Hi, yes I do mean that. I have looked at the definitions because I use that to add my current title ok and border into my sheets. I can't quite work out how to get the title lock name. I count the definitions but not get the names...

Thanks

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 4 of 7

NachoShaw
Advisor
Advisor
Just to clarify, it's a list of ALL titleblocks and ALL borders in the idw not the active sheet

Thanks

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 5 of 7

ekinsb
Alumni
Alumni

I think this should demonstrate what you're trying to do.

 

Public Sub ListDrawingResources()
    Dim drawDoc As DrawingDocument
    Set drawDoc = ThisApplication.ActiveDocument
    
    Debug.Print "Title Blocks"
    Dim titleBlockDef As TitleBlockDefinition
    For Each titleBlockDef In drawDoc.TitleBlockDefinitions
        Debug.Print titleBlockDef.name
    Next
    
    Debug.Print ""
    Debug.Print "Borders"
    Dim borderDef As BorderDefinition
    For Each borderDef In drawDoc.BorderDefinitions
        Debug.Print borderDef.name
    Next
    
    Debug.Print ""
    Debug.Print "Sketched Symbols"
    Dim sketchSymbolDef As SketchedSymbolDefinition
    For Each sketchSymbolDef In drawDoc.SketchedSymbolDefinitions
        Debug.Print sketchSymbolDef.name
    Next
End Sub

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 6 of 7

forbillian
Advocate
Advocate

Thanks You for your code Ekinsb,

 

I have used to delete borders if they exist.

 

I am trying to complete some code which adds Add a Border but I am stuck on changing Prompted Text Values that

can exist in different borders.

 

I need to loop through all or any possible sPromptStrings() & if 1 or say 50 exist then the code will still let me add a border without needing to know the specific number:

 

Sub Main InsertCustomBorderOnSheet()
' Set a reference to the drawing document.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument 

' Obtain a reference to the desired border definition.
Dim oBorderDef As BorderDefinition
 oBorderDef = oDrawDoc.BorderDefinitions.Item("Border")

Dim oSheet As Sheet
 oSheet = oDrawDoc.ActiveSheet

' Check to see if the sheet already has a border and delete it if it does.'If Not oSheet.Border Is Nothing Then'oSheet.Border.Delete'End If

' This border definition contains one prompted string input. An array' This line must show the exact number of Prompted Strings in the Border
'WANTING A "FOR i = 1 to 100" type iteration loop below?????
Dim
sPromptStrings(0 To 1) As String sPromptStrings(0) = "WHIM" sPromptStrings(1) = "WHAM" ' Add an instance of the border definition to the sheet. Dim oBorder As Border oBorder = oSheet.AddBorder(oBorderDef, sPromptStrings) 'THIS LINE LINE WORKS FOR INSERTING BORDER End Sub 

 

Thanks in Advance

0 Likes
Message 7 of 7

forbillian
Advocate
Advocate

Hi ekinsb,

 

This is some code I found which iterates through all prompted values in featured Border and makes them blank by value.  I need to use this somehow so that when I am adding a new Border I can set each value as blank when I am adding the border: See Below

 

Dim doc As DrawingDocument = ThisApplication.ActiveDocument

  Dim tb As TextBox

  Dim i As Integer = 1

  Dim border As Border = doc.ActiveSheet.Border

  Dim borderDef As BorderDefinition = border.Definition

 

  For Each tb In borderDef.Sketch.TextBoxes

          border.SetPromptResultText(borderDef.Sketch.TextBoxes.Item(i), "")

      i = i + 1

  Next
0 Likes