.Net Wrapper

.Net Wrapper

Anonymous
Not applicable
2,007 Views
13 Replies
Message 1 of 14

.Net Wrapper

Anonymous
Not applicable
I want to wrap a custom entity in a .Net wrapper class. I created the entity class with MFC support, but did not create it for .Net managed code support.

Can this be done, if so, what is the easiest method of doing so? I looked at the mgPoly class for an example, but I have to tell you, some of these examples confuse me more then anything. I am using VS 2005 with Acad 2007.

Any help or suggestions would be appreciated!

Mike B
0 Likes
2,008 Views
13 Replies
Replies (13)
Message 2 of 14

Anonymous
Not applicable
So, no answers huh?
Man, I wish I could become an ADN member. I am really getting tired of trying to figure everything out on my own. I have a really good idea, why doesn't Autodesk compile the ADN information, questions and answers, into a book and sell it for 99$ US. I would buy a copy....... honestly.

Come on, please, someone from Autodesk, give a desperate developer a hand. Arrrggghhh.....No chance there is a free membership for the ADN is there......The company I work for wouldn't pay for it because they are software developers, they have spent 80,000 $ this year on Autodesk products thought, that should count for something :)!! ahhh, didn't think so....

Alright, well, back to the drawing board, there has to be a way to figure this out....

Mike B
0 Likes
Message 3 of 14

Anonymous
Not applicable
Correction, "THE COMPANY I WORK FOR IS NOT A SOFTWARE DEVELOPEMENT COMPANY"... that is why they wouldn't pay for ADN......

Mike B
0 Likes
Message 4 of 14

pkohut-og
Contributor
Contributor
Really wish I could help here, but I don't do .Net Autocad. Keep slugging away. At some point it will click. When it does you'll be at a new level of programming. At some point that will also level out and you'll hit a brick wall again, for a while. Then 'click', and off to a new level. The cycle will repeat itself over and over.

FWIW...I find ADN useful only for the applications you'll be developing for. The web interface to the ADN discussion groups is poorly implemented, and finding information is often diffecult. This group is your best source.

Check out http://through-the-interface.typepad.com/ for some really good info .Net with Autocad.

Later,
Paul Kohut
0 Likes
Message 5 of 14

Anonymous
Not applicable
The thing about the ADN that makes it useful is the Dev Help Online - rather
than asking questions here, where people are helping you out of the goodness
of their hearts, you can ask AutoDesk themselves. If you have difficult
questions, they'll get elevated until you're talking to one of the head
technical guys. You're at least assured of a response. When they can't
answer your questions, you know that whatever workaround you've been
thinking about is going to be the best course of action.

Now, whether that makes it worth the price - maybe not. But if you're a
development company, or if you have to do a lot of internal development
(especially if it's on the bleeding edge), it should certainly be a
consideration.

-Rich


wrote in message news:5578145@discussion.autodesk.com...
Really wish I could help here, but I don't do .Net Autocad. Keep slugging
away. At some point it will click. When it does you'll be at a new level
of programming. At some point that will also level out and you'll hit a
brick wall again, for a while. Then 'click', and off to a new level. The
cycle will repeat itself over and over.

FWIW...I find ADN useful only for the applications you'll be developing for.
The web interface to the ADN discussion groups is poorly implemented, and
finding information is often diffecult. This group is your best source.

Check out http://through-the-interface.typepad.com/ for some really good
info .Net with Autocad.

Later,
Paul Kohut
0 Likes
Message 6 of 14

Anonymous
Not applicable
Paul Kohut wrote:

>> FWIW...I find ADN useful only for the applications you'll
>> be developing for. The web interface to the ADN discussion
>> groups is poorly implemented, and finding information is
>> often diffecult.

So, you know a Kabuki Dance when you see one, eh ? 🙂

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com
0 Likes
Message 7 of 14

Anonymous
Not applicable
A managed wrapper for a custom object is little more
than managed class that derives from one of the
managed wrapper classes exposed by AutoCAD, and
is housed in a mixed-mode assembly (e.g., /clr ) that
contains both managed and unmanaged code, and
relies heavily on implicit P/Invoke to call the native
custom object code from the managed wrapper code.

Your managed wrapper class must derive from the
managed wrapper class for the native class that
your native custom object derives from. For example,
if your custom object derives from AcDbCurve, then
your managed wrapper must derive from Autodesk::
AutoCAD::DatabaseServices::Curve. If your custom
object derives from AcDbEntity, your managed wrapper
must derive from ...DatabaseServices::Entity.

You must also apply the WrapperAttribute() to your
managed wrapper class, and specify the name of the
native custom object class that it wraps.

The other big piece of the puzzle is implementing
a factory (AcMgObjectFactory) which is a protocol
extension that you attach to your custom object's
AcRxClass. When the AutoCAD managed runtime
needs a wrapper for an instance of your custom
object, the factory will be called to create it.

However, doing this requires some experience writing
managed code; calling unmanaged code from managed
code; and doing that in managed C++ or C++/CLI,
rather than C# or VB. If you want to expose managed
events that get fired by native code, then things get a
bit more tricky.

So, can we assume that you've have the prerequisites?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5575077@discussion.autodesk.com...
I want to wrap a custom entity in a .Net wrapper class. I created the entity class with MFC support, but did not create it for .Net managed code support.

Can this be done, if so, what is the easiest method of doing so? I looked at the mgPoly class for an example, but I have to tell you, some of these examples confuse me more then anything. I am using VS 2005 with Acad 2007.

Any help or suggestions would be appreciated!

Mike B
0 Likes
Message 8 of 14

Anonymous
Not applicable
Well, I have not written any managed c++ or c++/CLI but I have written applications in c#. I cannot fathom why I could handle managed c++ or c++/CLI but you never know I guess until I try.

I tried creating a basic managed class to wrap the custom object, but I had alot of build errors. Don't remember what they were because I have deleted that project out of frusteration. I basically followed the mgPoly class.

Maybe I will try again with a basic custom entity derived from AcDbEntity that simply draws a line from start -> end point and try again.

Now when I create my custom entity, I shouldn't have to have the /clr option is that correct?

Ok, well, here I go, traversing up along the learning curve 🙂

Mike B
0 Likes
Message 9 of 14

Anonymous
Not applicable
Ok, well, I made yet a second attempt. I created the DBX and the managed wrapper class. I get several linker errors however, so I must be missing something.

The build log is attached as an HTML file. Can someone (Tony? maybe) look at it and possibly provide a hint?

Mike B
0 Likes
Message 10 of 14

Anonymous
Not applicable
Ok, Linker settings, all set, all compiled. WOW, getting somewhere.

Mike B
0 Likes
Message 11 of 14

Anonymous
Not applicable
Ok, so everything compiled fine. I also created a c# UI application with one command. I was successful at adding my custom object namespace etc.... but when I ran the application, it crashes. One thing it tells me is:
Application does not support just-in-time (JIT)
debugging.

Here was the "Exception Text"
[code]
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at ClassLibrary.Class.test()
[/code]

Now I am pretty sure this is a problem with the custom object, but have no idea what the problem would be. In my command I commented out the object creation and just sent a message to the editor and that worked fine.

Any suggestions on this?

Mike Bujak
0 Likes
Message 12 of 14

Anonymous
Not applicable
I believe the file not found means it wasn't able to find the module
containing the object you're trying to create. You may want to GAC your
managed wrapper so it knows where to find it.

gacutil.exe /i YourManagedWrapper.dll

Although i've written managed C++ and C#, i've not done much of that with
AutoCAD - it might not be necessary to GAC. Maybe your search paths aren't
all set correctly?

Also, i suggest you put in try catch blocks and catch those types of
errors - you will probably get more information than what is displayed in
the JIT error box.

-Rich


wrote in message news:5580043@discussion.autodesk.com...
Ok, so everything compiled fine. I also created a c# UI application with one
command. I was successful at adding my custom object namespace etc.... but
when I ran the application, it crashes. One thing it tells me is:
Application does not support just-in-time (JIT)
debugging.

Here was the "Exception Text"
[code]
System.Reflection.TargetInvocationException: Exception has been thrown by
the target of an invocation. ---> System.IO.FileNotFoundException: The
specified module could not be found. (Exception from HRESULT: 0x8007007E)
at ClassLibrary.Class.test()
[/code]

Now I am pretty sure this is a problem with the custom object, but have no
idea what the problem would be. In my command I commented out the object
creation and just sent a message to the editor and that worked fine.

Any suggestions on this?

Mike Bujak
0 Likes
Message 13 of 14

Anonymous
Not applicable
Thanks for the reply. I do have another question. I used NETLOAD to load the UI. Am I supposed to do this with my object wrapper dll as well? I ran NETLOAD on the wrapper dll and I get the same errors, but display in the autocad editor, so it probably isn't a case of not finding the wrapper object dll but a dll the wrapper class uses?

Mike B
0 Likes
Message 14 of 14

Anonymous
Not applicable
You don't need to NETLOAD if your managed wrapper is in a mixed mode DLL.
Don't forget to register the wrapper's class factory via AcMgObjectFactory.
This is how AutoCAD knows to instantiate your managed wrapper when it needs
to.


"MikeB_2K4" wrote in message news:5580423@discussion.autodesk.com...
Thanks for the reply. I do have another question. I used NETLOAD to load the
UI. Am I supposed to do this with my object wrapper dll as well? I ran
NETLOAD on the wrapper dll and I get the same errors, but display in the
autocad editor, so it probably isn't a case of not finding the wrapper
object dll but a dll the wrapper class uses?

Mike B
0 Likes