Replacing the title block on all drawing sheets

Replacing the title block on all drawing sheets

brow1372
Participant Participant
3,661 Views
5 Replies
Message 1 of 6

Replacing the title block on all drawing sheets

brow1372
Participant
Participant

Hi All,

 

I am trying to patch together some Ilogic code to delete and replace the title blocks on every sheet in a drawing.

I am stuck at the point that it should go through all the sheets and add the new title block.

 

Thanks for the help.

 

SyntaxEditor Code Snippet

         Dim oDoc As Inventor.Document
        oDoc = m_inventorApp

 
        ' Find out if TitleBlockDefinition exists
        Dim bTBDfound As Boolean
        bTBDfound = False
 
        Dim oTBD As TitleBlockDefinition
        For Each oTBD In oDoc.TitleBlockDefinitions
            Debug.Print(oTBD.Name)
            If oTBD.Name = "HMCTITLE" Then
                bTBDfound = True
                Exit For
            End If
        Next oTBD
 
'        If bTBDfound = False Then'            MsgBox("ANSI - Large Title block already deleted")'            End'        End If
 
        oTBD = oDoc.TitleBlockDefinitions("HMCTITLE")
        If oTBD.IsReferenced = True Then
            Dim oSheetFormat As SheetFormat, oSheet As Sheet
 
            ' Check if there is any instance in SheetFormat/Sheet
            ' that refers to the TitleBlockDefinition
            For Each oSheet In oDoc.Sheets
                If oSheet.TitleBlock.Definition Is oTBD Then
 
                    ' Delete this instance which refers to the
                    ' TitleBlockDefinition
                    oSheet.TitleBlock.Delete()
                End If
            Next
 
            For Each oSheetFormat In oDoc.SheetFormats
                If oSheetFormat.ReferencedTitleBlockDefinition Is
                  oTBD Then
                    ' Delete this instance which refers to the
                    ' TitleBlockDefinition
                    oSheetFormat.Delete()
                End If
            Next
 
            ' Now you can delete the TitleBlockDefinition.
            oTBD.Delete()
        Else
            ' TitleBlockDefinition is not referenced go ahead and
            ' delete
            oTBD.Delete()
        
        End If




ThisDrawing.ResourceFileName = "z:\templates\HMC DRAWING.idw"


ActiveSheet = ThisDrawing.Sheet("Sheet:1")
ActiveSheet.TitleBlock = "HMCTITLE"
'ActiveSheet = ThisDrawing.Sheet("Sheet:2")
ActiveSheet.TitleBlock = "HMCTITLE"
'
'ActiveSheet = ThisDrawing.Sheet("Sheet:3")'ActiveSheet.TitleBlock = "HMCTITLE"


iLogicVb.UpdateWhenDone = True

MessageBox.Show("Success", "Iproperty update", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)

 

Accepted solutions (1)
3,662 Views
5 Replies
Replies (5)
Message 2 of 6

Curtis_Waguespack
Consultant
Consultant

HI @row1372,

 

Here's a quick example, that uses title block definitions that are already in the file, and swaps one for another.

 

It was unclear to me what your goal was here.


Are you trying to delete all existing title blocks in the drawing, including those in the sheet formats, and then delete the title block definition, so that you can bring in a new version of the title block definition from another file, and insert it onto each sheet?

 

If that's the case then I think you're still missing some stuff.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

oInput = InputRadioBox("Select One", "B SIZE", "D SIZE", True, "iLogic")

Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveEditDocument

Dim oCurrentNumber  As Sheet
oCurrentNumber = oDoc.ActiveSheet

' Iterate through the sheets
Dim oSheet As Sheet
For Each oSheet In oDoc.Sheets
	oSheet.Activate
	If oInput = True Then
		ActiveSheet.TitleBlock = "B SIZE"
	Else 
		ActiveSheet.TitleBlock = "D SIZE"
	End If
Next

'return to starting sheet
oCurrentNumber.Activate

'[ optional to collapse nodes

Dim oNode As BrowserNode 
For Each oNode In oDoc.BrowserPanes.ActivePane.TopNode.BrowserNodes
	' If the node is expanded, collapse it.
	If oNode.Expanded = True Then
		oNode.Expanded = False
	End If
Next
']

 

EESignature

Message 4 of 6

brow1372
Participant
Participant

Thanks for the reply.

Yes I am deleting all references and instances of the existing title blocks and that part works fine.

At the very end where it says

 

ThisDrawing.ResourceFileName = "z:\templates\HMC DRAWING.idw"


ActiveSheet = ThisDrawing.Sheet("Sheet:1")
ActiveSheet.TitleBlock = "HMCTITLE"
'ActiveSheet = ThisDrawing.Sheet("Sheet:2")
ActiveSheet.TitleBlock = "HMCTITLE"

 is where I want it to add the title block from the new resource file and what I show here works.

My goal is to make it work no matter how many sheets I have.

I have tried to put some of the examples into practice without much luck.

Clearly I am almost illiterate when it comes to Ilogic code writing so I just need a little hand holding for this last bit.

 

Thanks again.

0 Likes
Message 5 of 6

brow1372
Participant
Participant
Accepted solution

Ok I think I figured it out.

This is what I came up with taken from your first response.

 

SyntaxEditor Code Snippet

ThisDrawing.ResourceFileName = "z:\templates\HMC DRAWING.idw"


        Dim oCurrentNumber  As Sheet
oCurrentNumber = oDoc.ActiveSheet

        Dim oSheet1 As Sheet
        For Each oSheet1 In oDoc.Sheets
        oSheet1.Activate
                
            ActiveSheet.TitleBlock = "HMCTITLE"
            Next 

oCurrentNumber.Activate

Thanks again 

Message 6 of 6

Lennart_Losjo
Advocate
Advocate

Hi. Do you have this code working without problems?

Will you please provide the complete code for me?

 

Sorry if this thread is outdated.

Senior Product Specialist
Fusion 360, Inventor.