Replace Title Block, C#

Replace Title Block, C#

Anonymous
Not applicable
1,342 Views
1 Reply
Message 1 of 2

Replace Title Block, C#

Anonymous
Not applicable

Hi,

 

I am trying to replace the title block of the first sheet of the active drawing via C#. I currently am receiving the following error on the last line of code: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)). Very frustrating.

 

Any ideas as to why the code below is throwing this error? I have tried multiple variations of the code below to no avail and I'm sure this is something minor that I am overlooking. The title block definition under Drawing Resources is replaced with no errors, the title block on Sheet 1 is deleted just fine, but I can't seem to add a Title Block back in!

 

How Documents are defined:

 

Inventor._DrawingDocument oDoc = getDoc();
            Inventor.DrawingDocument sourceDoc = (DrawingDocument)instance.Documents.OpenWithOptions(sPath, options, false);

 Find, copy, replace:

TitleBlockDefinition tBlock = sourceDoc.TitleBlockDefinitions[blockList.SelectedItem.ToString()];
            TitleBlockDefinition newBlock = tBlock.CopyTo(oDoc, true);
            oDoc.Sheets[1].TitleBlock.Delete();
            oDoc.Sheets[1].AddTitleBlock(newBlock);

 Any help would be greatly appreciated.

 

Thanks,

Ben

0 Likes
1,343 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

Needed an Object cast.


oDoc.Sheets[1].AddTitleBlock((Object)newBlock);

 

Works fine now.

0 Likes