Community
public static class SafeNativeMethods
{
[DllImport( "acdb17.dll", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acdbGetAdsName@@YA?AW4ErrorStatus@Acad@@AAY01JVAcDbObjectId@@@Z" )]
extern static public ErrorStatus acdbGetAdsName( out Int64 entres, ObjectId id );
[DllImport( "acad.exe", CallingConvention = CallingConvention.Cdecl )]
extern static IntPtr acdbEntGet( out Int64 e );
public static ResultBuffer EntGet( ObjectId id )
{
Int64 e;
if( acdbGetAdsName( out e, id ) == ErrorStatus.OK )
{
IntPtr res = acdbEntGet( out e );
if( res != IntPtr.Zero )
return ResultBuffer.Create( res, true );
}
return null;
}
}
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
"Tony Tanzillo" <
href="mailto:tony.tanzillo@THE_URL_BELOW.com">tony.tanzillo@THE_URL_BELOW.com>
wrote in message
href="news:5656222@discussion.autodesk.com">news:5656222@discussion.autodesk.com...
Hi Tim. For things like this where you don't have
an
API function in the release you're using, you can
drop
down to the legacy solution (the ObjectARX
equivalent
of the LISP (entget) function). In the code below,
you
need to change the name of the library (to
acdb16.dll)
in order to use this on AutoCAD 2006.
Call this function on the objectid of the object that has
the reactors on it, and it returns a
resultbuffer that is
the managed equvialent of the association list
that's
returned by the LISP (entget) function. You should
be
able to figure out what to do from there 🙂
[code]public static class SafeNativeMethods
{
[DllImport( "acdb17.dll", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acdbGetAdsName@@YA?AW4ErrorStatus@Acad@@AAY01JVAcDbObjectId@@@Z" )]
extern static public ErrorStatus acdbGetAdsName( out Int64 entres, ObjectId id );[DllImport( "acad.exe", CallingConvention = CallingConvention.Cdecl )]
extern static IntPtr acdbEntGet( out Int64 e );public static ResultBuffer EntGet( ObjectId id )
{
Int64 e;
if( acdbGetAdsName( out e, id ) == ErrorStatus.OK )
{
IntPtr res = acdbEntGet( out e );
if( res != IntPtr.Zero )
return ResultBuffer.Create( res, true );
}
return null;
}}
[/code]
AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting
AutoCAD 2000 through 2008
size=1>http://www.acadxtabs.com
<T.Willey> wrote in messageTony,
href="news:5654888@discussion.autodesk.com">
size=1>news:5654888@discussion.autodesk.com
size=1>...
If that is the only way, then
it looks like I can't do what I want in '06
with .Net, as there is no
method GetPersistentReactorIds() method for the
RasterImageDef
class.
Maybe I can figure out another way to do it.
Thanks for
your time and effort, it is appreciated.
--
Tim
"A blind man
lets nothing block his vision."
"Tony Tanzillo" <
href="mailto:tony.tanzillo@THE_URL_BELOW.com">
size=1>tony.tanzillo@THE_URL_BELOW.com> wrote in
message
size=1>news:5654798@discussion.autodesk.com...
Tim
- I didn't notice that GetReactors() has changed
in AutoCAD 2008. In
AutoCAD 2007 it does return a
DBObjectCollection, and that's the problem.
Not all
reactors are DBObjects, so that code isn't going to
work. In
AutoCAD 2008, GetReactors() returns a list
of RXObjects which is what it
should do.
Nonetheless, the method you should be calling is
not
GetReactors(), you should call GetPersistentReactorIds().
--
size=1>http://www.caddzone.com
AcadXTabs: MDI
Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through
2008
size=1>http://www.acadxtabs.com
size=1><T.Willey> wrote in message
href="news:5653143@discussion.autodesk.com">
size=1>news:5653143@discussion.autodesk.com...
I
can post the whole code, not a problem, I just didn't know if anyone
wanted
to see the whole thing.
I don't see a method for
GetPersistentReactorIds(), but in Reflector I do
see the GetReactors()
method. It says the GetReactors() method is inherited
from the
DBObject class. I just added a line to check to see if
the
RasterImageDef has a persistent reactor, and it showed
false.
Thanks for your help here Tony, I really appreciate
it.
--
Tim
"A blind man lets nothing
block his
vision."
"Tony Tanzillo" <
href="mailto:tony.tanzillo@THE_URL_BELOW.com">
size=1>tony.tanzillo@THE_URL_BELOW.com> wrote in
message
size=1>news:5653052@discussion.autodesk.com...
Hi
Tim.
You're describing a problem you're having, but you're
not
showing me the code where the problem is.
There's no 'GetReactor'
method, so I assumed you meant
the 'GetReactors' method, but the problem
there is that
GetReactors() doesn't return a DBObjectCollection.
I
can help if you post the relevant code, rather than
little bits and
pieces.
Off the t
op of my head, you should be calling
the
GetPersistentReactorIds() method, not GetReactors(),
since the
reactors you want are persistent.
--
href="http://www.caddzone.com">
size=1>http://www.caddzone.com
AcadXTabs: MDI
Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through
2008
size=1>http://www.acadxtabs.com
size=1><T.Willey> wrote in message
href="news:5652480@discussion.autodesk.com">
size=1>news:5652480@discussion.autodesk.com...
Hi
Tony,
I can't seem to get it to work even with the way you say
to go. I get the
same error message after I loop through with the
foreach l
oop. Here is the
code I tried, with all the variations I
tired. Am I doing something wrong?
Thanks for your help.
//try
{
foreach (DBObject dbo in dboc) {
//try {
if (dbo ==
null) throw new InvalidOperationException("null
DBObject");
//}
//catch {}
}
//}
//catch
(Autodesk.AutoCAD.Runtime.Exception AcadEr)
{
MessageBox.Show(AcadEr.Message); }
//catch (System.Exception ex) {
MessageBox.Show(ex.Message); }
MessageBox.Show("Done with
foreach");
for (int j = 0; j
< dboc.Count; ++j) {
DBObject
dbo = dbocas
DBObject;
MessageBox.Show(dbo.GetType().ToString());
}
--
Tim
"A blind man lets nothing block his vision."
"Tony
Tanzillo" <
size=1>tony.tanzillo@THE_URL_BELOW.com> wrote in
message
size=1>news:5652251@discussion.autodesk.com...
Hi
Tim.
Not long ago on this newsgroup, a bug was discovered
in the
indexer for DBObjectCollection.
You can't use it without first doing
this:
foreach( DBObject obj in yourDBObjectCollection
)
if( obj
== null
)
throw new
InvalidOperationException("null dbobject");
By calling foreach() on the
collection it forces the
creation of all DBObject wrappers. If you try to
use
the indexer without doing that first, it gets confused
and
kaboom.
So, just iterate over the collection usin something
like the
above first, then you can access the elements
via the indexer.
--
size=1>http://www.caddzone.com
AcadXTabs: MDI
Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through
2008
h
ttp://www.acadxtabs.com
<T.Willey> wrote in message
size=1>news:5651219@discussion.autodesk.com
size=1>...
Thanks Tony. Here is the routine I did to find the
information I want. I
don't think the formatting will show correctly,
so I'll post a file that has
the routine in it.
The problem is this
part.
try { DBObject dbo = dboc[0]; }
catch
(Autodesk.AutoCAD.Runtime.Exception AcadEr)
{
MessageBox.Show(AcadEr.Message); }
catch (System.Exception ex) {
MessageBox.Show(ex.Message); }
--
Tim
"A blind man
lets nothing block his vision."
"Tony Tanzillo" <
href="mailto:tony.tanzillo@T">tony.tanzillo@T
size=1>HE_URL_BELOW.com> wrote in message
href="news:5649956@discussion.autodesk.com">
size=1>news:5649956@discussion.autodesk.com
size=1>...
>> The problems is when I get the DBObjectCollection
returned, it
>> won't let me look at any of the objects within the
collection.
>> It errors out with "Attempted to read or wirte
protected menory.
Tim - Can't really guess about what your code is
doing, so if you
can post the relevant part, then maybe we can spot
something.
--
htt
p://www.caddzone.com
AcadXTabs: MDI
Document Tabs for AutoCAD 2008
Supporting A
utoCAD 2000 through
2008
size=1>http://www.acadxtabs.com
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
"Tony Tanzillo" <
href="mailto:tony.tanzillo@THE_URL_BELOW.com">tony.tanzillo@THE_URL_BELOW.com>
wrote in message
href="news:5656222@discussion.autodesk.com">news:5656222@discussion.autodesk.com...
Hi Tim. For things like this where you don't have
an
API function in the release you're using, you can
drop
down to the legacy solution (the ObjectARX
equivalent
of the LISP (entget) function). In the code below,
you
need to change the name of the library (to
acdb16.dll)
in order to use this on AutoCAD 2006.
Call this function on the objectid of the object that has
the reactors on it, and it returns a
resultbuffer that is
the managed equvialent of the association list
that's
returned by the LISP (entget) function. You should
be
able to figure out what to do from there 🙂
[code]public static class SafeNativeMethods
{
[DllImport( "acdb17.dll", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acdbGetAdsName@@YA?AW4ErrorStatus@Acad@@AAY01JVAcDbObjectId@@@Z" )]
extern static public ErrorStatus acdbGetAdsName( out Int64 entres, ObjectId id );[DllImport( "acad.exe", CallingConvention = CallingConvention.Cdecl )]
extern static IntPtr acdbEntGet( out Int64 e );public static ResultBuffer EntGet( ObjectId id )
{
Int64 e;
if( acdbGetAdsName( out e, id ) == ErrorStatus.OK )
{
IntPtr res = acdbEntGet( out e );
if( res != IntPtr.Zero )
return ResultBuffer.Create( res, true );
}
return null;
}}
[/code]
AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting
AutoCAD 2000 through 2008
size=1>http://www.acadxtabs.com
<T.Willey> wrote in messageTony,
href="news:5654888@discussion.autodesk.com">
size=1>news:5654888@discussion.autodesk.com
size=1>...
If that is the only way, then
it looks like I can't do what I want in '06
with .Net, as there is no
method GetPersistentReactorIds() method for the
RasterImageDef
class.
Maybe I can figure out another way to do it.
Thanks for
your time and effort, it is appreciated.
--
Tim
"A blind man
lets nothing block his vision."
"Tony Tanzillo" <
href="mailto:tony.tanzillo@THE_URL_BELOW.com">
size=1>tony.tanzillo@THE_URL_BELOW.com> wrote in
message
size=1>news:5654798@discussion.autodesk.com...
Tim
- I didn't notice that GetReactors() has changed
in AutoCAD 2008. In
AutoCAD 2007 it does return a
DBObjectCollection, and that's the problem.
Not all
reactors are DBObjects, so that code isn't going to
work. In
AutoCAD 2008, GetReactors() returns a list
of RXObjects which is what it
should do.
Nonetheless, the method you should be calling is
not
GetReactors(), you should call GetPersistentReactorIds().
--
size=1>http://www.caddzone.com
AcadXTabs: MDI
Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through
2008
size=1>http://www.acadxtabs.com
size=1><T.Willey> wrote in message
href="news:5653143@discussion.autodesk.com">
size=1>news:5653143@discussion.autodesk.com...
I
can post the whole code, not a problem, I just didn't know if anyone
wanted
to see the whole thing.
I don't see a method for
GetPersistentReactorIds(), but in Reflector I do
see the GetReactors()
method. It says the GetReactors() method is inherited
from the
DBObject class. I just added a line to check to see if
the
RasterImageDef has a persistent reactor, and it showed
false.
Thanks for your help here Tony, I really appreciate
it.
--
Tim
"A blind man lets nothing
block his
vision."
"Tony Tanzillo" <
href="mailto:tony.tanzillo@THE_URL_BELOW.com">
size=1>tony.tanzillo@THE_URL_BELOW.com> wrote in
message
size=1>news:5653052@discussion.autodesk.com...
Hi
Tim.
You're describing a problem you're having, but you're
not
showing me the code where the problem is.
There's no 'GetReactor'
method, so I assumed you meant
the 'GetReactors' method, but the problem
there is that
GetReactors() doesn't return a DBObjectCollection.
I
can help if you post the relevant code, rather than
little bits and
pieces.
Off the t
op of my head, you should be calling
the
GetPersistentReactorIds() method, not GetReactors(),
since the
reactors you want are persistent.
--
href="http://www.caddzone.com">
size=1>http://www.caddzone.com
AcadXTabs: MDI
Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through
2008
size=1>http://www.acadxtabs.com
size=1><T.Willey> wrote in message
href="news:5652480@discussion.autodesk.com">
size=1>news:5652480@discussion.autodesk.com...
Hi
Tony,
I can't seem to get it to work even with the way you say
to go. I get the
same error message after I loop through with the
foreach l
oop. Here is the
code I tried, with all the variations I
tired. Am I doing something wrong?
Thanks for your help.
//try
{
foreach (DBObject dbo in dboc) {
//try {
if (dbo ==
null) throw new InvalidOperationException("null
DBObject");
//}
//catch {}
}
//}
//catch
(Autodesk.AutoCAD.Runtime.Exception AcadEr)
{
MessageBox.Show(AcadEr.Message); }
//catch (System.Exception ex) {
MessageBox.Show(ex.Message); }
MessageBox.Show("Done with
foreach");
for (int j = 0; j
< dboc.Count; ++j) {
DBObject
dbo = dbocas
DBObject;
MessageBox.Show(dbo.GetType().ToString());
}
--
Tim
"A blind man lets nothing block his vision."
"Tony
Tanzillo" <
size=1>tony.tanzillo@THE_URL_BELOW.com> wrote in
message
size=1>news:5652251@discussion.autodesk.com...
Hi
Tim.
Not long ago on this newsgroup, a bug was discovered
in the
indexer for DBObjectCollection.
You can't use it without first doing
this:
foreach( DBObject obj in yourDBObjectCollection
)
if( obj
== null
)
throw new
InvalidOperationException("null dbobject");
By calling foreach() on the
collection it forces the
creation of all DBObject wrappers. If you try to
use
the indexer without doing that first, it gets confused
and
kaboom.
So, just iterate over the collection usin something
like the
above first, then you can access the elements
via the indexer.
--
size=1>http://www.caddzone.com
AcadXTabs: MDI
Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through
2008
h
ttp://www.acadxtabs.com
<T.Willey> wrote in message
size=1>news:5651219@discussion.autodesk.com
size=1>...
Thanks Tony. Here is the routine I did to find the
information I want. I
don't think the formatting will show correctly,
so I'll post a file that has
the routine in it.
The problem is this
part.
try { DBObject dbo = dboc[0]; }
catch
(Autodesk.AutoCAD.Runtime.Exception AcadEr)
{
MessageBox.Show(AcadEr.Message); }
catch (System.Exception ex) {
MessageBox.Show(ex.Message); }
--
Tim
"A blind man
lets nothing block his vision."
"Tony Tanzillo" <
href="mailto:tony.tanzillo@T">tony.tanzillo@T
size=1>HE_URL_BELOW.com> wrote in message
href="news:5649956@discussion.autodesk.com">
size=1>news:5649956@discussion.autodesk.com
size=1>...
>> The problems is when I get the DBObjectCollection
returned, it
>> won't let me look at any of the objects within the
collection.
>> It errors out with "Attempted to read or wirte
protected menory.
Tim - Can't really guess about what your code is
doing, so if you
can post the relevant part, then maybe we can spot
something.
--
htt
p://www.caddzone.com
AcadXTabs: MDI
Document Tabs for AutoCAD 2008
Supporting A
utoCAD 2000 through
2008
size=1>http://www.acadxtabs.com