Inventor Customization

Reply
Active Contributor
desidubajic
Posts: 33
Registered: ‎04-28-2007
Message 1 of 6 (505 Views)
Accepted Solution

Replacing Title Block (odd error)

505 Views, 5 Replies
07-18-2012 02:27 PM

Inventor 2013 Add In code written in C#

 

I have managed to extract the "new" TitleBlockDefinition from my source drawing. (tblock)

 

I am trying to replace the title block definition in my active drawing with the "new" one.

 

Note. Both definitions have the same name, the only difference is that the logo has changed.

 

// I tried

DrawingDocument curDwg = (DrawingDocument)InvApp.ActiveDocument;

TitleBlockDefinition updatedTblock = tblock.CopyTo(curDwg, true);

 

This fails to compile because for some reason the CopyTo function expects a "_DrawingDocument" reference instead of the expected "DrawingDocument".

 

So I redefine curDwg to a _DrawingDocument and try again. This time the code compiles but unfortunately produces an error. Worse yet the error is vague.

 

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error

(Exception from HRESULT:00x80004005 (E_FAIL))

 

Any ideas? The code for replacing a title block is in the Inventor API help file, however in VB not C#.

 

I've resolved the issue. The mistake I made was prematurely closing the drawing that contained the source template. My C# code now works.

 

What made it frustrating, was due to the vague error code I focused on the wrong area. The one thing that threw me was that my dwg variable was a DrawingDocument, yet the CopyTo method required a "_DrawingDocument". In the end it was a simple matter of "NewTBlock = SrcTBlock.CopyTo((_DrawingDocument)CurDwg, True).

 

I had tried that before, but it didn't work of course because the src drawing was already closed pror to callling this function.

 

sigh .. oh well ... next hurdle.

 

Thanks to everyone who responded.

Mentor
krieg
Posts: 176
Registered: ‎11-22-2009
Message 2 of 6 (479 Views)

Re: Replacing Title Block (odd error)

07-24-2012 12:34 PM in reply to: desidubajic

Hello

 

Is there a titleblock on one of the drawingsheets basing on the titleblockdefinition you try to substitute? You try this with Inventor dwg, not IDW right? Maybe that's a difference.

Active Contributor
desidubajic
Posts: 33
Registered: ‎04-28-2007
Message 3 of 6 (474 Views)

Re: Replacing Title Block (odd error)

07-24-2012 01:14 PM in reply to: desidubajic

I am using Visual Studio 2010 professional.

 

The titleblock in the target drawing (.dwg) is the same name as the titleblock I am replacing it with.

They are identical, field by field. The only difference is that our logo has changed.

 

The problem appears to be C# specific.

In the sample code (Which is in Visual Basic) it seems pretty straight forward.

 

(SourcetitleBlockDefinition).CopyTo(TargetDocument, ReplaceExisting)

 

TargetDocument is a "DrawingDocument" object, and the second optional parameter is a Boolean indicating whether you want to overwrite "replace" an existing titleblockdefinition (I assume it should have the same name)

 

However attempting to use the same method in C# seems to be different.

 

TargetDocument is defined as an "Inventor._DrawingDocument". Note the leading underscore. Since I linked to the current document as a "Inventor.DrawingDocument" I can't even compile the code, since the two definitions are not identical.

 

If I link to the current document definining it as an "Inventor._DrawingDocument" then the code compiles however it generates the error (I mentioned in my previous post) when executed. I'm a little stymied as to what to do next.

Distinguished Contributor
psaarloos
Posts: 147
Registered: ‎12-09-2004
Message 4 of 6 (470 Views)

Re: Replacing Title Block (odd error)

07-24-2012 01:43 PM in reply to: desidubajic
Hi,

Did you already tried to use the 'Inventor Drawing Resource Transfer Wizard' which is available in the programs menu (Autodesk --> Inventor --> Tools)?

It does basically what you're trying to achieve I think..

Regards,
Pim Saarloos
Active Contributor
desidubajic
Posts: 33
Registered: ‎04-28-2007
Message 5 of 6 (455 Views)

Re: Replacing Title Block (odd error)

07-25-2012 11:09 PM in reply to: desidubajic

We are using Inventor 2013 with Vault Professional 2013

 

We have thousands of drawings, and many are "released" and locked away. I cannot batch process the drawings as changes would require updating released and revisioned drawings.

 

As we update assemblies, we modify any drawings we come across that have the old logo. It's not really a biig deal to do the change manually, I was just hoping to provide a simple one touch update.

 

I've rewritten the code in Visual Basic, however I am having the same error occur. In the sample it is updating an .idw file, and I am using .dwg files. Surely this isn't an issue.

 

Unspecified error (Exceptoin from HRESULT: 0x80004005 (E_FAIL)

 

This is such a simple thing, yet very frustrating. I'm just not sure what to do. (I guess abandon the idea, as I am wasting too much time on this)

Active Contributor
desidubajic
Posts: 33
Registered: ‎04-28-2007
Message 6 of 6 (445 Views)

Re: Replacing Title Block (odd error)

07-26-2012 08:12 AM in reply to: desidubajic

I've resolved the issue. The mistake I made was prematurely closing the drawing that contained the source template. My C# code now works.

 

What made it frustrating, was due to the vague error code I focused on the wrong area. The one thing that threw me was that my dwg variable was a DrawingDocument, yet the CopyTo method required a "_DrawingDocument". In the end it was a simple matter of "NewTBlock = SrcTBlock.CopyTo((_DrawingDocument)CurDwg, True).

 

I had tried that before, but it didn't work of course because the src drawing was already closed pror to callling this function.

 

sigh .. oh well ... next hurdle.

 

Thanks to everyone who responded.

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.