Jump to content

Show an attached image just by mouseovering


wary faraj

Recommended Posts

I'd like to acknowledge your contributions to this thread despite the lack of responses. Thank you RenderMan.

 

Same here. Haven't had a chance to try any of it yet but willl. Thanks RenderMan.

Link to comment
Share on other sites

  • Replies 29
  • Created
  • Last Reply

Top Posters In This Topic

  • BlackBox

    15

  • ReMark

    6

  • wary faraj

    5

  • Murph_map

    4

Top Posters In This Topic

Posted Images

I'd like to acknowledge your contributions to this thread despite the lack of responses. Thank you RenderMan.

 

Same here. Haven't had a chance to try any of it yet but willl. Thanks RenderMan.

 

Thanks guys; I've been in the weeds about a handful of topics lately, and actually came across this usage while attempting to resolve another plight of mine. As soon as I read it (the blog post linked above), I immediately thought of its benefit to this topic.

 

This draft's Transaction only opens the DBObject(s) ForRead, and fails to function as desired when changing to ForWrite, and checking the ShowImage Property. Subsequently, more digging is needed as even when listing all events included with the MgdDbg utility, only Database Events are fired when Loading/Unloading an image. I need to find a way of performing the same task(s) without a dependency on Raster Design's .NET API.

 

Vanilla AutoCAD can attach images via the XRef Palette, so I know that it can be done, but much to my surprise RasterImage Objects do not have a Load(), and Unload() Method as shown in object browser... Once I am able to identify that mechanism (hopefully without pinvoke, etc.), I'll be back in business here.

 

I'm also interested in this functionality for other, existing applications in myriad ways, so I'm definitely pushing for success on this. Take from that what it's worth. :beer: LoL

 

 

 

** Edit to add - I also just wanted to reiterate that this completely inspired by Tony's code correction of Kean's blog post.

Edited by BlackBox
Link to comment
Share on other sites

While waiting for a project to plot to PDF, I did some more searching online... I believe that I've found the missing link, so to speak, here.

 

Basically, I came to a stopping point as I anticipated that the DBObject cast as a RasterImage would allow me access to the Load() and Unload() Methods I seek; only after reading the ADNDevBlog post mentioned above, do I now realize that I need to manipulate the dependent Raster Image Definition (RasterImageDef) Object within the Active Document's Database's Image Dictionary, that the Raster Image (RasterImage) Objects (the entities in Model Space) are tied to.

 

... Hopefully the time required for me to code what I've described here is as brief. :lol: LoL

Link to comment
Share on other sites

** Update -

 

The current version of this plug-in can be found at the bottom of this post.

 

 

I've made enough progress to post a functional draft that successfully Loads a raster image upon mouse over (of the image frame), and subsequently Unloads the raster image once the user is no longer hovering the image's frame (or the user Alt + Tabs to another window).

 

I've also added several Properties to the ToolTip that is also displayed whilst hovering a raster image. Not all of them will stay in the final product, but again, this is my working copy, so take from this what you will.

 

ct_acimagehover18.draft3.jpg

 

 

Here's my draft source-code, for anyone interested (see notes below):

 


using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

using acApp = Autodesk.AutoCAD.ApplicationServices.Application;

using System.Collections.Generic;

[assembly: CommandClass(typeof(FOO.BAR))]

namespace FOO
{

   public class BAR
   {

       [CommandMethod("ImageHoverOn")]
       public static void StartMonitor()
       {
           Editor ed =
             Application.DocumentManager.MdiActiveDocument.Editor;

           ed.PointMonitor += ed_PointMonitor;
       }


       [CommandMethod("ImageHoverOff")]
       public static void StopMonitor()
       {
           Editor ed =
             acApp.DocumentManager.MdiActiveDocument.Editor;

           ed.TurnForcedPickOn();

           ed.PointMonitor -= ed_PointMonitor;
       }

       public static Images imgs = new Images();

       public static void ed_PointMonitor(object sender, PointMonitorEventArgs e)
       {
           Editor ed = (Editor)sender;
           Document doc = ed.Document;
           Database db = doc.Database;

           string imageInfo = "";

           try
           {
               FullSubentityPath[] paths =
                 e.Context.GetPickedEntities();

               int i = paths.Length;

               DocumentLock dl =
                   doc.LockDocument(
                       DocumentLockMode.ProtectedAutoWrite,
                       null, null, true
                   );

               using (dl)
               {
                   Transaction tr = doc.TransactionManager.StartTransaction();

                   using (tr)
                   {
                       if (i <= 0 && imgs.Count > 0)
                       {
                           foreach (ObjectId imgDefId in imgs.ToArray())
                           {
                               RasterImageDef imgDef =
                                       (RasterImageDef)tr.GetObject(
                                           imgDefId, OpenMode.ForWrite
                                       );

                               if (imgDef != null && imgDef.IsLoaded)
                               {
                                   // Use false, as finally calls Commit()?
                                   //imgDef.Unload(true); 
                                   imgDef.Unload(false);

                                   // ???
                                   //imgDef.UpgradeOpen();
                                   imgDef.DowngradeOpen();

                                   imgs.Remove(imgDefId);
                               }
                           }

                           tr.Commit();
                           return;
                       }

                       ObjectId imgDictId = RasterImageDef.GetImageDictionary(db);

                       if (imgDictId != null)
                       {
                           //DBDictionary imgDict =
                           //    (DBDictionary)tr.GetObject(imgDictId, OpenMode.ForRead);

                           // Open each object, one by one
                           foreach (FullSubentityPath path in paths)
                           {
                               ObjectId[] ids = path.GetObjectIds();

                               ObjectId id = ids[ids.GetUpperBound(0)];

                               DBObject obj =
                                 tr.GetObject(id, OpenMode.ForRead);

                               if (obj != null)
                               {
                                   //RasterImage img = (RasterImage)obj;
                                   RasterImage img = obj as RasterImage;

                                   if (img != null)
                                   {
                                       // access the raster image definition
                                       ObjectId imgDefId = img.ImageDefId;

                                       RasterImageDef imgDef =
                                           (RasterImageDef)tr.GetObject(
                                               imgDefId, OpenMode.ForWrite
                                           );

                                       if (imgDef != null)
                                       {
                                           imgs.Add(imgDefId);

                                           imageInfo =
                                               "ActiveFileName: " + 
                                               imgDef.ActiveFileName +
                                               "\nColorDepth: " + 
                                               imgDef.ColorDepth +
                                               "\nFileDescCopy: " + 
                                               imgDef.FileDescCopy +
                                               "\nFileType: " + 
                                               imgDef.FileType +
                                               "\nImageModified: " + 
                                               imgDef.ImageModified +
                                               "\nIsEmbedded: " + 
                                               imgDef.IsEmbedded +
                                               "\nIsLoaded: " + 
                                               imgDef.IsLoaded +
                                               "\nOrganization: " + 
                                               imgDef.Organization +
                                               "\nResolutionMMPerPixel: " + 
                                               imgDef.ResolutionMMPerPixel +
                                               "\nResolutionUnits: " + 
                                               imgDef.ResolutionUnits +
                                               //"\nSearchForActivePath: " + 
                                               //imgDef.SearchForActivePath +
                                               "\nLocateActivePath: " + 
                                               imgDef.LocateActivePath() +
                                               "\nSize: " + 
                                               imgDef.Size +
                                               "\nSourceFileName: " + 
                                               imgDef.SourceFileName +
                                               "\nUndoStoreSize: " + 
                                               imgDef.UndoStoreSize +
                                               "\n";

                                           if (!imgDef.IsLoaded)
                                           {
                                               imgDef.Load();
                                               imgDef.UpgradeOpen();
                                           }
                                       }
                                   }
                               }
                           }
                       }

                       // Cheaper than aborting
                       tr.Commit();
                   }

                   // Add the tooltip of the lengths of the curves detected
                   //if (curveInfo != "")
                   //    e.AppendToolTipText(curveInfo);
                   if (imageInfo != "")
                   {
                       e.AppendToolTipText(imageInfo);
                   }
               }
           }

           catch (Exception ex)
           {
               // Not sure what we might get here, but not real action
               // needed (worth adding an Exception parameter and a
               // breakpoint, in case things need investigating).
               ed.WriteMessage(
                   "\n; ImageHover error: " + ex.Message + "\n "
                   );
           }
       }
   }


   public class Images : List<ObjectId>
   {
       public List<ObjectId> _Images { get; set; }

       public Images()
       {
       }

   }

}

** Notes -

 

I am already aware that a great deal of streamlining is needed, this is more of a proof-of-concept for me, and is not production ready.

 

This draft is being offered only as a Command at this time (using ImageHoverOn, and ImageHoverOff), rather than simply being loaded automagically, as I have yet to implement the necessary 'Document Controller' to hook a static Editor.PointMonitor Event handler in an MDI environment.

 

Another thing that's missing, is that at present this utility only works when hovering the image's frame, and not within the frame limits.

 

Perhaps a slight delay would also be advantageous, so that simply nudging the cursor doesn't make the image flicker.

 

... Features that this plug-in will have as soon as I have time.

 

 

 

This is the first time I've ever tried something like this, so constructive criticism, and laudatory feedback alike are welcomed.

 

Cheers! :beer:

Link to comment
Share on other sites

*Bump*

 

... Anyone had a chance to test this plug-in yet? :unsure:

 

I just did with MAP3D 2011 using the MAPINSERT with a SID format file. Once it hid the image (imagehoveron) I wasn't able to get it back (imagehoveroff). Also if I erased the image and reinserted it or any other images I got error msg in the command line.

; ImageHover error: eWasErased

; ImageHover error: eWasErased

; ImageHover error: eWasErased

That msg filled my text window.

 

Otherwise good work.

Link to comment
Share on other sites

Thanks, Murph.

 

Sorry that I wasn't more clear about some of the anticipated gaps that I've knowingly left (due to time constraints with daily work). I used the vanilla AutoCAD XREF palette to attach a raster image (ImageAttach Command?), and then manually unloaded it to test to ImageHoverOn command.

 

I have pretty good computer specs (quad-core i7, 16GB RAM, 2GB video card, etc.) so I was mostly looking for the potential lag, or flicker on other's machines to see if any sort of delay should be added, etc..

 

The error you experienced is caused when the image has been Loaded via the code, which stores the RasterImageRefId (an ObjectId) to an Images() derived type which inherits from List, and then the RasterImage has been erased prior to being restored (in this case Unloaded), which also removes the associated RasterImageDefId from the Images list object.

 

There's several items needed still in order to be production ready... The Document manager as stated earlier, the erased Exception & event handling, and also the querying and storing of all min and max coordinate values that should be evaluated against the current cursor position to determine if within the RasterImages extents, etc. so one no longer need hover the frame. The latter should be done via the DocumentCreated event, and as necessary given specific commands or database changes occur to account for Lisp, etc. methinks.

 

Thank you for giving this a try so promptly again, Murph.

 

Cheers! :beer:

Link to comment
Share on other sites

My test station is Visa w/sp2 32 bit with 2 gb RAM and an onboard video card. One reason I used the SID format was to see how it handled that format that cause issues with AutoAD from time to time. I notice no flickering or lag. Performance wise I give it (your app) a 3 star rating.

Link to comment
Share on other sites

Thanks for the additional info, Murph... That is a very generous rating, especially given my being new to .NET development.

 

 

 

** Edit to add - I'll post another (upgraded, and more complete) version at my soonest convenience.

 

Cheers! :beer:

Link to comment
Share on other sites

  • 2 months later...

Note to self:

 

Whenever you get back into this (one day), test the Autodesk.AutoCAD.EditorInput.Editor.Rollover Event

 

[assembly: ExtensionApplication(typeof(Foo.Bar))]

namespace Foo
{
   public class Bar: IExtensionApplication
   {
       void IExtensionApplication.Initialize()
       {
           acApp.DocumentManager.MdiActiveDocument.Editor.Rollover += _OnRollover;
       }

       void IExtensionApplication.Terminate()
       {
       }

       public static void _OnRollover(object sender, RolloverEventArgs e)
       {
           Editor ed = sender as Editor;

           ed.WriteMessage("\n[Editor.Rollover] : Do work ");
       }
   }
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...