Tomislav Posted June 4 Share Posted June 4 (edited) (defun ActivateExcel () ;; Initialize Excel application (setq excelApp (vlax-get-or-create-object "Excel.Application")) ;; Get the active workbook name (setq activeWorkbook (vlax-get-property excelApp 'ActiveWorkbook)) (setq workbookName (vlax-get-property activeWorkbook 'Name)) ;; Combine the workbook name with the standard Excel window title suffix (setq excelTitle (strcat workbookName " - Excel")) ;; Create a WScript.Shell COM object (setq shell (vlax-create-object "WScript.Shell")) ;; Activate the Excel application by its window title (vlax-invoke-method shell 'AppActivate excelTitle) ;; Release the COM objects (vlax-release-object shell) (vlax-release-object activeWorkbook) ) ;_ _defun ;*********************************************************** (defun ActivateExcel () ;; Initialize Excel application (setq excelApp (vlax-get-or-create-object "Excel.Application")) ;; Make sure the Excel application is visible (vlax-put excelApp 'Visible :vlax-true) ;; Get the HWND of the Excel application (setq hwnd (vlax-get excelApp 'HWND)) ;; Use WScript.Shell to bring the Excel window to the foreground (setq shell (vlax-create-object "WScript.Shell")) (vlax-invoke-method shell 'AppActivate hwnd) ;; Release the COM objects (vlax-release-object shell) (vlax-release-object excelApp) ) hello everyone, I'm in need of your help cause I've tried everything I found and nothing works to get focus to stay on Excel after end of lisp, after populating some cells with data, simply focus always returns to cad...here are just two of my latest attempts Edited June 4 by Tomislav Quote Link to comment Share on other sites More sharing options...
mhupp Posted June 6 Share Posted June 6 (edited) I had buttons in excel that would called lisp in cad when I needed to export & work in excel. Might have to add a wait time Sub RunLISPCommand() ' Declare the AutoCAD application object Dim acadApp As AcadApplication ' Get the AutoCAD application object Set acadApp = ThisDrawing.Application ' Send the LISP command to AutoCAD acadApp.ActiveDocument.SendCommand "Your Command HERE" & vbCr ... AppActivate "Microsoft Excel" End Sub Maybe try in https://www.cadtutor.net/forum/forum/57-net-objectarx-amp-vba/ Edited June 6 by mhupp 1 Quote Link to comment Share on other sites More sharing options...
Tomislav Posted June 6 Author Share Posted June 6 unfortunately I don't know a thing in vba Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 6 Share Posted June 6 Mhupp's idea is that you run from Excel rather than from CAD, instead of a lisp yes you would write a VBA macro. What are you trying to do when reading from Excel. I have a simple draw a LIne Circle and Pline in a Excel macro. I will test what happens if you can load a lisp run it and end it reading Ecel ells. But return to Excel. The simplest way may be the last line in your lisp is do this. (alert "Please select Excel again after pressing OK") Quote Link to comment Share on other sites More sharing options...
Tomislav Posted June 6 Author Share Posted June 6 (edited) I'm not reading from excel, but writing to excel cross section data from cad...I know I can just click on excel on task bar and bring it back to focus, but I'm trying to do it automatically on the end of lisp...the function ActivateExcel I would call on the end to bring it to focus Edited June 6 by Tomislav Quote Link to comment Share on other sites More sharing options...
rlx Posted June 6 Share Posted June 6 (edited) Sadly still no time to do any serious lisping, so much to do and so little time ... Anyways , maybe one of these commands : (vlax-put-property excelApp 'visible :vlax-true) (vlax-put-property excelApp 'ScreenUpdating :vlax-true) (vlax-put-property excelApp 'DisplayAlerts :vlax-false) (vla-put-windowstate (vlax-get-acad-object) acMin) (vla-put-windowstate excelApp acMax) Edited June 6 by rlx 1 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 7 Share Posted June 7 (edited) Thanks rlx this one sort of works for me. It only works if you have minimised the window. (vla-put-windowstate excelApp acMax) Also running dual screens. Need a Powershell script. ie winodws OS level. Ok found something now have to remember how to incorporate into a Powershell script and run from CAD, have done it before. $wshell = New-Object -ComObject wscript.shell $wshell.AppActivate('Excel') If you want to try, go bottom right in windows type cmd then powershell paste the 2 lines. Have an Excel open. Edited June 7 by BIGAL 1 Quote Link to comment Share on other sites More sharing options...
Tomislav Posted June 7 Author Share Posted June 7 12 hours ago, rlx said: Sadly still no time to do any serious lisping, so much to do and so little time ... Anyways , maybe one of these commands : (vlax-put-property excelApp 'visible :vlax-true) (vlax-put-property excelApp 'ScreenUpdating :vlax-true) (vlax-put-property excelApp 'DisplayAlerts :vlax-false) (vla-put-windowstate (vlax-get-acad-object) acMin) (vla-put-windowstate excelApp acMax) finally, BIG thanx , trying one by one with first one (of course ) didn't work, but when I've put them all it stayed on excel, seems like minimizing and maximizing did the trick...and thanx to others that tried to help me for spending their time to solve my problem Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 7 Share Posted June 7 As I suggested the maximizing worked if you had minimized manually did not think do that and then do maximise. I think rlx was trying to tell us something. Quote Link to comment Share on other sites More sharing options...
rlx Posted June 7 Share Posted June 7 Only remembered when selecting a range in excel you have to shift focus from AutoCad to Excel (and back) so just browsed through a few of my old programs and cut & pasted these lines. But to be honest , and I think this goes for most of us , a lot of my code is 'Frankenized' together from code I googled across time and space and put a little of my own scent on it. And sometimes , after so many years , having no active memory anymore ever written it Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 7 Share Posted June 7 Yeah just had another look yes there are duplicates backups etc but 3779 lsp files. I did something for a client where we used a Excel look up table and would now add the make Excel current to code rather than an Alert. Quote Link to comment Share on other sites More sharing options...
Tomislav Posted June 7 Author Share Posted June 7 29 minutes ago, BIGAL said: As I suggested the maximizing worked if you had minimized manually did not think do that and then do maximise. I think rlx was trying to tell us something. yeah, sometimes the solution is the simplest of thing... 9 minutes ago, rlx said: Only remembered when selecting a range in excel you have to shift focus from AutoCad to Excel (and back) so just browsed through a few of my old programs and cut & pasted these lines. But to be honest , and I think this goes for most of us , a lot of my code is 'Frankenized' together from code I googled across time and space and put a little of my own scent on it. And sometimes , after so many years , having no active memory anymore ever written it that's the way I mostly do it cause I do have some knowledge, but for something more complicated I have to copy+tweak... I have one quick question now that I have your 'focus' ...can I pass selection set to copyWithBasePoint command somehow? Quote Link to comment Share on other sites More sharing options...
rlx Posted June 7 Share Posted June 7 I use a few simple toolbar buttons for copy with basepoint. Check if sysvar 'pickfirst' is set to 1 First I select objects and then click on button of my choise. ID_Bcopy [_Button("Copy With Basepoint 0,0", "bcopy.bmp", "ICON_16_BLANK")]^C^C_copybase;0,0; ID_Bpaste [_Button("Paste with Basepoint 0,0", "bpaste.bmp", "ICON_16_BLANK")]^C^C_pasteclip;0,0; ID_GetBcopy [_Button("Copy With Get Basepoint", "bcopy_get.bmp", "ICON_16_BLANK")]^C^C_copybase; ID_GetBpaste [_Button("Paste with Get Basepoint", "bpaste_get.bmp", "ICON_16_BLANK")]^C^C_pasteclip; First 2 lines always use 0,0 as base point and last 2 lines allows to enter base point manually in lisp you would do something lile (command "_copybase" pause "0,0") or (command "_copybase" pause "0,0") Quote Link to comment Share on other sites More sharing options...
Tomislav Posted June 7 Author Share Posted June 7 i have similar buttons also, but i'm trying to add objects in SS while i'm creating them, in a lisp, and then pass them to copybp, so i can call pastetooriginal with created script to copy them to another drawing, cause can't copy them other way through lisp... if i had the knowledge, easiest would be to modify Lee's Copy2DrawingsV1-3.lsp to accept selection set instead of selecting objects, and instead of selecting file to where to copy it would create new file...but that's too much for me Quote Link to comment Share on other sites More sharing options...
rlx Posted June 7 Share Posted June 7 (defun c:cwb ( / ss pt) (if (and (setq pt (getpoint "\nSelect basepoint")) (setq ss (ssget))) (command "_copybase" pt ss ""))) (defun c:pwb () (command "pasteclip" pause)) 1 Quote Link to comment Share on other sites More sharing options...
Tomislav Posted June 7 Author Share Posted June 7 ok, thank you, so the ss can be passed normally to copybase, I will supply pt and ss , so it is: (defun c:cwb ( ss pt /) (if (and (= pt T)(= ss T)) (command "_copybase" pt ss ""))) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 7 Share Posted June 7 "add objects in SS while i'm creating them, in a lisp," Look into lisp function SSADD you should be able to add (entlast) to ss. (setq ss (ssadd)) ; makes a blank selection set do stuff (setq ss (ssadd (entlast) ss)) 1 Quote Link to comment Share on other sites More sharing options...
Tomislav Posted June 8 Author Share Posted June 8 12 hours ago, BIGAL said: "add objects in SS while i'm creating them, in a lisp," Look into lisp function SSADD you should be able to add (entlast) to ss. (setq ss (ssadd)) ; makes a blank selection set do stuff (setq ss (ssadd (entlast) ss)) exactly what my idea was, after every object add it to ss, and on the end after being copied, delete them... Quote Link to comment Share on other sites More sharing options...
mhupp Posted June 8 Share Posted June 8 You can set a "place holder" right before creating or modifying things in the drawing. using entnext to add each to the selection set. (setq ss (ssadd)) ; Create an empty selection set (setq LastEnt (entlast)) ; Get the last entity in the drawing ; code to add items (while (setq LastEnt (entnext LastEnt)) ; Add all entity's created/modified after setting lastent to the selection set (ssadd LastEnt ss) ) 1 Quote Link to comment Share on other sites More sharing options...
Tomislav Posted June 9 Author Share Posted June 9 10 hours ago, mhupp said: You can set a "place holder" right before creating or modifying things in the drawing. using entnext to add each to the selection set. (setq ss (ssadd)) ; Create an empty selection set (setq LastEnt (entlast)) ; Get the last entity in the drawing ; code to add items (while (setq LastEnt (entnext LastEnt)) ; Add all entity's created/modified after setting lastent to the selection set (ssadd LastEnt ss) ) that is very useful, thanx, was wondering if there is something like startundomark but for selecting objects and this is it.... it's a shame autolisp can't access other drawings directly like vba, so scripts must be made to circumvent that...they pretty much slow down things Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.