Pressing "Enter" to open OLE Object in Host Application.

Pressing "Enter" to open OLE Object in Host Application.

Yasir.Aman
Advocate Advocate
601 Views
2 Replies
Message 1 of 3

Pressing "Enter" to open OLE Object in Host Application.

Yasir.Aman
Advocate
Advocate

Hey everyone,

So, to open OLE objects in their host applications, we usually do the whole deal of selecting the OLE object, right-clicking, hovering over OLE, and then choosing "Open." Or we can select the OLE object and type OLEOPEN and hit Enter/Space.

I'm wondering if there's a way, maybe with a macro or something, to make it simpler. Like, when I press Enter/Space in AutoCAD, it checks if there's an OLE object selected. If yes, it should just fire up the right host application.

I get it might not be a big deal for everyone, but I'm constantly dealing with OLE objects, especially from Excel, and I'm trying to cut down on clicks.

While I recognize the potential performance implications of having AutoCAD check for OLE objects every time Enter or Space is pressed, I consider this an experimental endeavor and would appreciate any suggestions or code snippets you might suggest.

Thank you!

0 Likes
602 Views
2 Replies
Replies (2)
Message 2 of 3

komondormrex
Mentor
Mentor

hey there,

maybe this one helps

(defun c:ole_open (/ ole_sset)
  (if (zerop (getvar 'pickfirst)) (setvar 'pickfirst 1))
  (if (setq ole_sset (ssget '((0 . "ole2frame"))))
      (foreach ole (vl-remove-if 'listp (mapcar 'cadr (ssnamex ole_sset)))
	(command-s "_oleopen" (cadr (sssetfirst nil (ssadd ole))))
      )
  )
  (princ)
)

 

Message 3 of 3

Yasir.Aman
Advocate
Advocate

Big thanks @komondormrex for your valuable input. This code is very effective at opening multiple OLE Objects at once in their respective host applications and will certainly prove useful for me.

 

However, my initial question is a bit different. Picture this: usually, hitting Enter/Space in AutoCAD with no active command just repeats the last used command. Now, I want to OVERRIDE this behavior. When I hit Enter/Space without any command active, I want AutoCAD to be Sherlock Holmes 😉. It should check if there's an OLE OBJECT already selected. If yes, bam! Open it in its host application. If not, no drama, just replay the last used command as usual 🙂.

 

Hope this clears up my original puzzle.

 

Thanks a ton once again!

0 Likes