AddBaseView COM Exception

AddBaseView COM Exception

speterso
Contributor Contributor
678 Views
4 Replies
Message 1 of 5

AddBaseView COM Exception

speterso
Contributor
Contributor

Hello,

I've read many articles here about an AddBaseView error and none of them resulted in addressing my issue.  I will try to include as much detail I can about what I have tried and what the error is.

 

First the code, everyone likes code:

String TemplateFilename = m_InventorApp.FileOptions.TemplatesPath + "Standard.idw";

DrawingDocument OutDWGDoc = (DrawingDocument)m_InventorApp.Documents.Open(TemplateFilename, true);


OutDWGDoc.Activate(); // <-- this not usually done just wanted to ensure drawing was active after opening it

 

MessageBox.Show("Number of Sheets: " + OutDWGDoc.Sheets.Count.ToString()); // <-- this was added to check if sheet count was correct


Sheet OutDWGSheet = OutDWGDoc.Sheets[1]; // <-- in debugger this seems to not set sheet correctly, OutDWGSheet has no object referecable data when stepped over

 

PartDocument RouterPRTDoc = (PartDocument)m_InventorApp.Documents.Open(FullPartFileName.Replace(".ipt", "R.ipt"), true);

 

NameValueMap NameValMap = m_InventorApp.TransientObjects.CreateNameValueMap();
NameValMap.Add("SheetMetalFoldedModel", false);

 

TransientGeometry tgView = m_InventorApp.TransientGeometry;

 

// The below line is where the COM Exception gets caught
DrawingView DWGBaseView = OutDWGSheet.DrawingViews.AddBaseView((_Document)RouterPRTDoc, tgView.CreatePoint2d(DWGView.Left, DWGView.Top), 1/1, ViewOrientationTypeEnum.kDefaultViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle, "BaseViewForRouter", DWGView.Camera, NameValMap);

 

The TemplateFilename does point to a correct path "O:\\NetworkMachine\\SharedFolder\\<extra path info to folder>\\Standard.idw".

 

m_inventorApp is the inventor application.

 

See comments in above code for details on things I added to help debug issue and where issue occurs.

 

Here is the image of the error message returned from Inventor when plugin is executed.Error.PNG

 

 

 

 

 

 

 

 

 

 

 

We are using Inventor 2017, Autodesk Desktop App says Inventor 2017 is up to date, Addin is compiled using .NET 4.6.2 Framework, the plugin appears to register with Inventor correctly.

 

What is strange is this error is happening only on some machines.  We checked windows patches and Inventor patches and all are current.

 

Things we have tried:

  • I have attempted Both types of casting methods (ex Obj Blah = (Obj)function.Document...;  and Obj Blah = function.Document...  As Obj;  ) when opening the DrawingDocument and PartDocument.
  • This Addin was working without this error until we removed a Style from the Style sheet editor we created and did not need anymore.  After the save of the Template we have been getting this error.  We are able to open the Template and all looks good, we save the template etc. error still occurs.
  • We have tried moving the Template folder to the local C: drive and changed the template path in Inventor, error still occurs.
  • I have been compiling the Addin on Windows 10 computer and running Addin on Windows 7 computers.  Some work some don't.
  • We checked the Styles Editor Application in the start menu for Inventor to ensure the Style we deleted was not in there.

 

Can anyone help or think of something else we can try to fix this.  I am not sure what happened that triggered this issue, it seems strange though it happened with a Style Editor change one would not think it would break this Addin.

 

Thanks in advance

--

Shannon

 

 

 

 

 

0 Likes
679 Views
4 Replies
Replies (4)
Message 2 of 5

dgreatice
Collaborator
Collaborator

Hy,

 

I think you workflow are wrong.

 

1. Open Dwg, Activated

2. Set Object (OutDwgSheet)

3. Oper Part Document? this will be Active Document

4. Set Object (NameValMap)

5. Create Base View

 

see my example video at youtube.

https://www.youtube.com/watch?v=OobG6PLNsmM

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 3 of 5

speterso
Contributor
Contributor

I found the line of code causing the issue.

DrawingDocument OutDWGDoc = (DrawingDocument)m_InventorApp.Documents.Open(TemplateFilename, true);

Was causing the issue I changed it to

DrawingDocument OutDWGDoc = (DrawingDocument)m_InventorApp.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, TemplateFilename, false);

and it now runs on the client machines.

 

Anyone know what could be happening here?  Even though the issue is solved I am scratching my head understanding why this is even an issue.  All I did was instead of opening the document in the inventor instance I add the document to the inventor instance.

 

The strange thing is both work fine on my computers I personally tested on but the Open call fails on all of one of our clients machines but Add works fine for them.  What setting or configuration could be causing this?

0 Likes
Message 4 of 5

dgreatice
Collaborator
Collaborator

Hi,

 

I think addBaseView get error because, you active document are Part Document, not drawing document.

send it back drawing document  to active document.

 

your code:

PartDocument RouterPRTDoc = (PartDocument)m_InventorApp.Documents.Open(FullPartFileName.Replace(".ipt", "R.ipt"), true);

 

move this line after partdocument opened:

OutDWGDoc.Activate();

 

then:

DrawingView DWGBaseView = OutDWGSheet.DrawingViews.AddBaseView((_Document)RouterPRTDoc, tgView.CreatePoint2d(DWGView.Left, DWGView.Top), 1/1, ViewOrientationTypeEnum.kDefaultViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle, "BaseViewForRouter", DWGView.Camera, NameValMap);

 

 

 

 

 

 

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 5 of 5

speterso
Contributor
Contributor

I tried that as well, but thanks for the feedback.  I even moved the PartDocument Open line above everything else so when the Drawing Document is opened and activate right afterwards it would have Drawing Document as active document.

 

As stated a couple times, all versions of code work on my development computer and other test computers I have here.  Only our clients computers have problems running the code.  When I changes the Drawing Document Open command to Drawing Document Add command it fixed the clients machine and of course works on all my computers here.

 

I am just not understanding is why Open command would not work on this clients computers but the Add command works fine, especially when both work fine on my test computers at my location.

0 Likes