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: 

Replace Title Block, C#

1 REPLY 1
Reply
Message 1 of 2
bennywise578
1198 Views, 1 Reply

Replace Title Block, C#

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

1 REPLY 1
Message 2 of 2
bennywise578
in reply to: bennywise578

Needed an Object cast.


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

 

Works fine now.

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

Post to forums  

Autodesk Design & Make Report