Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Replacing titleblocks, Code will only replace 1st and last page

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
Molly15
539 Views, 8 Replies

Replacing titleblocks, Code will only replace 1st and last page

I have put together some code from some pieces online. It is working well with one exception. It will only replace the 1st and last page titleblocks.

 

A little background. With our drawings we have a titleblock for page 1 and then we have a titleblock for page 2 and on. The code is replacing the 1st page with the correct (1st) page titleblock and the the last page with the correct (page2) titleblock. The titleblocks in the middle however are getting page 1 titleblocks. Any suggestions would be greatly appreciated. I am very new with iLogic so be gentile:-)

 

    Dim oDrawingDoc As Inventor.DrawingDocument
    Dim oSheetNumber As Integer
    Dim oActiveSheetNumber As Integer
    Dim oActiveSheetName As String    
    Dim oSheet As Sheet
    Dim oSourceTitleBlockDef As TitleBlockDefinition
    Dim oNewTitleBlockDef As TitleBlockDefinition

    oDrawingDoc = ThisApplication.ActiveDocument

    oActiveSheetName = ActiveSheet.Name

    oSheet = oDrawingDoc.ActiveSheet
    
    If (oSheet.TitleBlock.Name = "page1titleblock") Then
        oTitleBlockName = "page1titleblock"
    ElseIf (oSheet.TitleBlock.Name = "page2titleblock") Then
        oTitleBlockName = "page2titleblock"
     Else:
    End If

For oSheetNumber = 1 To oDrawingDoc.Sheets.Count
        oDrawingDoc.Sheets(oSheetNumber).Activate
        If Not oDrawingDoc.ActiveSheet.TitleBlock Is Nothing Then
            oDrawingDoc.ActiveSheet.TitleBlock.Delete
        End If
    Next oSheetNumber

    Dim oTitle As TitleBlockDefinition
    Dim oTitleBlock As TitleBlock
    
    For Each oTitle In oDrawingDoc.TitleBlockDefinitions
        If oTitle.IsReferenced = False Then
        oTitle.Delete
        End If
        Next
        
ThisDrawing.ResourceFileName = "path\to\Template\template.DWG"
ThisDrawing.KeepExtraResources = True

ActiveSheet.TitleBlock = "page1titleblock"
ActiveSheet.TitleBlock = "page2titleblock"

    oSheetNumber = 1
        oDrawingDoc.Sheets(oSheetNumber).Activate
        ActiveSheet.TitleBlock = oTitleBlockName

    oSheetNumber = 2 
        oDrawingDoc.Sheets(oSheetNumber).Activate
        ActiveSheet.TitleBlock = oTitleBlockName

 

Tags (1)
8 REPLIES 8
Message 2 of 9
NachitoMax
in reply to: Molly15

Hi

 

i havent read your code but you will need to itterate through the sheets and replace the titleblock independently. i have made a tool that does this and im in the process of making it into an addin. I will post a video very shortly for you see if it what you are trying to achieve

 

Thanks

 

Nigel

 

Nacho

Automation & Design Engineer

Inventor Programmer (C#, VB.Net / iLogic)


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.


Message 3 of 9
NachitoMax
in reply to: Molly15

Hi

 

See video attached

 

 

Thanks

 

 

Nacho

Automation & Design Engineer

Inventor Programmer (C#, VB.Net / iLogic)


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.


Message 4 of 9
GosponZ
in reply to: NachitoMax

Here is code i'm using to change TB in multi sheets .Make parameter for Border. Insert empty sheet with new TB and run rule . Delete empty sheet

I'm sure there is better way but this one working just fine.

 

For Each sheetX As Sheet In ThisDrawing.Document.Sheets

ThisDrawing.Sheet(sheetX.Name).TitleBlock = "Your TB"

iLogicVb.UpdateWhenDone = True

ThisApplication.ActiveView.Fit

Next

If Parameter("Border") = "Border" Then

ActiveSheet.Border = "Border"

End If

iLogicVb.UpdateWhenDone = True

Message 5 of 9
Molly15
in reply to: GosponZ

Thanks to all for your help and suggestions. The code is working:-)

Message 6 of 9
adam.nagy
in reply to: Molly15

Hi Molly,

 

Could you please mark the answer that helped as solution? 🙂

I think it's possible to mark multiple comments like that if you wish.

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 7 of 9
GosponZ
in reply to: adam.nagy

I can't see that option
Message 8 of 9
adam.nagy
in reply to: GosponZ

Hi,

 

Tha author of a thread can click "ACCEPT AS SOLUTION" on any comment made.

I also think this can be done on multiple comments of the same thread (if someone wants to) - I'm pretty sure I've seen a thread where multiple comments were greened out. 🙂

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 9 of 9
GosponZ
in reply to: adam.nagy

Hi Adam,
maybe Molly can. I do not see ,not in option drop menu, or button for accepting solution.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report