.NET

.NET

Reply
Active Contributor
110000474593
Posts: 29
Registered: ‎09-24-2012
Message 1 of 19 (594 Views)
Accepted Solution

WCF and Autocad P&ID, eNotApplicable error

594 Views, 18 Replies
07-14-2013 08:27 AM

Hello everyone,

 

I have a problem with implementing WCF in Autocad P&ID 2014. I've downloaded the trial version of P&ID 2014 to run some test with it. I want to talk to the Autcad application with an external windows aplication. With the help of this example, I've managed it to open Autocad with the external applicatoin. I also created some self made Commands by creating .dll files and NETLOAD them into Autocad. All works fine as I expected. After that, I want to use WCF to talk to the Autocad application. I watched the lesson of Paul Schleppy, which is recommanded in this discussion. I get the WCF service working in Autocad and I can send messages to it without any problems. The service is hosted inside autocad.

 

The only thing is: When I want to talk to the 'CurrentDocument' of Autocad, I get the following error: eNotApplicable. This error occurs for an example, when I want to send something to the editor of the CurrentDocument. But also when I want to open the database of the CurrentDocument. An expert on .NET programming with Autocad tells me this is because I want to use UI dependent functions on a background thread, which are only available on the UI thread. He said I must avoid this kind of functions. But that means I can't do anything with the CurrentDocument?? He also gave another solution. He says I have to store the UI SynchronizationContext at the startup of the host and then use the UI dependent functions with a 'Post' or 'Send'. But that isn't working either, I still get the eNotApplicable error.

 

He said the problem could be the trial version of Autocad P&ID 2014, because sometimes trail versions acting weird.

 

Now I'am curious: Do you have other solutions? Or do you have other experiences with WCF and Autocad and how do you work this out? I really want to make this working.

 

I have attached my Visual Studio solution. It contains three projects. One host, one service and one client (a little Winform app). I use VS2012 on a 64-bit laptop. Befor you build the soluton, make shure you change the IP adress in the 'Form1' class of the client. Once you build the solution, first NETLOAD the host in Autocad and then the service. Then use the following command: "AutoHostAutocadService". Now the service is listening. After that, you can attach youre VS to Autocad and the you can press F5 for debugging. A little winform app will start. Type something in the textbox and click the button. If you have set a breakpoint in the constructor of the 'FindTag' class, this breakpoint will hit. In the constructor, the eNotApplicable is raised by writing a message to the editor.

 

Please, can anyone help me?

Made some modifications to your service class: added a helper class clsFindTag that inherits from Control.  This seems to be working. Let me know if you have questions.

Active Contributor
110000474593
Posts: 29
Registered: ‎09-24-2012
Message 2 of 19 (559 Views)

Re: WCF and Autocad P&ID, eNotApplicable error

07-15-2013 02:17 AM in reply to: 110000474593

For clarity, this error only appears when I work with WCF. I don't get this error when I use my self made commands.

Valued Contributor
sszabo
Posts: 86
Registered: ‎09-05-2012
Message 3 of 19 (552 Views)

Re: WCF and Autocad P&ID, eNotApplicable error

07-15-2013 06:17 AM in reply to: 110000474593

You probably have to solve the multithreading issue I encountered when I was trying to do the same.  Check out this thread

Active Contributor
110000474593
Posts: 29
Registered: ‎09-24-2012
Message 4 of 19 (538 Views)

Re: WCF and Autocad P&ID, eNotApplicable error

07-15-2013 07:36 AM in reply to: sszabo

Hi sszabo,

 

Thanks for your reply. I already looked at that thread two weeks ago, but I didn't get it working. Maybe I'm going to look at it another time again.

Do you have it working now? You first also get the eNotApplicable error? Is there another way to use WCF with autocad or do you use the same way as I?

 

Thanks in advance.

Valued Contributor
sszabo
Posts: 86
Registered: ‎09-05-2012
Message 5 of 19 (531 Views)

Re: WCF and Autocad P&ID, eNotApplicable error

07-15-2013 08:34 AM in reply to: 110000474593

eNotApplicable just means you are trying to access the dwg DB from a service response which is running in a different thread than your IEXtensionApplication.

 

All you have to do is create a new VB class project and copy/paste the code into it, add the usual references, (make sure you remove double space ow attribute refs will not compile) , compile the DLL and it should netload and start the WCF service.  I am using this template for actual projects and it works.  If you get stuck let me know where, chances are I can help you out.

 

Here is the list of references you'll have to add to your project:

 

accoremgd

acdbmgd

acmgd

Autodesk.AutoCAD.Interop

Autodesk.AutoCAD.Interop.Common

System.Runtime.Serialization

System.ServiceModel

System.Windows.Forms

 

 

Valued Contributor
sszabo
Posts: 86
Registered: ‎09-05-2012
Message 6 of 19 (523 Views)

Re: WCF and Autocad P&ID, eNotApplicable error

07-15-2013 09:41 AM in reply to: 110000474593

BTW, I just downloaded and took a quick look at your code, I think now I remeber the issue, I struggled with it myself.  The bottom line: Editor access has to be from the main thread.  Again take a look at my logMessage function.

ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 7 of 19 (510 Views)

Re: WCF and Autocad P&ID, eNotApplicable error

07-15-2013 12:20 PM in reply to: sszabo

Use Dispatcher.beginInvoke()





Fenton Webb

Developer Technical Services

Autodesk Developer Network


Valued Contributor
sszabo
Posts: 86
Registered: ‎09-05-2012
Message 8 of 19 (504 Views)

Re: WCF and Autocad P&ID, eNotApplicable error

07-15-2013 12:43 PM in reply to: fenton.webb

I tried that like this, it didn't work for me (no exceptions, but never saw the message either)

 

                Action action = () =>
                {
                    fDocument.Editor.WriteMessage("Hello, this is FindTag : IFindTag");
                };
                Dispatcher.CurrentDispatcher.BeginInvoke(action);

Valued Contributor
sszabo
Posts: 86
Registered: ‎09-05-2012
Message 9 of 19 (495 Views)

Re: WCF and Autocad P&ID, eNotApplicable error

07-15-2013 01:18 PM in reply to: sszabo

I have to issue a correction to my earlier post!  (I am using Adam Nagy's solution for this) it's not that your call has to be in the main thread, rather it has to go through the Invoke method of a Control, at least that's what worked for me, but if you can make Fenton's idea work that certainly looks more elegant since your FindTag class won't even have to inherit from Control.

Active Contributor
110000474593
Posts: 29
Registered: ‎09-24-2012
Message 10 of 19 (486 Views)

Re: WCF and Autocad P&ID, eNotApplicable error

07-15-2013 11:59 PM in reply to: fenton.webb

Hi Fenton,

 

Thanks for your reply. I did a web search on 'Dispatcher.beginInvoke()'. Is it true that this used in WPF, and not in Winforms? Because in Winforms we have the 'Control.BeginInvoke' method. I can't use Dispatcher.beginInvoke() because there is no reference for Winforms called 'System.Windows.Threading'. Also adding the 'Windows.Base' reference isn't working. So how would I implement this?

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.