Results 1 to 9 of 9

Thread: Adding a new sheet using VSTA...

  1. #1
    100 Club FWSchreck's Avatar
    Join Date
    2000-12
    Posts
    177
    Login to Give a bone
    0

    Default Adding a new sheet using VSTA...

    Hello:

    I'm writing a VSTA routine to add sheets into the active project. I'm having trouble coming up with the code to set the proper titleblock family and type at sheet creation.

    Here's the code I have so far:

    Private Sub AddNewSheet(ByVal strSheetNumber As String, ByVal strSheetName As String)

    Dim p_Titleblock As FamilySymbol

    p_Titleblock.Family = "??"
    p_Titleblock.Name = "??"

    Dim myDetailSheet As ViewSheet = Me.Create.NewViewSheet(p_Titleblock)
    myDetailSheet.Name = strSheetName
    myDetailSheet.SheetNumber = strSheetNumber

    End Sub

    How can I specify the proper titleblock family and type for the NewViewSheet method?

  2. #2
    100 Club FWSchreck's Avatar
    Join Date
    2000-12
    Posts
    177
    Login to Give a bone
    0

    Thumbs up Re: Adding a new sheet using VSTA...

    All:

    After doing some digging, I came up with this:

    -----------------------------------------------------------------------------------

    Private Sub MakeNewSheet(ByVal strSheetNumber As String, ByVal strSheetName As String)

    Dim CurrentFamily As FamilySymbolSet = Me.TitleBlocks

    Dim p_Titleblock As FamilySymbol = Nothing

    For Each f As FamilySymbol In CurrentFamily
    If f IsNot Nothing Then
    p_Titleblock = f
    Exit For
    End If
    Next

    Dim myDetailSheet As ViewSheet = Me.Create.NewViewSheet(p_Titleblock)
    myDetailSheet.Name = strSheetName
    myDetailSheet.SheetNumber = strSheetNumber

    End Sub

    Public Sub AddNewSheet()
    MakeNewSheet("A2.01", "First Floor Plan")
    MakeNewSheet("A2.02", "Second Floor Plan")
    ' Add more sheets here
    End Sub

    --------------------------------------------------------------------------------------------------

    This seems to work properly. Does anyone have any suggestions for improvement?

  3. #3
    All AUGI, all the time cphubb's Avatar
    Join Date
    2003-11
    Location
    Seattle
    Posts
    691
    Login to Give a bone
    0

    Default Re: Adding a new sheet using VSTA...

    Fred,

    I tried your code out and am getting an error. VSTA is saying that 'TitleBlocks' is not a member of 'CreateSheets.ThisApplication' and'NewViewSheet' is not a member of 'Autodesk.Revit.Creation.Application

    I think I have all my references and imports correct. Did you do anythig to get these two classes imported?

    Thanks

  4. #4
    I could stop if I wanted to TroyGates's Avatar
    Join Date
    2015-08
    Location
    Irvine, CA
    Posts
    281
    Login to Give a bone
    0

    Default Re: Adding a new sheet using VSTA...

    If you created the macro as an application macro instead of a document macro you should change:

    Code:
    Dim CurrentFamily As FamilySymbolSet = Me.TitleBlocks
    to

    Code:
    Dim CurrentFamily As FamilySymbolSet = Me.ActiveDocument.TitleBlocks
    and

    Code:
    Dim myDetailSheet As ViewSheet = Me.Create.NewViewSheet(p_Titleblock)
    to

    Code:
    Dim myDetailSheet As ViewSheet = Me.ActiveDocument.Create.NewViewSheet(p_Titleblock)

    You also need to use the following imports:

    Code:
    Imports Autodesk.Revit.Symbols
    Imports Autodesk.Revit.Elements

  5. #5
    All AUGI, all the time cphubb's Avatar
    Join Date
    2003-11
    Location
    Seattle
    Posts
    691
    Login to Give a bone
    0

    Default Re: Adding a new sheet using VSTA...

    Troy,

    Thanks that fixed the build errors. However when I run the macros now they error with a general error "Attempt to modify the model outside of transaction" and then a number of error traces. Any idea why it builds but does not run? Finally after I tried to run the macro, I clicked back to the macro manager and Revit crashed.

  6. #6
    I could stop if I wanted to TroyGates's Avatar
    Join Date
    2015-08
    Location
    Irvine, CA
    Posts
    281
    Login to Give a bone
    0

    Default Re: Adding a new sheet using VSTA...

    I posted the changes without realizing it doesn't work as an application macro, only as a document macro. I'm not sure why the code works at the document level and not at the application level.

    Tried the following in Revit 2010 Application Macro and it gives the same error as you.
    Code:
        Private Sub MakeNewSheet(ByVal strSheetNumber As String, ByVal strSheetName As String)
            Dim doc As Document = Me.ActiveDocument
            Dim CurrentFamily As FamilySymbolSet = doc.TitleBlocks
            Dim p_Titleblock As FamilySymbol = Nothing
    
            For Each f As FamilySymbol In CurrentFamily
                If f IsNot Nothing Then
                    p_Titleblock = f
                    Exit For
                End If
            Next
    
            Dim myDetailSheet As ViewSheet = doc.Create.NewViewSheet(p_Titleblock)
            myDetailSheet.Name = strSheetName        
            myDetailSheet.SheetNumber = strSheetNumber
        End Sub
    
        Public Sub AddNewSheet()
            MakeNewSheet("A2.01", "First Floor Plan")
            MakeNewSheet("A2.02", "Second Floor Plan")
        End Sub
    Yet I try the same code in Revit 2009 Application Macro and it works fine.

    Something in Revit 2010 VSTA is different in accessing the title blocks from the Application level. I am not sure what it is, but I will try to figure it out.
    Last edited by TroyGates; 2009-07-14 at 11:36 PM.

  7. #7
    Member
    Join Date
    2007-09
    Posts
    2
    Login to Give a bone
    0

    Default Re: Adding a new sheet using VSTA...

    try to use :

    Code:
    Private Sub MakeNewSheet(ByVal strSheetNumber As String, ByVal strSheetName As String)
            Dim doc As Autodesk.Revit.Document = Application.ActiveDocument
            Dim CurrentFamily As Autodesk.Revit.Symbols.FamilySymbolSet = doc.TitleBlocks
            Dim p_Titleblock As Autodesk.Revit.Symbols.FamilySymbol = Nothing
    
            For Each f As Autodesk.Revit.Symbols.FamilySymbol In CurrentFamily
                If f IsNot Nothing Then
                    p_Titleblock = f
                    Exit For
                End If
            Next
    
            Dim myDetailSheet As Autodesk.Revit.Elements.ViewSheet = doc.Create.NewViewSheet(p_Titleblock)
            myDetailSheet.Name = strSheetName
            myDetailSheet.SheetNumber = strSheetNumber
        End Sub
    
        Public Sub AddNewSheet()
            MakeNewSheet("A2.01", "First Floor Plan")
            MakeNewSheet("A2.02", "Second Floor Plan")
        End Sub

  8. #8
    All AUGI, all the time cphubb's Avatar
    Join Date
    2003-11
    Location
    Seattle
    Posts
    691
    Login to Give a bone
    0

    Default Re: Adding a new sheet using VSTA...

    THAN,

    tried your modification. I see why it should work, because the application was not in scope for the active document and ME does not appear to work in that manner for 2010. However I am still getting the same error of being outside the transaction. I also went back to 2009 and tried the code both ways and it worked either way.

  9. #9
    Member
    Join Date
    2001-07
    Location
    Dallas
    Posts
    19
    Login to Give a bone
    0

    Default Re: Adding a new sheet using VSTA...

    In document level you have to begin and end the transactions, so in this case just a few tweaks to make this work as a Document Level Macro :

    Imports:
    Code:
    Imports Autodesk.Revit.Creation
    Imports Autodesk.Revit.Symbols
    Imports Autodesk.Revit.Elements
    Code:
        Private Sub MakeNewSheet(ByVal strSheetNumber As String, ByVal strSheetName As String)
    
            Me.ActiveDocument.BeginTransaction()
            Dim CurrentFamily As FamilySymbolSet = Me.ActiveDocument.TitleBlocks
            Dim p_Titleblock As FamilySymbol = Nothing
    
            For Each f As FamilySymbol In CurrentFamily
                If f IsNot Nothing Then
                    p_Titleblock = f
                    Exit For
                End If
            Next
    
            Dim myDetailSheet As ViewSheet = Me.ActiveDocument.Create.NewViewSheet(p_Titleblock)
            myDetailSheet.Name = strSheetName
            myDetailSheet.SheetNumber = strSheetNumber
    
            Me.ActiveDocument.EndTransaction()
        End Sub
    Calling the SUB:
    Code:
        Public Sub AddNewSheet()
            MakeNewSheet("A2.01", "First Floor Plan")
            MakeNewSheet("A2.02", "Second Floor Plan")
        End Sub

    of course you may want to wrap this bad boy in some Try-Catching if ya know what I mean!

Similar Threads

  1. Adding to a printed Mylar sheet
    By Chowdur in forum CAD Management - General
    Replies: 11
    Last Post: 2012-12-09, 04:34 AM
  2. Replies: 14
    Last Post: 2011-05-31, 07:43 PM
  3. If adding a new sheet within a sheet set
    By cadman_meg in forum AutoCAD Sheet Set Manager
    Replies: 0
    Last Post: 2008-07-29, 09:39 PM
  4. Adding images in a sheet's layout
    By p.vicini in forum Revit Architecture - General
    Replies: 14
    Last Post: 2005-10-18, 05:30 PM
  5. Adding to Sheet Sets *
    By scott.wilcox in forum AutoCAD Wish List
    Replies: 5
    Last Post: 2005-07-06, 02:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •