iLogic: Getting a parameter is incorrect error when I try to add a TitleBlockDefinition to a newly added sheet.

iLogic: Getting a parameter is incorrect error when I try to add a TitleBlockDefinition to a newly added sheet.

shizahkhalid
Contributor Contributor
371 Views
6 Replies
Message 1 of 7

iLogic: Getting a parameter is incorrect error when I try to add a TitleBlockDefinition to a newly added sheet.

shizahkhalid
Contributor
Contributor

 

 

    Dim oDoc As Document
    For Each oDoc in oActiveDoc.AllReferencedDocuments
        If oDoc.DocumentType = kAssemblyDocumentObject Then

            ' Add a new sheet
            Dim newSheet As Sheet
            newSheet = oDrgDoc.Sheets.Add()
    
            ' Apply the title block to the new sheet
            Dim templateTitleBlock As TitleBlockDefinition = oDrgDoc.TitleBlockDefinitions.Item("CPT A3 REV")

            Dim sPromptStrings(0 To 1) As String
            sPromptStrings(0) = "String 1"
            sPromptStrings(1) = "String 2"

            Dim activeSheet As Sheet
            activeSheet = oDrgDoc.ActiveSheet
            activeSheet.AddTitleBlock(templateTitleBlock, , sPromptStrings)

            newSheet.Name = oDoc.DisplayName
            
            ' Create the drawing for the assembly document on the new sheet
            CreateDrawing(oDoc, newSheet)
            iLogicVb.RunExternalRule("CreatePartsList")
        End If
    Next

 

 

For line 18, activeSheet.AddTitleBlock(templateTitleBlock, , sPromptStrings), I am getting the error "The parameter is incorrect". I don't understand why as the syntax and inputs are all as they should be. Please help!

0 Likes
372 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor

Hi @shizahkhalid.  At Line 18 your code may be working with a different Sheet object than the one you created on Line 7, which could be why it is throwing an error.  Just use that same 'newSheet' variable there, instead of trying to obtain the correct sheet again on Lines 16 & 17.  You can probably just delete Lines 16 & 17, then use the 'newSheet' variable on Line 18, instead of the 'activeSheet' variable.  Also, for performance reasons, it would be better to obtain a reference to the TitleBlockDefinition you want to use before you start that loop, because you do not need to 'get' it every time, just once.

Edit:  You may also need to add a line of code like the following:

newSheet.Activate

...at around Line 8 (after you add it), just to make ensure it is active before attempting to add the new TitleBlock instance to it.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 7

shizahkhalid
Contributor
Contributor

Thank you for the prompt response! I have made the changes you suggested, and am still getting the same error 😣.

    Dim templateTitleBlock As TitleBlockDefinition = oDrgDoc.TitleBlockDefinitions.Item("CPT A3 REV")

    Dim oDoc As Document
    For Each oDoc in oActiveDoc.AllReferencedDocuments
        If oDoc.DocumentType = kAssemblyDocumentObject Then

            ' Add a new sheet
            Dim newSheet As Sheet
            newSheet = oDrgDoc.Sheets.Add()

            Dim sPromptStrings(0 To 1) As String
            sPromptStrings(0) = "String 1"
            sPromptStrings(1) = "String 2"

            newSheet.AddTitleBlock(templateTitleBlock, , sPromptStrings)

            newSheet.Name = oDoc.DisplayName
            
            ' Create the drawing for the assembly document on the new sheet
            CreateDrawing(oDoc, newSheet)
            iLogicVb.RunExternalRule("CreatePartsList")
        End If
    Next

shizak_1977_0-1710517203060.png

shizak_1977_1-1710517226423.png

 

 

0 Likes
Message 4 of 7

WCrihfield
Mentor
Mentor

OK.  Is it possible that the new sheet already has a TitleBlock on it?  I know the Sheet.AddTitleBlock method says that it will simply replace any existing TitleBlock, but it seems like it has not always worked that way for everyone, maybe due to the presence of prompted entries in it.  Also, are you 100% sure that new TitleBlockDefinition has exactly 2 prompted entries in it?  I'm pretty sure the size of the array of strings needs to be the same size as the number of prompted entries in the TitleBlockDefinition, even though it does not mention that detail.  Try inserting the three lines of code after adding the new sheet, but before trying to add the new TitleBlock.

If newSheet.TitleBlock IsNot Nothing Then
	newSheet.TitleBlock.Delete
End If

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 7

shizahkhalid
Contributor
Contributor

I added that code snippet and still no luck. Is there some other way i can add new sheets so that they already contain the formatting of the original sheet in the drawing? 

I tested out the code as a separate rule and got a Type Mismatch error for the same line of code (line 27). And yes, I am certain the title block contains two prompted entries. 

Sub main()
    ' Set reference to active document. This assumes the active document is an assembly
    Dim oActiveDoc As Document
    oActiveDoc = ThisApplication.ActiveDocument

    strLocation = ThisApplication.FileOptions.TemplatesPath
    oDrgDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, strLocation & "CPT-DRAWING-TEMPLATE.idw")
	
	Dim oDoc As Document
    For Each oDoc In oActiveDoc.AllReferencedDocuments
        If oDoc.DocumentType = kAssemblyDocumentObject Then

            ' Add a new sheet
            Dim newSheet As Sheet
            newSheet = oDrgDoc.Sheets.Add()

            newSheet.Activate

            If newSheet.TitleBlock IsNot Nothing Then
                newSheet.TitleBlock.Delete
            End If

            Dim sPromptStrings(0 To 1) As String
            sPromptStrings(0) = "String 1"
            sPromptStrings(1) = "String 2"

            newSheet.AddTitleBlock(templateTitleBlock, , sPromptStrings)

            newSheet.Name = oDoc.DisplayName
            
        End If
    Next
	
End Sub

shizak_1977_0-1710520232551.png

 

shizak_1977_1-1710520248852.png

 

0 Likes
Message 6 of 7

WCrihfield
Mentor
Mentor

@shizahkhalid

In your new complete rule, you have not declared the 'templateTitleBlock' variable, nor set a value to it, so it would not be able to work yet.  Yes, there are one or two other ways to add a new sheet where the new sheet would already contain the Border, TitleBlock, notes, and even views in it, but not guaranteed to keep any dimensions.  The most common manual way would be to copy the previous sheet to the clipboard, then unselect that previous sheet, then paste that sheet from the clipboard back into your drawing.  This can be done by code too, but maybe just not as simple as it sounds.  The built-in way is by using a SheetFormat.  You could make sure you have a SheetFormat the way you want it, then use the Sheets.AddUsingSheetFormat method to create a new sheet based on that SheetFormat.  If the new sheet already has a TitleBlock instance on it, and it contains some prompted entries, then it provides a way to fill those in when you create the new sheet that way.  If the new sheet contained any views in it, then you would need to provide either the FullDocumentName or a model Document object as input when creating the new sheet, then that will be what the views are referencing in the new sheet.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 7

shizahkhalid
Contributor
Contributor

Ah, my bad! i declared templateTitleBlock now and am getting the same parameter incorrect error as before. So strange because its a simple enough rule. Going to give up on this now and create a SheetFormat. Thanks!

0 Likes