.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Rasterimage.Associaterasterdef ?? what's the deal with this

9 REPLIES 9
Reply
Message 1 of 10
cbertschy
961 Views, 9 Replies

Rasterimage.Associaterasterdef ?? what's the deal with this

I currently have code working that will grab an image stored on a local drive, create the rasterimagedef dictionary entry, create the raster image object, and display the image in autocad. The program works but there is no reactor link to the image and this is apparent as the xref/image manager shows that the added image entry has no references in the drawing. The drawing does have the image working... but clearly something is not linked correctly. I would normally post my code but I amaffraid it will be a garbled mess like the garbage I have been wading through to find something helpful since the forum update.

My code is very similar in structure to the attached link I found which has the same issue as my code is having. In fact, everything I have found online appears to have this same problem.
http://www.objectarx.net/bbs/viewthread.php?tid=2500 &ex tra=page%3D1

I have been trying to fix this by implimenting the rasterimage.AssociateRasterDef and stuffing the parameter with the new rasterimagedef() entry (both before and after the dictionary entry and transaction) with no luck. The mgd help is very vague on this and mentions that a RasterImageDefReactor must be constructed. I am still learning the C# api and language, with no background in c++ arx. A small example of using the AssociateRasterDef correctly would be very helpful.

Thanks,
Chris Bertschy

Side note: I typically post with OE, but I used the RTF web format for this one. It appears that the only way to get a readable post is to use the web rtf box. Are the users of newsgroup readers being punished??
9 REPLIES 9
Message 2 of 10
Anonymous
in reply to: cbertschy


Your code isn't calling RasterImage.AssociateImageDef(), which
is

what creates the reactor and adds it to
the RasterImageDef.

 


 

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000
through 2009

href="http://www.acadxtabs.com">http://www.acadxtabs.com

 


 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I
currently have code working that will grab an image stored on a local drive,
create the rasterimagedef dictionary entry, create the raster image object,
and display the image in autocad. The program works but there is no reactor
link to the image and this is apparent as the xref/image manager shows that
the added image entry has no references in the drawing. The drawing does have
the image working... but clearly something is not linked correctly. I would
normally post my code but I amaffraid it will be a garbled mess like the
garbage I have been wading through to find something helpful since the forum
update.

My code is very similar in structure to the attached link I
found which has the same issue as my code is having. In fact, everything I
have found online appears to have this same problem.

class=jive-link-external
href="http://www.objectarx.net/bbs/viewthread.php?tid=2500&extra=page...



I have been trying to fix this by implimenting the
rasterimage.AssociateRasterDef and stuffing the parameter with the new
rasterimagedef() entry (both before and after the dictionary entry and
transaction) with no luck. The mgd help is very vague on this and mentions
that a RasterImageDefReactor must be constructed. I am still learning the C#
api and language, with no background in c++ arx. A small example of using the
AssociateRasterDef correctly would be very helpful.

Thanks,
Chris
Bertschy

Side note: I typically post with OE, but I used the RTF web
format for this one. It appears that the only way to get a readable post is to
use the web rtf box. Are the users of newsgroup readers being
punished??
Message 3 of 10
Anonymous
in reply to: cbertschy


That is correct.  When I code something
like:

 

ri.associaterasterdef(rid);

 

I get an error in autocad that tells me the entry
does not exist in the database.

 

I am guessing that it is looking for a reactor id
that does not exist or that the raster image def is not being handle
properly.  My question is really where in the code would I put the call to
ri.associaterasterdef(rasterimagedef).  I found a small tid bit that
mentioned setting up a reactionid but nothing on how to handle this. 
Attached is my version.  It is a work in progress.  I am posting via
OE so I have no idea how this will look. 

 

Thanks, Tony. 






public

class
size=1>ACADutility
{





public
size=1>static
void
color=#191970 size=1>addimage

size=1>(
double
size=1>height
,
size=1>double
width,
Point3d p1,
size=1>Point3d p2
){









Document doc =
Application.
size=1>DocumentManager
.
size=1>MdiActiveDocument
;



Database db =
doc.
size=1>Database
;



Editor ed =
doc.
size=1>Editor
;



Transaction tr =
db.
size=1>TransactionManager
.
color=#191970 size=1>StartTransaction

size=1>();



DocumentLock doclock =
doc.
color=#191970 size=1>LockDocument
();



using
size=1>(
tr)


{





BlockTable bt =
(
BlockTable)
size=1>tr
.
size=1>GetObject
(
size=1>db
.
size=1>BlockTableId
,
size=1>OpenMode
.
size=1>ForRead
);


BlockTableRecord btr =
new
size=1>BlockTableRecord
();



btr = (
size=1>BlockTableRecord
)
size=1>tr
.
size=1>GetObject
(
size=1>bt
[
size=1>BlockTableRecord
.
size=1>ModelSpace
],
size=1>OpenMode
.
size=1>ForWrite
);




RasterImageDef rid =
new
size=1>RasterImageDef
();





ObjectId ImgDictID =
RasterImageDef
size=1>.
GetImageDictionary
color=#006400 size=1>(
db
size=1>);



if
size=1>(
ImgDictID
size=1>.
IsNull)


{



ImgDictID =
RasterImageDef
size=1>.

size=1>CreateImageDictionary
(
size=1>db
);




}




rid.
size=1>SourceFileName
=
color=#0000ff size=1>"c:\\temp\\gis-image-test.jpg"

size=1>;


rid.
size=1>ResolutionUnits
=
size=1>Unit
.
size=1>Foot
;


rid.
color=#191970 size=1>Load
();


rid.
color=#191970 size=1>OpenImage
();


rid.
color=#191970 size=1>UpdateEntities
();




DBDictionary imgdict
size=1>=(
DBDictionary
size=1>)
tr.
color=#191970 size=1>GetObject

size=1>(
ImgDictID,
OpenMode.
size=1>ForWrite
);



ObjectId rasterimdefid
size=1>;




rasterimdefid =
imgdict.
color=#191970 size=1>SetAt
(
color=#0000ff size=1>"image-SERVICE"
,
rid);





tr.
color=#191970 size=1>AddNewlyCreatedDBObject

size=1>(
rid,
true
size=1>);





RasterImage ri =
new
size=1>RasterImage
();
color=#008000 size=1>



RasterImageDef newimagedef
size=1>= (
RasterImageDef
size=1>)
tr.
color=#191970 size=1>GetObject

size=1>(
rid.
size=1>ObjectId
,
size=1>OpenMode
.
size=1>ForWrite
);// this was my last ditch
effort to get a raster image def to work. stuffing


//the original rid object into the method this not
work so I attempted to get update object after the image dictionary
update.  Not that this should mattre but I can't


//get it to work  upgrade open was something
ignorant that I also tried.  I had the ri.imagedfid = rid.objectid
commented out but still did not work.  all the


//example on the web show only this method being
used to link the raster image to the dictionary definition.  this does not
work correctly.  It does work to make the added image


//use the imagedefinition but does not add the
neccesary reactor info to recognize that the imagedef has references in the
drawing


newimagedef.
color=#191970>UpgradeOpen

size=1>();


ri.ImageDefId
color=#006400>=
rid.ObjectId

color=#006400>;


ri.
color=#191970>AssociateRasterDef

color=#006400>(
newimagedef

size=1>);



ri.Visible
color=#006400>=
true

color=#006400>;


ri.Orientation
color=#006400>=
new
color=#191970>CoordinateSystem3d

color=#006400>(
p1, new
Vector3d

color=#006400>(
width,
color=#00008b>0
,
color=#00008b>0
), new
Vector3d

color=#006400>(
0
color=#006400>,
height,
color=#00008b>0
));



 



btr.
color=#191970>AppendEntity

color=#006400>(
ri
);



tr.
color=#191970>AddNewlyCreatedDBObject

color=#006400>(
ri,
color=#008b8b>true
);
color=#008000>



tr.
color=#191970>Commit
();
color=#008000>



}



doclock.
color=#191970>Dispose

size=1>();



}


}




}


 


 



style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


Your code isn't calling RasterImage.AssociateImageDef(),
which is

what creates the reactor and adds it to
the RasterImageDef.

 


 

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000
through 2009

href="http://www.acadxtabs.com">http://www.acadxtabs.com

 


 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I
currently have code working that will grab an image stored on a local drive,
create the rasterimagedef dictionary entry, create the raster image object,
and display the image in autocad. The program works but there is no reactor
link to the image and this is apparent as the xref/image manager shows that
the added image entry has no references in the drawing. The drawing does
have the image working... but clearly something is not linked correctly. I
would normally post my code but I amaffraid it will be a garbled mess like
the garbage I have been wading through to find something helpful since the
forum update.

My code is very similar in structure to the attached
link I found which has the same issue as my code is having. In fact,
everything I have found online appears to have this same problem.

class=jive-link-external
href="http://www.objectarx.net/bbs/viewthread.php?tid=2500&extra=...



I have been trying to fix this by
implimenting the rasterimage.AssociateRasterDef and stuffing the parameter
with the new rasterimagedef() entry (both before and after the dictionary
entry and transaction) with no luck. The mgd help is very vague on this and
mentions that a RasterImageDefReactor must be constructed. I am still
learning the C# api and language, with no background in c++ arx. A small
example of using the AssociateRasterDef correctly would be very helpful.


Thanks,
Chris Bertschy

Side note: I typically post with
OE, but I used the RTF web format for this one. It appears that the only way
to get a readable post is to use the web rtf box. Are the users of newsgroup
readers being punished??
Message 4 of 10
Anonymous
in reply to: cbertschy


You don't pass any reactor id to
AssociateRasterDef().

 

You pass what the name of that method implies
(the

RasterImageDef object, which may need to be open

and write-enabled).

 

That's all there is to it. You don't need to deal
with

any reactors.


 

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000
through 2009

href="http://www.acadxtabs.com">http://www.acadxtabs.com

 


 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


That is correct.  When I code something
like:

 

ri.associaterasterdef(rid);

 

I get an error in autocad that tells me the entry
does not exist in the database.

 

I am guessing that it is looking for a reactor id
that does not exist or that the raster image def is not being handle
properly.  My question is really where in the code would I put the call
to ri.associaterasterdef(rasterimagedef).  I found a small tid bit that
mentioned setting up a reactionid but nothing on how to handle this. 
Attached is my version.  It is a work in progress.  I am posting via
OE so I have no idea how this will look. 

 

Thanks, Tony. 






public

class
size=1>ACADutility
{





public
size=1>static
void
color=#191970 size=1>addimage

size=1>(
double
size=1>height
,
size=1>double
width,
Point3d p1,
size=1>Point3d p2
){









Document doc =
Application.
size=1>DocumentManager
.
size=1>MdiActiveDocument
;



Database db =
doc.
size=1>Database
;



Editor ed =
doc.
size=1>Editor
;



Transaction tr =
db.
size=1>TransactionManager
.
color=#191970 size=1>StartTransaction

size=1>();



DocumentLock doclock
size=1>=
doc
size=1>.
LockDocument
color=#006400 size=1>();



using
size=1>(
tr)


{





BlockTable bt =
(
BlockTable)
size=1>tr
.
size=1>GetObject
(
size=1>db
.
size=1>BlockTableId
,
size=1>OpenMode
.
size=1>ForRead
);


BlockTableRecord btr
size=1>=
new
size=1>BlockTableRecord
();



btr = (
size=1>BlockTableRecord
)
size=1>tr
.
size=1>GetObject
(
size=1>bt
[
size=1>BlockTableRecord
.
size=1>ModelSpace
],
size=1>OpenMode
.
size=1>ForWrite
);




RasterImageDef rid =
new
size=1>RasterImageDef
();





ObjectId ImgDictID =
RasterImageDef
size=1>.

size=1>GetImageDictionary
(
size=1>db
);



if
size=1>(
ImgDictID
size=1>.
IsNull)


{



ImgDictID =
RasterImageDef
size=1>.

size=1>CreateImageDictionary

size=1>(
db);




}




rid.
size=1>SourceFileName
=
color=#0000ff size=1>"c:\\temp\\gis-image-test.jpg"

size=1>;


rid.
size=1>ResolutionUnits
=
size=1>Unit
.
size=1>Foot
;


rid.
color=#191970 size=1>Load
();


rid.
color=#191970 size=1>OpenImage
();


rid.
color=#191970 size=1>UpdateEntities

size=1>();




DBDictionary imgdict
size=1>=(
DBDictionary
size=1>)
tr
size=1>.
GetObject
color=#006400 size=1>(
ImgDictID
size=1>,
OpenMode
size=1>.
ForWrite);



ObjectId rasterimdefid
size=1>;




rasterimdefid =
imgdict.
color=#191970 size=1>SetAt
(
color=#0000ff size=1>"image-SERVICE"
,
rid);





tr.
color=#191970 size=1>AddNewlyCreatedDBObject

size=1>(
rid,
true
size=1>);





RasterImage ri =
new
size=1>RasterImage
();
color=#008000 size=1>



RasterImageDef newimagedef
size=1>= (
RasterImageDef
size=1>)
tr
size=1>.
GetObject
color=#006400 size=1>(
rid
size=1>.
ObjectId,
OpenMode.
size=1>ForWrite
);// this was my last ditch
effort to get a raster image def to work. stuffing


//the original rid object into the method this
not work so I attempted to get update object after the image dictionary
update.  Not that this should mattre but I can't


//get it to work  upgrade open was
something ignorant that I also tried.  I had the ri.imagedfid =
rid.objectid commented out but still did not work.  all the


//example on the web show only this method being
used to link the raster image to the dictionary definition.  this does
not work correctly.  It does work to make the added image


//use the imagedefinition but does not add the
neccesary reactor info to recognize that the imagedef has references in the
drawing


newimagedef.
color=#191970>UpgradeOpen

size=1>();


ri.ImageDefId
color=#006400>=
rid.ObjectId

color=#006400>;


ri.
color=#191970>AssociateRasterDef

color=#006400>(
newimagedef

size=1>);



ri.Visible
color=#006400>=
true

color=#006400>;


ri.Orientation
color=#006400>=
new
color=#191970>CoordinateSystem3d

color=#006400>(
p1,
color=#008b8b>new
Vector3d

size=1>(width,
color=#00008b>0
,
color=#00008b>0
), new
Vector3d

color=#006400>(
0
color=#006400>,
height,
color=#00008b>0
));



 



btr.
color=#191970>AppendEntity

color=#006400>(
ri
);



tr.
color=#191970>AddNewlyCreatedDBObject

color=#006400>(
ri,
color=#008b8b>true
);
color=#008000>



tr.
color=#191970>Commit

size=1>();



}



doclock.
color=#191970>Dispose

size=1>();



}


}




}


 


 



style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


Your code isn't calling RasterImage.AssociateImageDef(),
which is

what creates the reactor and adds it to
the RasterImageDef.

 


 

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD
2000 through 2009

href="http://www.acadxtabs.com">http://www.acadxtabs.com

 


 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I
currently have code working that will grab an image stored on a local
drive, create the rasterimagedef dictionary entry, create the raster image
object, and display the image in autocad. The program works but there is
no reactor link to the image and this is apparent as the xref/image
manager shows that the added image entry has no references in the drawing.
The drawing does have the image working... but clearly something is not
linked correctly. I would normally post my code but I amaffraid it will be
a garbled mess like the garbage I have been wading through to find
something helpful since the forum update.

My code is very similar
in structure to the attached link I found which has the same issue as my
code is having. In fact, everything I have found online appears to have
this same problem.

href="http://www.objectarx.net/bbs/viewthread.php?tid=2500&extra=page%3D1"
target=_new...


I have been trying to fix this by
implimenting the rasterimage.AssociateRasterDef and stuffing the parameter
with the new rasterimagedef() entry (both before and after the dictionary
entry and transaction) with no luck. The mgd help is very vague on this
and mentions that a RasterImageDefReactor must be constructed. I am still
learning the C# api and language, with no background in c++ arx. A small
example of using the AssociateRasterDef correctly would be very helpful.


Thanks,
Chris Bertschy

Side note: I typically post with
OE, but I used the RTF web format for this one. It appears that the only
way to get a readable post is to use the web rtf box. Are the users of
newsgroup readers being
punished??
Message 5 of 10
Anonymous
in reply to: cbertschy


   I have been trying to pass the
object rasterimagedef object with no results.  It continues to throw the
eNotinDatabase exception.  There is another  method used as a switch
called enablereactors().  Should i refrain from telling the transaction
manager to add the newly created rasterimagedef until the new raster image has
called the associaterasterdef... or does it not really matter.  I can't
tell if this is causing the problem.  I have tried it both ways and the
associaterasterdef() method will not work with the rasterimagedef.  Do I
have to fully commit() the transaction and start a new transaction before I
can attempt to feed it as a database object into the associate
method?

 

cbertschy


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


You don't pass any reactor id to
AssociateRasterDef().

 

You pass what the name of that method implies
(the

RasterImageDef object, which may need to be
open

and write-enabled).

 

That's all there is to it. You don't need to deal
with

any reactors.


 

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000
through 2009

href="http://www.acadxtabs.com">http://www.acadxtabs.com

 


 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


That is correct.  When I code something
like:

 

ri.associaterasterdef(rid);

 

I get an error in autocad that tells me the
entry does not exist in the database.

 

I am guessing that it is looking for a reactor
id that does not exist or that the raster image def is not being handle
properly.  My question is really where in the code would I put the call
to ri.associaterasterdef(rasterimagedef).  I found a small tid bit that
mentioned setting up a reactionid but nothing on how to handle this. 
Attached is my version.  It is a work in progress.  I am posting
via OE so I have no idea how this will look. 

 

Thanks, Tony. 






public

class
size=1>ACADutility
{





public
color=#a52a2a size=1>static
void
addimage
size=1>(
double
size=1>height
,
color=#ff0000 size=1>double
width
color=#006400 size=1>,
Point3d p1
color=#006400 size=1>,
Point3d p2
color=#006400 size=1>){









Document doc =
Application
size=1>.
DocumentManager
size=1>.
MdiActiveDocument
size=1>;



Database db =
doc.
size=1>Database
;



Editor ed =
doc.
size=1>Editor
;



Transaction tr =
db.
size=1>TransactionManager
.
color=#191970 size=1>StartTransaction

size=1>();



DocumentLock doclock
size=1>=
doc
size=1>.
LockDocument
color=#006400 size=1>();



using
size=1>(
tr)


{





BlockTable bt =
(
BlockTable
size=1>)
tr
size=1>.
GetObject
color=#006400 size=1>(
db
size=1>.
BlockTableId,
OpenMode.
size=1>ForRead
);


BlockTableRecord btr
size=1>=
new
size=1>BlockTableRecord
();



btr = (
size=1>BlockTableRecord
)
size=1>tr
.
size=1>GetObject
(
size=1>bt
[
size=1>BlockTableRecord
.
size=1>ModelSpace
],
size=1>OpenMode
.
size=1>ForWrite
);




RasterImageDef rid
size=1>=
new
size=1>RasterImageDef
();





ObjectId ImgDictID
size=1>=
RasterImageDef
size=1>.

size=1>GetImageDictionary
(
size=1>db
);



if
size=1>(
ImgDictID
size=1>.
IsNull)


{



ImgDictID =
RasterImageDef
size=1>.

size=1>CreateImageDictionary

size=1>(
db);




}




rid.
size=1>SourceFileName
=
color=#0000ff size=1>"c:\\temp\\gis-image-test.jpg"

color=#006400 size=1>;


rid.
size=1>ResolutionUnits
=
size=1>Unit
.
size=1>Foot
;


rid.
color=#191970 size=1>Load
();


rid.
color=#191970 size=1>OpenImage
();


rid.
color=#191970 size=1>UpdateEntities

size=1>();




DBDictionary imgdict
size=1>=(
DBDictionary
size=1>)
tr
size=1>.
GetObject
color=#006400 size=1>(
ImgDictID
color=#006400 size=1>,
OpenMode
color=#006400 size=1>.
ForWrite
size=1>);



ObjectId rasterimdefid
size=1>;




rasterimdefid =
imgdict
size=1>.
SetAt
color=#006400 size=1>(

size=1>"image-SERVICE"
,
size=1>rid
);





tr.
color=#191970 size=1>AddNewlyCreatedDBObject

size=1>(
rid,
true
size=1>);





RasterImage ri =
new
size=1>RasterImage
();
color=#008000 size=1>



RasterImageDef newimagedef
size=1>= (
RasterImageDef
size=1>)
tr
size=1>.
GetObject
color=#006400 size=1>(
rid
size=1>.
ObjectId,
OpenMode.
size=1>ForWrite
);// this was my last ditch
effort to get a raster image def to work. stuffing


//the original rid object into the method this
not work so I attempted to get update object after the image dictionary
update.  Not that this should mattre but I can't


//get it to work  upgrade open was
something ignorant that I also tried.  I had the ri.imagedfid =
rid.objectid commented out but still did not work.  all the


//example on the web show only this method
being used to link the raster image to the dictionary definition.  this
does not work correctly.  It does work to make the added
image


//use the imagedefinition but does not add the
neccesary reactor info to recognize that the imagedef has references in the
drawing


newimagedef.
color=#191970>UpgradeOpen

size=1>();


ri.ImageDefId
color=#006400>=
rid.ObjectId

color=#006400>;


ri.
color=#191970>AssociateRasterDef

color=#006400>(
newimagedef

size=1>);



ri.Visible
color=#006400>=
true

color=#006400>;


ri.Orientation
color=#006400>=
new
color=#191970>CoordinateSystem3d

color=#006400>(
p1,
color=#008b8b>new
Vector3d

size=1>(width,
color=#00008b>0
,
color=#00008b>0
),
color=#008b8b>new
Vector3d

size=1>(0
color=#006400>,
height,
color=#00008b>0
));



 



btr.
color=#191970>AppendEntity

color=#006400>(
ri

size=1>);



tr.
color=#191970>AddNewlyCreatedDBObject

color=#006400>(
ri,
color=#008b8b>true

size=1>);



tr.
color=#191970>Commit

size=1>();



}



doclock.
color=#191970>Dispose

size=1>();



}


}




}


 


 



style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


Your code isn't calling RasterImage.AssociateImageDef(),
which is

what creates the reactor and adds it to
the RasterImageDef.

 


 

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD
2000 through 2009

href="http://www.acadxtabs.com">http://www.acadxtabs.com

 


 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I
currently have code working that will grab an image stored on a local
drive, create the rasterimagedef dictionary entry, create the raster
image object, and display the image in autocad. The program works but
there is no reactor link to the image and this is apparent as the
xref/image manager shows that the added image entry has no references in
the drawing. The drawing does have the image working... but clearly
something is not linked correctly. I would normally post my code but I
amaffraid it will be a garbled mess like the garbage I have been wading
through to find something helpful since the forum update.

My
code is very similar in structure to the attached link I found which has
the same issue as my code is having. In fact, everything I have found
online appears to have this same problem.

class=jive-link-external
href="http://www.objectarx.net/bbs/viewthread.php?tid=250...



I have been trying to fix this by
implimenting the rasterimage.AssociateRasterDef and stuffing the
parameter with the new rasterimagedef() entry (both before and after the
dictionary entry and transaction) with no luck. The mgd help is very
vague on this and mentions that a RasterImageDefReactor must be
constructed. I am still learning the C# api and language, with no
background in c++ arx. A small example of using the AssociateRasterDef
correctly would be very helpful.

Thanks,
Chris
Bertschy

Side note: I typically post with OE, but I used the RTF
web format for this one. It appears that the only way to get a readable
post is to use the web rtf box. Are the users of newsgroup readers being
punished??
Message 6 of 10
Anonymous
in reply to: cbertschy


This works for me:

 

{code}

 

// Requires a reference to System.Windows.Forms

 

using System;
using System.Collections.Generic;
using
System.Text;
using Autodesk.AutoCAD.Runtime;
using
Autodesk.AutoCAD.ApplicationServices;
using
Autodesk.AutoCAD.EditorInput;
using
Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using
System.Windows.Forms;
using System.IO;
using Acad =
Autodesk.AutoCAD.ApplicationServices.Application;

 

[assembly: CommandClass( typeof( RasterImageSample.Commands )
)]

 

namespace RasterImageSample
{
   public class
Commands
   {
      [CommandMethod(
"RASTER_SAMPLE" )]
      public static void
RasterCommand()
     
{
         Document doc =
Acad.DocumentManager.MdiActiveDocument;
        
OpenFileDialog ofd = new
OpenFileDialog();
         ofd.Filter
= "JPeg Files|*.jpg|Gif Files|*.gif|PNG
Files|*.png";
        
ofd.FilterIndex = 0;
        
ofd.Title = "Select Image File";

 

         if(
ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK
)
        
{
            string
filename =
ofd.FileName;
           
using( Transaction trans = doc.TransactionManager.StartTransaction()
)
           
{
              
ObjectId idModel =
SymbolUtilityServices.GetBlockModelSpaceId(doc.Database);
              
BlockTableRecord ms = trans.GetObject( idModel, OpenMode.ForWrite) as
BlockTableRecord;
              
RasterImageDef imageDef = AddImageDef( doc.Database, trans, filename
);
              
if( imageDef != null
)
              
{
                 
RasterImage image = new
RasterImage();
                 
image.ImageDefId =
imageDef.ObjectId;
                 
ObjectId imageId = ms.AppendEntity( image
);
                 
if( imageId.IsNull
)
                    
throw new Autodesk.AutoCAD.Runtime.Exception( ErrorStatus.NullObjectId
);
                 
trans.AddNewlyCreatedDBObject( image, true
);
                 
RasterImage.EnableReactors( true
);
                 
image.AssociateRasterDef( imageDef
);
                 
Point3d origin = (Point3d) Acad.GetSystemVariable( "VIEWCTR"
);
                 
image.Orientation = new CoordinateSystem3d( origin, Vector3d.XAxis,
Vector3d.YAxis);
              
}
              
trans.Commit();
           
}
        
}
      }

 

      public static RasterImageDef
AddImageDef( Database db, Transaction trans, string imageFilespec
)
     
{
         if( !File.Exists(
imageFilespec )
)
            throw
new FileNotFoundException( imageFilespec
);
         ObjectId idImageDict =
RasterImageDef.GetImageDictionary( db
);
         if( idImageDict.IsNull
)
           
idImageDict = RasterImageDef.CreateImageDictionary( db
);
         if( idImageDict.IsNull
)
            throw
new InvalidOperationException( "failed to get or create image dictionary"
);

 

         DBDictionary
imageDictionary = trans.GetObject( idImageDict, OpenMode.ForRead ) as
DBDictionary;
         if(
imageDictionary == null
)
            throw
new InvalidOperationException( "Failed to open image dictionary" );

 

        
RasterImageDef imageDef = new
RasterImageDef();
        
imageDef.SourceFileName =
imageFilespec;
        
imageDef.Load();

 

         String name =
RasterImageDef.SuggestName( imageDictionary, imageFilespec );

 

        
imageDictionary.UpgradeOpen();
        
ObjectId idEntry = imageDictionary.SetAt( name, imageDef
);
        
imageDictionary.DowngradeOpen();

 

         if(
idEntry.IsNull )
        
{
           
imageDef.Dispose();
           
imageDef =
null;
           
throw new InvalidOperationException( "Failed to add image definition to image
dictionary" );
        
}

 

        
trans.AddNewlyCreatedDBObject( imageDef, true );

 

         return
imageDef;
      }
  
}
}

 

{code}


 

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000
through 2009

href="http://www.acadxtabs.com">http://www.acadxtabs.com

 


 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


That is correct.  When I code something
like:

 

ri.associaterasterdef(rid);

 

I get an error in autocad that tells me the entry
does not exist in the database.

 

I am guessing that it is looking for a reactor id
that does not exist or that the raster image def is not being handle
properly.  My question is really where in the code would I put the call
to ri.associaterasterdef(rasterimagedef).  I found a small tid bit that
mentioned setting up a reactionid but nothing on how to handle this. 
Attached is my version.  It is a work in progress.  I am posting via
OE so I have no idea how this will look. 

 

Thanks, Tony. 






public

class
size=1>ACADutility
{





public
size=1>static
void
color=#191970 size=1>addimage

size=1>(
double
size=1>height
,
size=1>double
width,
Point3d p1,
size=1>Point3d p2
){









Document doc =
Application.
size=1>DocumentManager
.
size=1>MdiActiveDocument
;



Database db =
doc.
size=1>Database
;



Editor ed =
doc.
size=1>Editor
;



Transaction tr =
db.
size=1>TransactionManager
.
color=#191970 size=1>StartTransaction

size=1>();



DocumentLock doclock
size=1>=
doc
size=1>.
LockDocument
color=#006400 size=1>();



using
size=1>(
tr)


{





BlockTable bt =
(
BlockTable)
size=1>tr
.
size=1>GetObject
(
size=1>db
.
size=1>BlockTableId
,
size=1>OpenMode
.
size=1>ForRead
);


BlockTableRecord btr
size=1>=
new
size=1>BlockTableRecord
();



btr = (
size=1>BlockTableRecord
)
size=1>tr
.
size=1>GetObject
(
size=1>bt
[
size=1>BlockTableRecord
.
size=1>ModelSpace
],
size=1>OpenMode
.
size=1>ForWrite
);




RasterImageDef rid =
new
size=1>RasterImageDef
();





ObjectId ImgDictID =
RasterImageDef
size=1>.

size=1>GetImageDictionary
(
size=1>db
);



if
size=1>(
ImgDictID
size=1>.
IsNull)


{



ImgDictID =
RasterImageDef
size=1>.

size=1>CreateImageDictionary

size=1>(
db);




}




rid.
size=1>SourceFileName
=
color=#0000ff size=1>"c:\\temp\\gis-image-test.jpg"

size=1>;


rid.
size=1>ResolutionUnits
=
size=1>Unit
.
size=1>Foot
;


rid.
color=#191970 size=1>Load
();


rid.
color=#191970 size=1>OpenImage
();


rid.
color=#191970 size=1>UpdateEntities

size=1>();




DBDictionary imgdict
size=1>=(
DBDictionary
size=1>)
tr
size=1>.
GetObject
color=#006400 size=1>(
ImgDictID
size=1>,
OpenMode
size=1>.
ForWrite);



ObjectId rasterimdefid
size=1>;




rasterimdefid =
imgdict.
color=#191970 size=1>SetAt
(
color=#0000ff size=1>"image-SERVICE"
,
rid);





tr.
color=#191970 size=1>AddNewlyCreatedDBObject

size=1>(
rid,
true
size=1>);





RasterImage ri =
new
size=1>RasterImage
();
color=#008000 size=1>



RasterImageDef newimagedef
size=1>= (
RasterImageDef
size=1>)
tr
size=1>.
GetObject
color=#006400 size=1>(
rid
size=1>.
ObjectId,
OpenMode.
size=1>ForWrite
);// this was my last ditch
effort to get a raster image def to work. stuffing


//the original rid object into the method this
not work so I attempted to get update object after the image dictionary
update.  Not that this should mattre but I can't


//get it to work  upgrade open was
something ignorant that I also tried.  I had the ri.imagedfid =
rid.objectid commented out but still did not work.  all the


//example on the web show only this method being
used to link the raster image to the dictionary definition.  this does
not work correctly.  It does work to make the added image


//use the imagedefinition but does not add the
neccesary reactor info to recognize that the imagedef has references in the
drawing


newimagedef.
color=#191970>UpgradeOpen

size=1>();


ri.ImageDefId
color=#006400>=
rid.ObjectId

color=#006400>;


ri.
color=#191970>AssociateRasterDef

color=#006400>(
newimagedef

size=1>);



ri.Visible
color=#006400>=
true

color=#006400>;


ri.Orientation
color=#006400>=
new
color=#191970>CoordinateSystem3d

color=#006400>(
p1,
color=#008b8b>new
Vector3d

size=1>(width,
color=#00008b>0
,
color=#00008b>0
), new
Vector3d

color=#006400>(
0
color=#006400>,
height,
color=#00008b>0
));



 



btr.
color=#191970>AppendEntity

color=#006400>(
ri
);



tr.
color=#191970>AddNewlyCreatedDBObject

color=#006400>(
ri,
color=#008b8b>true
);
color=#008000>



tr.
color=#191970>Commit

size=1>();



}



doclock.
color=#191970>Dispose

size=1>();



}


}




}


 


 



style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


Your code isn't calling RasterImage.AssociateImageDef(),
which is

what creates the reactor and adds it to
the RasterImageDef.

 


 

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD
2000 through 2009

href="http://www.acadxtabs.com">http://www.acadxtabs.com

 


 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I
currently have code working that will grab an image stored on a local
drive, create the rasterimagedef dictionary entry, create the raster image
object, and display the image in autocad. The program works but there is
no reactor link to the image and this is apparent as the xref/image
manager shows that the added image entry has no references in the drawing.
The drawing does have the image working... but clearly something is not
linked correctly. I would normally post my code but I amaffraid it will be
a garbled mess like the garbage I have been wading through to find
something helpful since the forum update.

My code is very similar
in structure to the attached link I found which has the same issue as my
code is having. In fact, everything I have found online appears to have
this same problem.

href="http://www.objectarx.net/bbs/viewthread.php?tid=2500&extra=page%3D1"
target=_new...


I have been trying to fix this by
implimenting the rasterimage.AssociateRasterDef and stuffing the parameter
with the new rasterimagedef() entry (both before and after the dictionary
entry and transaction) with no luck. The mgd help is very vague on this
and mentions that a RasterImageDefReactor must be constructed. I am still
learning the C# api and language, with no background in c++ arx. A small
example of using the AssociateRasterDef correctly would be very helpful.


Thanks,
Chris Bertschy

Side note: I typically post with
OE, but I used the RTF web format for this one. It appears that the only
way to get a readable post is to use the web rtf box. Are the users of
newsgroup readers being
punished??
Message 7 of 10
Anonymous
in reply to: cbertschy

This is a repeat of the code in the last post for people using the web interface:




{code}

using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using System.Windows.Forms;
using System.IO;
using Acad = Autodesk.AutoCAD.ApplicationServices.Application;

[assembly: CommandClass( typeof( RasterImageSample.Commands ) )]

namespace RasterImageSample
{
public class Commands
{
[CommandMethod( "RASTER_SAMPLE" )]
public static void RasterCommand()
{
Document doc = Acad.DocumentManager.MdiActiveDocument;
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "JPeg Files|*.jpg|Gif Files|*.gif|PNG Files|*.png";
ofd.FilterIndex = 0;
ofd.Title = "Select Image File";

if( ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK )
{
string filename = ofd.FileName;
using( Transaction trans = doc.TransactionManager.StartTransaction() )
{
ObjectId idModel = SymbolUtilityServices.GetBlockModelSpaceId(doc.Database);
BlockTableRecord ms = trans.GetObject( idModel, OpenMode.ForWrite) as BlockTableRecord;
RasterImageDef imageDef = AddImageDef( doc.Database, trans, filename );
if( imageDef != null )
{
RasterImage image = new RasterImage();
image.ImageDefId = imageDef.ObjectId;
ObjectId imageId = ms.AppendEntity( image );
if( imageId.IsNull )
throw new Autodesk.AutoCAD.Runtime.Exception( ErrorStatus.NullObjectId );
trans.AddNewlyCreatedDBObject( image, true );
RasterImage.EnableReactors( true );
image.AssociateRasterDef( imageDef );
Point3d origin = (Point3d) Acad.GetSystemVariable( "VIEWCTR" );
image.Orientation = new CoordinateSystem3d( origin, Vector3d.XAxis, Vector3d.YAxis);
}
trans.Commit();
}
}
}

public static RasterImageDef AddImageDef( Database db, Transaction trans, string imageFilespec )
{
if( !File.Exists( imageFilespec ) )
throw new FileNotFoundException( imageFilespec );
ObjectId idImageDict = RasterImageDef.GetImageDictionary( db );
if( idImageDict.IsNull )
idImageDict = RasterImageDef.CreateImageDictionary( db );
if( idImageDict.IsNull )
throw new InvalidOperationException( "failed to get or create image dictionary" );

DBDictionary imageDictionary = trans.GetObject( idImageDict, OpenMode.ForRead ) as DBDictionary;
if( imageDictionary == null )
throw new InvalidOperationException( "Failed to open image dictionary" );

RasterImageDef imageDef = new RasterImageDef();
imageDef.SourceFileName = imageFilespec;
imageDef.Load();

String name = RasterImageDef.SuggestName( imageDictionary, imageFilespec );

imageDictionary.UpgradeOpen();
ObjectId idEntry = imageDictionary.SetAt( name, imageDef );
imageDictionary.DowngradeOpen();

if( idEntry.IsNull )
{
imageDef.Dispose();
imageDef = null;
throw new InvalidOperationException( "Failed to add image definition to image dictionary" );
}

trans.AddNewlyCreatedDBObject( imageDef, true );

return imageDef;
}
}
}

{code}




--

http://www.caddzone.com

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

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


"CB" wrote in message news:6061628@discussion.autodesk.com...
I have been trying to pass the object rasterimagedef object with no results. It continues to throw the eNotinDatabase exception. There is another method used as a switch called enablereactors(). Should i refrain from telling the transaction manager to add the newly created rasterimagedef until the new raster image has called the associaterasterdef... or does it not really matter. I can't tell if this is causing the problem. I have tried it both ways and the associaterasterdef() method will not work with the rasterimagedef. Do I have to fully commit() the transaction and start a new transaction before I can attempt to feed it as a database object into the associate method?

cbertschy
"Tony Tanzillo" wrote in message news:6061633@discussion.autodesk.com...
You don't pass any reactor id to AssociateRasterDef().

You pass what the name of that method implies (the
RasterImageDef object, which may need to be open
and write-enabled).

That's all there is to it. You don't need to deal with
any reactors.

--

http://www.caddzone.com

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

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


"CB" wrote in message news:6061565@discussion.autodesk.com...
That is correct. When I code something like:

ri.associaterasterdef(rid);

I get an error in autocad that tells me the entry does not exist in the database.

I am guessing that it is looking for a reactor id that does not exist or that the raster image def is not being handle properly. My question is really where in the code would I put the call to ri.associaterasterdef(rasterimagedef). I found a small tid bit that mentioned setting up a reactionid but nothing on how to handle this. Attached is my version. It is a work in progress. I am posting via OE so I have no idea how this will look.

Thanks, Tony.



public class ACADutility {
public static void addimage(double height, double width, Point3d p1, Point3d p2){
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
Transaction tr = db.TransactionManager.StartTransaction();
DocumentLock doclock = doc.LockDocument();
using (tr)
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = new BlockTableRecord();
btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForWrite);
RasterImageDef rid = new RasterImageDef();
ObjectId ImgDictID = RasterImageDef.GetImageDictionary(db);
if (ImgDictID.IsNull)
{
ImgDictID = RasterImageDef.CreateImageDictionary(db);
}
rid.SourceFileName = "c:\\temp\\gis-image-test.jpg";
rid.ResolutionUnits = Unit.Foot;
rid.Load();
rid.OpenImage();
rid.UpdateEntities();
DBDictionary imgdict =(DBDictionary)tr.GetObject(ImgDictID, OpenMode.ForWrite);
ObjectId rasterimdefid;
rasterimdefid = imgdict.SetAt("image-SERVICE", rid);
tr.AddNewlyCreatedDBObject(rid, true);
RasterImage ri = new RasterImage();
RasterImageDef newimagedef = (RasterImageDef)tr.GetObject(rid.ObjectId, OpenMode.ForWrite);// this was my last ditch effort to get a raster image def to work. stuffing
//the original rid object into the method this not work so I attempted to get update object after the image dictionary update. Not that this should mattre but I can't
//get it to work upgrade open was something ignorant that I also tried. I had the ri.imagedfid = rid.objectid commented out but still did not work. all the
//example on the web show only this method being used to link the raster image to the dictionary definition. this does not work correctly. It does work to make the added image
//use the imagedefinition but does not add the neccesary reactor info to recognize that the imagedef has references in the drawing
newimagedef.UpgradeOpen();
ri.ImageDefId = rid.ObjectId;
ri.AssociateRasterDef(newimagedef);
ri.Visible = true;
ri.Orientation = new CoordinateSystem3d( p1, new Vector3d(width,0,0), new Vector3d(0,height,0));

btr.AppendEntity(ri);
tr.AddNewlyCreatedDBObject(ri, true);
tr.Commit();
}
doclock.Dispose();
}
}
}


"Tony Tanzillo" wrote in message news:6061475@discussion.autodesk.com...
Your code isn't calling RasterImage.AssociateImageDef(), which is
what creates the reactor and adds it to the RasterImageDef.

--

http://www.caddzone.com

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

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


wrote in message news:6061357@discussion.autodesk.com...
I currently have code working that will grab an image stored on a local drive, create the rasterimagedef dictionary entry, create the raster image object, and display the image in autocad. The program works but there is no reactor link to the image and this is apparent as the xref/image manager shows that the added image entry has no references in the drawing. The drawing does have the image working... but clearly something is not linked correctly. I would normally post my code but I amaffraid it will be a garbled mess like the garbage I have been wading through to find something helpful since the forum update.

My code is very similar in structure to the attached link I found which has the same issue as my code is having. In fact, everything I have found online appears to have this same problem.
http://www.objectarx.net/bbs/viewthread.php?tid=2500 &ex tra=page%3D1

I have been trying to fix this by implimenting the rasterimage.AssociateRasterDef and stuffing the parameter with the new rasterimagedef() entry (both before and after the dictionary entry and transaction) with no luck. The mgd help is very vague on this and mentions that a RasterImageDefReactor must be constructed. I am still learning the C# api and language, with no background in c++ arx. A small example of using the AssociateRasterDef correctly would be very helpful.

Thanks,
Chris Bertschy

Side note: I typically post with OE, but I used the RTF web format for this one. It appears that the only way to get a readable post is to use the web rtf box. Are the users of newsgroup readers being punished??
Message 8 of 10
Anonymous
in reply to: cbertschy

Could not get your code to compile due to the different framework version I
must be using .net 2.0 (no System.Windows.Forms). I have been using .net
2.0 with sharpdevelop. Maybe this is why the Associate method is giving me
problems also. I am downloading the 1 gig sdk and will try again with the
.net 3.5 framework. Thank you for you example and time. I'll post my
results tonight.

cbertschy

"Tony Tanzillo" wrote in message
news:6061643@discussion.autodesk.com...
This is a repeat of the code in the last post for people using the web
interface:




{code}

using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using System.Windows.Forms;
using System.IO;
using Acad = Autodesk.AutoCAD.ApplicationServices.Application;

[assembly: CommandClass( typeof( RasterImageSample.Commands ) )]

namespace RasterImageSample
{
public class Commands
{
[CommandMethod( "RASTER_SAMPLE" )]
public static void RasterCommand()
{
Document doc = Acad.DocumentManager.MdiActiveDocument;
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "JPeg Files|*.jpg|Gif Files|*.gif|PNG Files|*.png";
ofd.FilterIndex = 0;
ofd.Title = "Select Image File";

if( ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK )
{
string filename = ofd.FileName;
using( Transaction trans =
doc.TransactionManager.StartTransaction() )
{
ObjectId idModel =
SymbolUtilityServices.GetBlockModelSpaceId(doc.Database);
BlockTableRecord ms = trans.GetObject( idModel,
OpenMode.ForWrite) as BlockTableRecord;
RasterImageDef imageDef = AddImageDef( doc.Database, trans,
filename );
if( imageDef != null )
{
RasterImage image = new RasterImage();
image.ImageDefId = imageDef.ObjectId;
ObjectId imageId = ms.AppendEntity( image );
if( imageId.IsNull )
throw new Autodesk.AutoCAD.Runtime.Exception(
ErrorStatus.NullObjectId );
trans.AddNewlyCreatedDBObject( image, true );
RasterImage.EnableReactors( true );
image.AssociateRasterDef( imageDef );
Point3d origin = (Point3d) Acad.GetSystemVariable(
"VIEWCTR" );
image.Orientation = new CoordinateSystem3d( origin,
Vector3d.XAxis, Vector3d.YAxis);
}
trans.Commit();
}
}
}

public static RasterImageDef AddImageDef( Database db, Transaction
trans, string imageFilespec )
{
if( !File.Exists( imageFilespec ) )
throw new FileNotFoundException( imageFilespec );
ObjectId idImageDict = RasterImageDef.GetImageDictionary( db );
if( idImageDict.IsNull )
idImageDict = RasterImageDef.CreateImageDictionary( db );
if( idImageDict.IsNull )
throw new InvalidOperationException( "failed to get or create
image dictionary" );

DBDictionary imageDictionary = trans.GetObject( idImageDict,
OpenMode.ForRead ) as DBDictionary;
if( imageDictionary == null )
throw new InvalidOperationException( "Failed to open image
dictionary" );

RasterImageDef imageDef = new RasterImageDef();
imageDef.SourceFileName = imageFilespec;
imageDef.Load();

String name = RasterImageDef.SuggestName( imageDictionary,
imageFilespec );

imageDictionary.UpgradeOpen();
ObjectId idEntry = imageDictionary.SetAt( name, imageDef );
imageDictionary.DowngradeOpen();

if( idEntry.IsNull )
{
imageDef.Dispose();
imageDef = null;
throw new InvalidOperationException( "Failed to add image
definition to image dictionary" );
}

trans.AddNewlyCreatedDBObject( imageDef, true );

return imageDef;
}
}
}

{code}




--

http://www.caddzone.com

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

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


"CB" wrote in message
news:6061628@discussion.autodesk.com...
I have been trying to pass the object rasterimagedef object with no
results. It continues to throw the eNotinDatabase exception. There is
another method used as a switch called enablereactors(). Should i refrain
from telling the transaction manager to add the newly created rasterimagedef
until the new raster image has called the associaterasterdef... or does it
not really matter. I can't tell if this is causing the problem. I have
tried it both ways and the associaterasterdef() method will not work with
the rasterimagedef. Do I have to fully commit() the transaction and start a
new transaction before I can attempt to feed it as a database object into
the associate method?

cbertschy
"Tony Tanzillo" wrote in message
news:6061633@discussion.autodesk.com...
You don't pass any reactor id to AssociateRasterDef().

You pass what the name of that method implies (the
RasterImageDef object, which may need to be open
and write-enabled).

That's all there is to it. You don't need to deal with
any reactors.

--

http://www.caddzone.com

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

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


"CB" wrote in message
news:6061565@discussion.autodesk.com...
That is correct. When I code something like:

ri.associaterasterdef(rid);

I get an error in autocad that tells me the entry does not exist in the
database.

I am guessing that it is looking for a reactor id that does not exist or
that the raster image def is not being handle properly. My question is
really where in the code would I put the call to
ri.associaterasterdef(rasterimagedef). I found a small tid bit that
mentioned setting up a reactionid but nothing on how to handle this.
Attached is my version. It is a work in progress. I am posting via OE so I
have no idea how this will look.

Thanks, Tony.



public class ACADutility {
public static void addimage(double height, double width, Point3d p1, Point3d
p2){
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
Transaction tr = db.TransactionManager.StartTransaction();
DocumentLock doclock = doc.LockDocument();
using (tr)
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = new BlockTableRecord();
btr =
(BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForWrite);
RasterImageDef rid = new RasterImageDef();
ObjectId ImgDictID = RasterImageDef.GetImageDictionary(db);
if (ImgDictID.IsNull)
{
ImgDictID = RasterImageDef.CreateImageDictionary(db);
}
rid.SourceFileName = "c:\\temp\\gis-image-test.jpg";
rid.ResolutionUnits = Unit.Foot;
rid.Load();
rid.OpenImage();
rid.UpdateEntities();
DBDictionary imgdict =(DBDictionary)tr.GetObject(ImgDictID,
OpenMode.ForWrite);
ObjectId rasterimdefid;
rasterimdefid = imgdict.SetAt("image-SERVICE", rid);
tr.AddNewlyCreatedDBObject(rid, true);
RasterImage ri = new RasterImage();
RasterImageDef newimagedef = (RasterImageDef)tr.GetObject(rid.ObjectId,
OpenMode.ForWrite);// this was my last ditch effort to get a raster image
def to work. stuffing
//the original rid object into the method this not work so I attempted to
get update object after the image dictionary update. Not that this should
mattre but I can't
//get it to work upgrade open was something ignorant that I also tried. I
had the ri.imagedfid = rid.objectid commented out but still did not work.
all the
//example on the web show only this method being used to link the raster
image to the dictionary definition. this does not work correctly. It does
work to make the added image
//use the imagedefinition but does not add the neccesary reactor info to
recognize that the imagedef has references in the drawing
newimagedef.UpgradeOpen();
ri.ImageDefId = rid.ObjectId;
ri.AssociateRasterDef(newimagedef);
ri.Visible = true;
ri.Orientation = new CoordinateSystem3d( p1, new Vector3d(width,0,0), new
Vector3d(0,height,0));

btr.AppendEntity(ri);
tr.AddNewlyCreatedDBObject(ri, true);
tr.Commit();
}
doclock.Dispose();
}
}
}


"Tony Tanzillo" wrote in message
news:6061475@discussion.autodesk.com...
Your code isn't calling RasterImage.AssociateImageDef(), which is
what creates the reactor and adds it to the RasterImageDef.

--

http://www.caddzone.com

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

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


wrote in message news:6061357@discussion.autodesk.com...
I currently have code working that will grab an image stored on a local
drive, create the rasterimagedef dictionary entry, create the raster image
object, and display the image in autocad. The program works but there is no
reactor link to the image and this is apparent as the xref/image manager
shows that the added image entry has no references in the drawing. The
drawing does have the image working... but clearly something is not linked
correctly. I would normally post my code but I amaffraid it will be a
garbled mess like the garbage I have been wading through to find something
helpful since the forum update.

My code is very similar in structure to the attached link I found which has
the same issue as my code is having. In fact, everything I have found online
appears to have this same problem.
http://www.objectarx.net/bbs/viewthread.php?tid=2500 &ex tra=page%3D1

I have been trying to fix this by implimenting the
rasterimage.AssociateRasterDef and stuffing the parameter with the new
rasterimagedef() entry (both before and after the dictionary entry and
transaction) with no luck. The mgd help is very vague on this and mentions
that a RasterImageDefReactor must be constructed. I am still learning the C#
api and language, with no background in c++ arx. A small example of using
the AssociateRasterDef correctly would be very helpful.

Thanks,
Chris Bertschy

Side note: I typically post with OE, but I used the RTF web format for this
one. It appears that the only way to get a readable post is to use the web
rtf box. Are the users of newsgroup readers being punished??
Message 9 of 10
Anonymous
in reply to: cbertschy

Correction. I forgot the reference to System.Windows.Forms. You code works
very well. I will need to study it better to see where I went wrong. Thank
you for your fine example.

cbertschy


"cbertschy" wrote in message
news:6061858@discussion.autodesk.com...
Could not get your code to compile due to the different framework version I
must be using .net 2.0 (no System.Windows.Forms). I have been using .net
2.0 with sharpdevelop. Maybe this is why the Associate method is giving me
problems also. I am downloading the 1 gig sdk and will try again with the
.net 3.5 framework. Thank you for you example and time. I'll post my
results tonight.

cbertschy

"Tony Tanzillo" wrote in message
news:6061643@discussion.autodesk.com...
This is a repeat of the code in the last post for people using the web
interface:




{code}

using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using System.Windows.Forms;
using System.IO;
using Acad = Autodesk.AutoCAD.ApplicationServices.Application;

[assembly: CommandClass( typeof( RasterImageSample.Commands ) )]

namespace RasterImageSample
{
public class Commands
{
[CommandMethod( "RASTER_SAMPLE" )]
public static void RasterCommand()
{
Document doc = Acad.DocumentManager.MdiActiveDocument;
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "JPeg Files|*.jpg|Gif Files|*.gif|PNG Files|*.png";
ofd.FilterIndex = 0;
ofd.Title = "Select Image File";

if( ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK )
{
string filename = ofd.FileName;
using( Transaction trans =
doc.TransactionManager.StartTransaction() )
{
ObjectId idModel =
SymbolUtilityServices.GetBlockModelSpaceId(doc.Database);
BlockTableRecord ms = trans.GetObject( idModel,
OpenMode.ForWrite) as BlockTableRecord;
RasterImageDef imageDef = AddImageDef( doc.Database, trans,
filename );
if( imageDef != null )
{
RasterImage image = new RasterImage();
image.ImageDefId = imageDef.ObjectId;
ObjectId imageId = ms.AppendEntity( image );
if( imageId.IsNull )
throw new Autodesk.AutoCAD.Runtime.Exception(
ErrorStatus.NullObjectId );
trans.AddNewlyCreatedDBObject( image, true );
RasterImage.EnableReactors( true );
image.AssociateRasterDef( imageDef );
Point3d origin = (Point3d) Acad.GetSystemVariable(
"VIEWCTR" );
image.Orientation = new CoordinateSystem3d( origin,
Vector3d.XAxis, Vector3d.YAxis);
}
trans.Commit();
}
}
}

public static RasterImageDef AddImageDef( Database db, Transaction
trans, string imageFilespec )
{
if( !File.Exists( imageFilespec ) )
throw new FileNotFoundException( imageFilespec );
ObjectId idImageDict = RasterImageDef.GetImageDictionary( db );
if( idImageDict.IsNull )
idImageDict = RasterImageDef.CreateImageDictionary( db );
if( idImageDict.IsNull )
throw new InvalidOperationException( "failed to get or create
image dictionary" );

DBDictionary imageDictionary = trans.GetObject( idImageDict,
OpenMode.ForRead ) as DBDictionary;
if( imageDictionary == null )
throw new InvalidOperationException( "Failed to open image
dictionary" );

RasterImageDef imageDef = new RasterImageDef();
imageDef.SourceFileName = imageFilespec;
imageDef.Load();

String name = RasterImageDef.SuggestName( imageDictionary,
imageFilespec );

imageDictionary.UpgradeOpen();
ObjectId idEntry = imageDictionary.SetAt( name, imageDef );
imageDictionary.DowngradeOpen();

if( idEntry.IsNull )
{
imageDef.Dispose();
imageDef = null;
throw new InvalidOperationException( "Failed to add image
definition to image dictionary" );
}

trans.AddNewlyCreatedDBObject( imageDef, true );

return imageDef;
}
}
}

{code}




--

http://www.caddzone.com

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

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


"CB" wrote in message
news:6061628@discussion.autodesk.com...
I have been trying to pass the object rasterimagedef object with no
results. It continues to throw the eNotinDatabase exception. There is
another method used as a switch called enablereactors(). Should i refrain
from telling the transaction manager to add the newly created rasterimagedef
until the new raster image has called the associaterasterdef... or does it
not really matter. I can't tell if this is causing the problem. I have
tried it both ways and the associaterasterdef() method will not work with
the rasterimagedef. Do I have to fully commit() the transaction and start a
new transaction before I can attempt to feed it as a database object into
the associate method?

cbertschy
"Tony Tanzillo" wrote in message
news:6061633@discussion.autodesk.com...
You don't pass any reactor id to AssociateRasterDef().

You pass what the name of that method implies (the
RasterImageDef object, which may need to be open
and write-enabled).

That's all there is to it. You don't need to deal with
any reactors.

--

http://www.caddzone.com

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

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


"CB" wrote in message
news:6061565@discussion.autodesk.com...
That is correct. When I code something like:

ri.associaterasterdef(rid);

I get an error in autocad that tells me the entry does not exist in the
database.

I am guessing that it is looking for a reactor id that does not exist or
that the raster image def is not being handle properly. My question is
really where in the code would I put the call to
ri.associaterasterdef(rasterimagedef). I found a small tid bit that
mentioned setting up a reactionid but nothing on how to handle this.
Attached is my version. It is a work in progress. I am posting via OE so I
have no idea how this will look.

Thanks, Tony.



public class ACADutility {
public static void addimage(double height, double width, Point3d p1, Point3d
p2){
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
Transaction tr = db.TransactionManager.StartTransaction();
DocumentLock doclock = doc.LockDocument();
using (tr)
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = new BlockTableRecord();
btr =
(BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForWrite);
RasterImageDef rid = new RasterImageDef();
ObjectId ImgDictID = RasterImageDef.GetImageDictionary(db);
if (ImgDictID.IsNull)
{
ImgDictID = RasterImageDef.CreateImageDictionary(db);
}
rid.SourceFileName = "c:\\temp\\gis-image-test.jpg";
rid.ResolutionUnits = Unit.Foot;
rid.Load();
rid.OpenImage();
rid.UpdateEntities();
DBDictionary imgdict =(DBDictionary)tr.GetObject(ImgDictID,
OpenMode.ForWrite);
ObjectId rasterimdefid;
rasterimdefid = imgdict.SetAt("image-SERVICE", rid);
tr.AddNewlyCreatedDBObject(rid, true);
RasterImage ri = new RasterImage();
RasterImageDef newimagedef = (RasterImageDef)tr.GetObject(rid.ObjectId,
OpenMode.ForWrite);// this was my last ditch effort to get a raster image
def to work. stuffing
//the original rid object into the method this not work so I attempted to
get update object after the image dictionary update. Not that this should
mattre but I can't
//get it to work upgrade open was something ignorant that I also tried. I
had the ri.imagedfid = rid.objectid commented out but still did not work.
all the
//example on the web show only this method being used to link the raster
image to the dictionary definition. this does not work correctly. It does
work to make the added image
//use the imagedefinition but does not add the neccesary reactor info to
recognize that the imagedef has references in the drawing
newimagedef.UpgradeOpen();
ri.ImageDefId = rid.ObjectId;
ri.AssociateRasterDef(newimagedef);
ri.Visible = true;
ri.Orientation = new CoordinateSystem3d( p1, new Vector3d(width,0,0), new
Vector3d(0,height,0));

btr.AppendEntity(ri);
tr.AddNewlyCreatedDBObject(ri, true);
tr.Commit();
}
doclock.Dispose();
}
}
}


"Tony Tanzillo" wrote in message
news:6061475@discussion.autodesk.com...
Your code isn't calling RasterImage.AssociateImageDef(), which is
what creates the reactor and adds it to the RasterImageDef.

--

http://www.caddzone.com

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

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


wrote in message news:6061357@discussion.autodesk.com...
I currently have code working that will grab an image stored on a local
drive, create the rasterimagedef dictionary entry, create the raster image
object, and display the image in autocad. The program works but there is no
reactor link to the image and this is apparent as the xref/image manager
shows that the added image entry has no references in the drawing. The
drawing does have the image working... but clearly something is not linked
correctly. I would normally post my code but I amaffraid it will be a
garbled mess like the garbage I have been wading through to find something
helpful since the forum update.

My code is very similar in structure to the attached link I found which has
the same issue as my code is having. In fact, everything I have found online
appears to have this same problem.
http://www.objectarx.net/bbs/viewthread.php?tid=2500 &ex tra=page%3D1

I have been trying to fix this by implimenting the
rasterimage.AssociateRasterDef and stuffing the parameter with the new
rasterimagedef() entry (both before and after the dictionary entry and
transaction) with no luck. The mgd help is very vague on this and mentions
that a RasterImageDefReactor must be constructed. I am still learning the C#
api and language, with no background in c++ arx. A small example of using
the AssociateRasterDef correctly would be very helpful.

Thanks,
Chris Bertschy

Side note: I typically post with OE, but I used the RTF web format for this
one. It appears that the only way to get a readable post is to use the web
rtf box. Are the users of newsgroup readers being punished??
Message 10 of 10
Anonymous
in reply to: cbertschy

Got it working. Thanks again for the example. I added a call to the
transaction manager to add the newly created image before calling the
associate method as you had done in your example. Worked great

cbertschy


"cbertschy" wrote in message
news:6061860@discussion.autodesk.com...
Correction. I forgot the reference to System.Windows.Forms. You code works
very well. I will need to study it better to see where I went wrong. Thank
you for your fine example.

cbertschy


"cbertschy" wrote in message
news:6061858@discussion.autodesk.com...
Could not get your code to compile due to the different framework version I
must be using .net 2.0 (no System.Windows.Forms). I have been using .net
2.0 with sharpdevelop. Maybe this is why the Associate method is giving me
problems also. I am downloading the 1 gig sdk and will try again with the
.net 3.5 framework. Thank you for you example and time. I'll post my
results tonight.

cbertschy

"Tony Tanzillo" wrote in message
news:6061643@discussion.autodesk.com...
This is a repeat of the code in the last post for people using the web
interface:




{code}

using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using System.Windows.Forms;
using System.IO;
using Acad = Autodesk.AutoCAD.ApplicationServices.Application;

[assembly: CommandClass( typeof( RasterImageSample.Commands ) )]

namespace RasterImageSample
{
public class Commands
{
[CommandMethod( "RASTER_SAMPLE" )]
public static void RasterCommand()
{
Document doc = Acad.DocumentManager.MdiActiveDocument;
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "JPeg Files|*.jpg|Gif Files|*.gif|PNG Files|*.png";
ofd.FilterIndex = 0;
ofd.Title = "Select Image File";

if( ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK )
{
string filename = ofd.FileName;
using( Transaction trans =
doc.TransactionManager.StartTransaction() )
{
ObjectId idModel =
SymbolUtilityServices.GetBlockModelSpaceId(doc.Database);
BlockTableRecord ms = trans.GetObject( idModel,
OpenMode.ForWrite) as BlockTableRecord;
RasterImageDef imageDef = AddImageDef( doc.Database, trans,
filename );
if( imageDef != null )
{
RasterImage image = new RasterImage();
image.ImageDefId = imageDef.ObjectId;
ObjectId imageId = ms.AppendEntity( image );
if( imageId.IsNull )
throw new Autodesk.AutoCAD.Runtime.Exception(
ErrorStatus.NullObjectId );
trans.AddNewlyCreatedDBObject( image, true );
RasterImage.EnableReactors( true );
image.AssociateRasterDef( imageDef );
Point3d origin = (Point3d) Acad.GetSystemVariable(
"VIEWCTR" );
image.Orientation = new CoordinateSystem3d( origin,
Vector3d.XAxis, Vector3d.YAxis);
}
trans.Commit();
}
}
}

public static RasterImageDef AddImageDef( Database db, Transaction
trans, string imageFilespec )
{
if( !File.Exists( imageFilespec ) )
throw new FileNotFoundException( imageFilespec );
ObjectId idImageDict = RasterImageDef.GetImageDictionary( db );
if( idImageDict.IsNull )
idImageDict = RasterImageDef.CreateImageDictionary( db );
if( idImageDict.IsNull )
throw new InvalidOperationException( "failed to get or create
image dictionary" );

DBDictionary imageDictionary = trans.GetObject( idImageDict,
OpenMode.ForRead ) as DBDictionary;
if( imageDictionary == null )
throw new InvalidOperationException( "Failed to open image
dictionary" );

RasterImageDef imageDef = new RasterImageDef();
imageDef.SourceFileName = imageFilespec;
imageDef.Load();

String name = RasterImageDef.SuggestName( imageDictionary,
imageFilespec );

imageDictionary.UpgradeOpen();
ObjectId idEntry = imageDictionary.SetAt( name, imageDef );
imageDictionary.DowngradeOpen();

if( idEntry.IsNull )
{
imageDef.Dispose();
imageDef = null;
throw new InvalidOperationException( "Failed to add image
definition to image dictionary" );
}

trans.AddNewlyCreatedDBObject( imageDef, true );

return imageDef;
}
}
}

{code}




--

http://www.caddzone.com

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

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


"CB" wrote in message
news:6061628@discussion.autodesk.com...
I have been trying to pass the object rasterimagedef object with no
results. It continues to throw the eNotinDatabase exception. There is
another method used as a switch called enablereactors(). Should i refrain
from telling the transaction manager to add the newly created rasterimagedef
until the new raster image has called the associaterasterdef... or does it
not really matter. I can't tell if this is causing the problem. I have
tried it both ways and the associaterasterdef() method will not work with
the rasterimagedef. Do I have to fully commit() the transaction and start a
new transaction before I can attempt to feed it as a database object into
the associate method?

cbertschy
"Tony Tanzillo" wrote in message
news:6061633@discussion.autodesk.com...
You don't pass any reactor id to AssociateRasterDef().

You pass what the name of that method implies (the
RasterImageDef object, which may need to be open
and write-enabled).

That's all there is to it. You don't need to deal with
any reactors.

--

http://www.caddzone.com

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

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


"CB" wrote in message
news:6061565@discussion.autodesk.com...
That is correct. When I code something like:

ri.associaterasterdef(rid);

I get an error in autocad that tells me the entry does not exist in the
database.

I am guessing that it is looking for a reactor id that does not exist or
that the raster image def is not being handle properly. My question is
really where in the code would I put the call to
ri.associaterasterdef(rasterimagedef). I found a small tid bit that
mentioned setting up a reactionid but nothing on how to handle this.
Attached is my version. It is a work in progress. I am posting via OE so I
have no idea how this will look.

Thanks, Tony.



public class ACADutility {
public static void addimage(double height, double width, Point3d p1, Point3d
p2){
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
Transaction tr = db.TransactionManager.StartTransaction();
DocumentLock doclock = doc.LockDocument();
using (tr)
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = new BlockTableRecord();
btr =
(BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForWrite);
RasterImageDef rid = new RasterImageDef();
ObjectId ImgDictID = RasterImageDef.GetImageDictionary(db);
if (ImgDictID.IsNull)
{
ImgDictID = RasterImageDef.CreateImageDictionary(db);
}
rid.SourceFileName = "c:\\temp\\gis-image-test.jpg";
rid.ResolutionUnits = Unit.Foot;
rid.Load();
rid.OpenImage();
rid.UpdateEntities();
DBDictionary imgdict =(DBDictionary)tr.GetObject(ImgDictID,
OpenMode.ForWrite);
ObjectId rasterimdefid;
rasterimdefid = imgdict.SetAt("image-SERVICE", rid);
tr.AddNewlyCreatedDBObject(rid, true);
RasterImage ri = new RasterImage();
RasterImageDef newimagedef = (RasterImageDef)tr.GetObject(rid.ObjectId,
OpenMode.ForWrite);// this was my last ditch effort to get a raster image
def to work. stuffing
//the original rid object into the method this not work so I attempted to
get update object after the image dictionary update. Not that this should
mattre but I can't
//get it to work upgrade open was something ignorant that I also tried. I
had the ri.imagedfid = rid.objectid commented out but still did not work.
all the
//example on the web show only this method being used to link the raster
image to the dictionary definition. this does not work correctly. It does
work to make the added image
//use the imagedefinition but does not add the neccesary reactor info to
recognize that the imagedef has references in the drawing
newimagedef.UpgradeOpen();
ri.ImageDefId = rid.ObjectId;
ri.AssociateRasterDef(newimagedef);
ri.Visible = true;
ri.Orientation = new CoordinateSystem3d( p1, new Vector3d(width,0,0), new
Vector3d(0,height,0));

btr.AppendEntity(ri);
tr.AddNewlyCreatedDBObject(ri, true);
tr.Commit();
}
doclock.Dispose();
}
}
}


"Tony Tanzillo" wrote in message
news:6061475@discussion.autodesk.com...
Your code isn't calling RasterImage.AssociateImageDef(), which is
what creates the reactor and adds it to the RasterImageDef.

--

http://www.caddzone.com

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

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


wrote in message news:6061357@discussion.autodesk.com...
I currently have code working that will grab an image stored on a local
drive, create the rasterimagedef dictionary entry, create the raster image
object, and display the image in autocad. The program works but there is no
reactor link to the image and this is apparent as the xref/image manager
shows that the added image entry has no references in the drawing. The
drawing does have the image working... but clearly something is not linked
correctly. I would normally post my code but I amaffraid it will be a
garbled mess like the garbage I have been wading through to find something
helpful since the forum update.

My code is very similar in structure to the attached link I found which has
the same issue as my code is having. In fact, everything I have found online
appears to have this same problem.
http://www.objectarx.net/bbs/viewthread.php?tid=2500 &ex tra=page%3D1

I have been trying to fix this by implimenting the
rasterimage.AssociateRasterDef and stuffing the parameter with the new
rasterimagedef() entry (both before and after the dictionary entry and
transaction) with no luck. The mgd help is very vague on this and mentions
that a RasterImageDefReactor must be constructed. I am still learning the C#
api and language, with no background in c++ arx. A small example of using
the AssociateRasterDef correctly would be very helpful.

Thanks,
Chris Bertschy

Side note: I typically post with OE, but I used the RTF web format for this
one. It appears that the only way to get a readable post is to use the web
rtf box. Are the users of newsgroup readers being punished??

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost