Edit TitleBlock Definition

Edit TitleBlock Definition

Anonymous
Not applicable
2,285 Views
21 Replies
Message 1 of 22

Edit TitleBlock Definition

Anonymous
Not applicable

Hi!

I'm currently editing titleblock definitions in .IDW files.

For some drawing documents, using the Definition.Edit() method leads to a crash (E_FAIL exception, System.RuntimeType.ForwardCallToInvokeMember problem).

 

The code I use is pretty straightforward so I guess there's something missing:

 

// sheet is active
var t = sheet.TitleBlock.Definition;

// t is not null 
// this call crashes sometimes againt some documents.
t.Edit(out DrawingSketch s);

What am I missing? What should I check before trying to edit the definition?

 

Thanks in advance for your help.

0 Likes
2,286 Views
21 Replies
Replies (21)
Message 2 of 22

bradeneuropeArthur
Mentor
Mentor

What program language are you using?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 22

bradeneuropeArthur
Mentor
Mentor

Try to do it this way:

for VBA

Public Sub main()

Dim CmdMan As ControlDefinition
    Set CmdMan = ThisApplication.CommandManager.ControlDefinitions.Item("DrawingTitleBlockEditCtxCmd")
    
    CmdMan.Execute
        
End Sub

For Ilogic:

Public Sub main()

Dim CmdMan As ControlDefinition
CmdMan = ThisApplication.CommandManager.ControlDefinitions.Item("DrawingTitleBlockEditCtxCmd")
    
    CmdMan.Execute
       
End Sub

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 4 of 22

Anonymous
Not applicable

My language is C# 🙂

0 Likes
Message 5 of 22

Anonymous
Not applicable

Thanks for taking time to answer.

I will try later and tell you how it goes.

0 Likes
Message 6 of 22

WCrihfield
Mentor
Mentor

I don't know if you are trying to delete any of the TitleBlockDefinitions or not durring your editing but, I know you have to check if the TitleBlockDefinition is being referenced before you can delete it.

It is considered referenced if it is being used on any of the sheets within the drawing.  Also, it commonly won't allow you to delete the default TitleBlockDefinition, for some reason.

The following iLogic code is one example of how to check this property.

If TitleBlockDefinition.IsReferenced = True Then

'you can't delete it

ElseIf TitleBlockDefinition.IsReferenced = False Then

'you can delete it

End If

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 22

Anonymous
Not applicable

Hi. Thanks for this.

But unfortunately, executing the command before editing does not change anything.

0 Likes
Message 8 of 22

Anonymous
Not applicable

Hi!

@WCrihfield> Thanks for your answer but I don't delete anything here, I just want to edit the titleblock. Still I checked this property and it's always set to true. But it does not seem to cause any problems regarding edition on other drawings. So I'm still stuck here...

 

Anyway thank you for your kind help.

0 Likes
Message 9 of 22

Anonymous
Not applicable

For info, here's the Exception :

> System.Runtime.InteropServices.COMException (0x80004005): Erreur non spécifiée (Exception de HRESULT : 0x80004005 (E_FAIL))
> System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
> Inventor.TitleBlockDefinition.Edit(DrawingSketch& Result)

Does it ring some bell?

0 Likes
Message 10 of 22

WCrihfield
Mentor
Mentor

I'm not familiar with C# coding, but here is the starting and ending portions of the code to edit a TitleBlockDefinition in iLogic.

 

All lines of code here starting with an ' apostrophe means it is commented out, and is just there to show you another example of how to the same thing.

 

You can either access the TitleBlockDefinition by digging down through the Sheet, then TitleBlock (as it looks like you were attempting to to), or you can access it by oDoc.TitleBlockDefinitions.Item(1), if its the first one.  Or you can replace the 1 with the quoted String name of it.

The first "Edit" line is a bit tricky, because it works more like a Get statement, than a invocation.

It acts as a Sub that returns the reference to a copy of the DrawingSketch within the TitleBlockDefinition for you.

Then you can use that reference as a variable to edit the sketch.

There's a long scrolling list of ways to edit the sketch, so I thought I'd leave that portion out for a later discussion, if needed.

When you're done editing the sketch, the ExitEdit line for the oTBDef, if you answer True, it saves your edited sketch back over the original, replacing it.  Or if you answer True, this () area offers a second optional setting, where you can specify a New Name As Object (but it can just be a String), and if you specify one, it then saves your edits as a new TitleBlockDefinition.

 

Dim oDoc As DrawingDocument = ThisDrawing.Document
'Dim oTBDefs As TitleBlockDefinitions = oDoc.TitleBlockDefinitions
'Dim oSheet As Sheet = oDoc.Sheets.Item(1)
Dim oSheet As Sheet = oDoc.ActiveSheet
Dim oTBDef As TitleBlockDefinition = oSheet.TitleBlock.Definition
Dim oTBDSketch As DrawingSketch
oTBDef.Edit(oTBDSketch)
'Now use oTBDSketch as your variable representing a DrawingSketch to Edit it. 'Then, when done, the following line saves your changes.
oTBDef.ExitEdit(True) 'Or, if you want to save it as a new TitleBlockDefinition, use the following line instead. 'oTBDef.ExitEdit(True,oNewNameAsString)

I don't know of a good way to translate this to C# for you.

I hope this helps.
If this solves your problem, or answers your questions, please click 'Accept As Solution".
Or, if this helps you reach your goal, please click 'LIKES" 👍.

Also, if you're interested, here are a few of the 'Ideas' I'd like to get implemented.
If you agree with any of them, please vote for them.

  • Options to format contents of MessageBox, InputBox, and InputListBox Click Here
  • Ability to fully constrain and dimension to the edjes of images within drawing title block sketches, SketchedSymbol sketches, other drawing sketches, and assembly sketches Click Here
  • Save section view status in DesignViewRepresentation, so it can be used in drawing view Click Here
  • Add SolidBodies folder to iLogic Rule Editor Model Tab Click Here
  • Convert all views to Raster before autosave stores to 'OldVersions' folder Click Here

Thanks, and best of luck in your future Inventor Customization endeavors.

Autodesk Inventor 2020 Online Help
Inventor Forum
Inventor Customization Forum
Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 11 of 22

Anonymous
Not applicable

Thanks for your help!

Well, I kind of use the same logic. And it often works.

But there are files I just can't edit and which throw the same COM Exception.

So, taking some perspective, I wonder if it wouldn't be related to the fact that these files come from Vault and may have some status that forbid any edition.

Maybe it could trigger some idea on your side?

 

Anyway, again, thank you very much for taking time to help me.

 

0 Likes
Message 12 of 22

WCrihfield
Mentor
Mentor

That's possible.  Unfortunately, I wouldn't be much help with matters concerning Vault, because my place of business has been putting off implementing it for years, mostly due to some coworkers fears of it causing additional slowdowns (based on their past experiences at other locations), and the local and corporate network configurations.

Hopefully someone with C# and Vault experience will come along and take an interest in your post, to further help you.

Best of luck.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 13 of 22

Anonymous
Not applicable

Thanks for your help.

I think that maybe the problem also exits for old Inventor files. Maybe if these files have not been updated since a quite older version (2015), we may have trouble getting some of their props?

0 Likes
Message 14 of 22

WCrihfield
Mentor
Mentor

If you're editing the textual content of you TitleBlockDefinition, keep in mind, it depends on how you set up those entries.  If you used Promted Attributes, then you would have to work with the Attributes of the TitleBlockDefinition.  Or if you set the entries by inserting iProperties, or Parameters, etc. with the Text Editor, then you would have to either change the iProperty, Parameter, or format your text entry the same way it is within the Text Editor when you insert those kinds of items.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 15 of 22

Anonymous
Not applicable

Thanks.

Yes I found that. And it's clearly an important thing to know.

Regarding my problem I think I will check if that changes if I update the files using Inventor 2020.

 

Thank you again for your help! If I find the answer I'll update this thread.

0 Likes
Message 16 of 22

Anonymous
Not applicable

Hi, I'm still stuck with the same problem after updating the .idw files and could not have the start of a rational explanation. Could someone at Autodesk have an idea?

 

Thanks!

0 Likes
Message 17 of 22

WCrihfield
Mentor
Mentor

Forum tip.  If you want to get the attention of specific Autodesk employee folks who frequently answer questions here on this forum, you could try mentioning their username with the @ sign in front of it like this:

@Anonymous 

That usually instantly notifies them that you mentioned them in a post, and they will most likely at least check it out.

Good luck.🙂

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 18 of 22

MICHAEL.JONES.AMCE
Advocate
Advocate

We are also experiencing problems using VB.net to edit/update/create title block definitions.  The VBA code seems to work w/o any problems.  The VB.net code is throwing an exception when we attempt to update the textbox formatted text.

 

    ' STEP 3.0: REPLACE THE VALUES FOR THE CUSTOM IPROPS IN THE TABLE DEFINITIONS
    Private Sub UpdateTitleBlock(tbDef As TitleBlockDefinition)
        ' <Property Document='drawing' PropertySet='User Defined Properties' Property='SHEET_1_SMALL_TITLE_2'

        If tbDef.Name = g_OriginalTBDefName Then
            Exit Sub
        End If

        Dim tb As TextBox
        Dim tbFormattedTxt As String
        Dim NewFormattedText As String = ""
        Dim NewText As String = ""
        Dim CheckTxt As String

        ' Get the Drawing sketch
        Dim tbDefSketch As DrawingSketch = tbDef.Sketch

        ' 1-LIBERTY-24X36
        Dim ShtNumber As String = tbDef.Name
        ShtNumber = Trim(ShtNumber.Split("-")(0))

        ' Overview:
        ' Search for the beginning of the field text string
        Dim ChkStr As String = "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"

        ' Open the edit process/routine
        tbDef.Edit(tbDefSketch)

        For i = 1 To tbDef.Sketch.TextBoxes.Count

            tb = tbDef.Sketch.TextBoxes.Item(i)
            tbFormattedTxt = tb.FormattedText

            'Debug.Print(tb.FormattedText)
            If tbFormattedTxt.Contains(ChkStr) Then
                ' strip off the vbCrLf from the end of the string
                CheckTxt = Replace(UpdateTxtBox(tbFormattedTxt, ShtNumber), vbCrLf, "")
                tb.FormattedText = CheckTxt
            End If

        Next i

        ' Exit the edit process
        tbDef.ExitEdit(True)

    End Sub

 

 

0 Likes
Message 19 of 22

WCrihfield
Mentor
Mentor

Hi @MICHAEL.JONES.AMCE.  You appear to be using some sort of custom method within your Replace() method called 'UpdateTxtBox', which appears to have two input variables.  What is that method doing in this situation?  Also, I see that you are setting a value to your variable called 'tbDefSketch' when you first create it.  That is unnecessary.  The variable gets a value assigned to it by the 'tbDef.Edit()' line.  I doubt that would cause any problem though.  Also, are you absolutely sure that it is finding the String value of 'vbCrLf' in that FormattedText?  There are multiple 'constants' that are similar to that, which represent very similar functionality/value.  You might benefit from enclosing that bit of code for replacing the FormattedText within a Try...Catch block to help 'handle' that possible error.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 20 of 22

MICHAEL.JONES.AMCE
Advocate
Advocate

The "UpdateTxtBox" method is replacing the values in the formatted text for the revised title block.

 

The VBA routine would add in the VBcrLF after I converted the XML doc back to a string and when then place that into the tb definition as extra lines in the text box.  So we were stripping them from the end of the converted string.

 

We had the routine working in VBA, and are trying to port it to VB.net and running into problems.

 

We are creating title block definitions for multiple sheets in the same drawing file and then revising the field text to access the correct iProps for each sheet.  Eleven custom iProps for each sheet. The custom iProps are also created dynamically before we create the new title block definitions.

 

 

   Private Function UpdateTxtBox(tbtxt As String, sNum As Integer) As String
        Dim xDoc As New XmlDocument
        Dim element As XElement
        Dim i As Integer
        Dim tbEdit As String = tbtxt
        Dim CurrentID, CurrentProp, NewID
        Dim NewProp As String = ""

        Dim tbArrayTxt() As String

        Dim PropCount As Integer = tbEdit.Contains(g_BRCode)
        Dim MultiFieldTxt As Boolean = False

        If PropCount > 0 Then ' we have more than a single field text
            tbArrayTxt = Split(tbEdit, g_BRCode)
            MultiFieldTxt = True
        End If

        Dim JoinTxt As String

        JoinTxt = Join(tbArrayTxt)

        If JoinTxt Is Nothing Then
            Array.Resize(tbArrayTxt, g_MaxPropsInFieldTxt)
            tbArrayTxt(0) = tbEdit
        End If

        For i = 0 To UBound(tbArrayTxt)
            If tbArrayTxt(i) <> "" Then
                Try
                    element = XElement.Parse(tbArrayTxt(i))
                    CurrentID = element.@PropertyID
                    CurrentProp = element.@Property

                    If CurrentProp = g_SheetIDProp Then
                        NewProp = Replace(CurrentProp, "1", sNum)
                    End If

                    If CurrentProp.Contains(g_SheetPattern) Then
                        NewProp = Replace(CurrentProp, "_1_", "_" & sNum & "_")
                    End If

                    If NewProp <> "" Then
                        NewID = ReturnCustPropID(NewProp)
                    Else ' iProp is not a multi-sheet iProp we can now exit
                        UpdateTxtBox = tbtxt
                        Exit Function
                    End If

                    If NewID = "" Then ' iProp does not exist
                        MsgBox("Error, missing multi-sheet iProperty", vbCritical)
                        UpdateTxtBox = tbtxt
                        Exit Function
                    End If

                    element.@Property = NewProp
                    element.@PropertyID = NewID

                    tbArrayTxt(i) = element.ToString
                    tbArrayTxt(i) = Replace(tbArrayTxt(i), CurrentProp, NewProp)
                   
                Catch
                    tbArrayTxt(i) = ""
                End Try

            End If
        Next

        If MultiFieldTxt Then
            UpdateTxtBox = Join(tbArrayTxt, g_BRCode)
        Else
            UpdateTxtBox = tbArrayTxt(0)
        End If

   End Function

 

 

 

0 Likes