AcApDocManager::sendStringToExecute and reactor documentCreated

AcApDocManager::sendStringToExecute and reactor documentCreated

Anonymous
Not applicable
967 Views
11 Replies
Message 1 of 12

AcApDocManager::sendStringToExecute and reactor documentCreated

Anonymous
Not applicable
Hi Guys,
It seems the function
AcApDocManager::sendStringToExecute won't work properly within the
AcApDocManagerReactor::documentCreated
It always returns eNoDocument in that case. I tried documentActivated and
documentBecameCurrent, same disappointment.
I need to send an AutoLisp line as soon as the document gets created and I
thought it is the best place to do so.
Is there a way to achieve this (other than old "acad.lsp")?
Your help is very much appreciated.
Thanks heaps.
Charlie.
0 Likes
968 Views
11 Replies
Replies (11)
Message 2 of 12

Anonymous
Not applicable
Try instead ads_queueexpr() or acedPostCommand() or use ::SetTimer() function on AcApDocManagerReactor::documentCreated() and AcApDocManager::sendStringToExecute() in timer callback function Message was edited by: Alexander Rivilis
0 Likes
Message 3 of 12

Anonymous
Not applicable
Hi Alexander,
SetTimer fails sometimes when loading big dwgs.
The other functions are not published, what is the lib?
Thanks heaps, you help many when you help one!
Nabil.
0 Likes
Message 4 of 12

Anonymous
Not applicable
🙂 What about check result of AcApDocManager::sendStringToExecute() and if it is fails - restart timer? It is easy!
About other functions:
http://through-the-interface.typepad.com/through_the_interface/2006/08/techniques_for_.html
http://through-the-interface.typepad.com/through_the_interface/2006/08/cancelling_an_a.html
0 Likes
Message 5 of 12

Anonymous
Not applicable
Alexander,
I tried both methods and they both crashed when dwg is of a good size (like
>1.5M)...
Any ideas why?
Thanks heaps,
Charlie.

wrote in message news:5309187@discussion.autodesk.com...
:) What about check result of AcApDocManager::sendStringToExecute() and if
it is fails - restart timer? It is easy!
About other functions:
http://through-the-interface.typepad.com/through_the_interface/2006/08/techniques_for_.html
http://through-the-interface.typepad.com/through_the_interface/2006/08/cancelling_an_a.html
0 Likes
Message 6 of 12

Anonymous
Not applicable
Explain more your's problem. Maybe your's code crash AutoCAD?
1) What error messge?
2) What version of AutoCAD?
3) What doing command (code) started with sendStringToExecute?
4) Are you locking document in your's code?
5) Are you remembering to destroy timer beforer sendStringToExecute? Message was edited by: Alexander Rivilis
0 Likes
Message 7 of 12

Anonymous
Not applicable
Answers are below:

wrote in message news:5309197@discussion.autodesk.com...
Explain more your's problem. Maybe your's code crash AutoCAD?
1) What error messge?
No error message, AutoCAD just hangs there, eating memory.

2) What version of AutoCAD?
AutoCAD2007

3) What doing command (code) started with sendStringToExecute?
it is in documentCreated of a reactor.
A> USING ads_queueexpr version:
void MyDocReactor::documentCreated( AcApDocument *pDoc )

{

if (pDoc != NULL)

{

CString cmd = L"(load \"my_lisp_file.fas\")))\n";

ads_queueexpr(cmd.GetBuffer());

}

}

B> USING sendStringToExecute version using a timer:
void MyDocReactor::documentCreated( AcApDocument *pDoc )

{

if (pDoc != NULL)

{

CDocument *cDoc = pDoc->cDoc();

POSITION pos = cDoc->GetFirstViewPosition();

CWnd *view = cDoc->GetNextView(pos);

view->SetTimer(ULTRA_TIMER,10000,TimerProc); // react after 10 seconds -> it
still crashes on good size drawings

}

}

// the TimerProc function
void CALLBACK EXPORT TimerProc(

HWND hWnd, // handle of CWnd that called SetTimer

UINT nMsg, // WM_TIMER

UINT_PTR nIDEvent, // timer identification

DWORD dwTime // system time

)

{

if (nIDEvent == ULTRA_TIMER)

{

CString cmd = L"(load\"my_lisp_file.fas\")))\n";

if (SendString(cmd) != Acad::eNoDocument)

KillTimer(hWnd,nIDEvent); // once it succeeds kill timer

}

}

// In the SendString function I am doing
pDocManager->activateDocument(pDoc, true); // a must

pDocManager->lockDocument(pDoc); // maybe a must but don't play with fate

pDocManager->sendStringToExecute(pDoc, sCommandLine, true, true, false);

pDocManager->unlockDocument(pDoc); // maybe a must but don't play with fate


4) Are you locking document in your's code?
Yes.

5) Are you remembering to destroy timer beforer sendStringToExecute?
I do it just after, but note that using ads_queueexpr is causing the same
problems.

Thanks heaps.

Charlie.

Message was edited by: Alexander Rivilis
0 Likes
Message 8 of 12

Anonymous
Not applicable
Alexander,
I think there is a function in my_lisp_file.fas that is causing the huge
delay in big drawings.
Thanks so much for your help, it is very much appreciated and it was very
valuable.
I would use ads_queueexpr, it is simpler than SetTimer.

Charlie.

"charlie" wrote in message
news:5309242@discussion.autodesk.com...
Answers are below:

wrote in message news:5309197@discussion.autodesk.com...
Explain more your's problem. Maybe your's code crash AutoCAD?
1) What error messge?
No error message, AutoCAD just hangs there, eating memory.

2) What version of AutoCAD?
AutoCAD2007

3) What doing command (code) started with sendStringToExecute?
it is in documentCreated of a reactor.
A> USING ads_queueexpr version:
void MyDocReactor::documentCreated( AcApDocument *pDoc )

{

if (pDoc != NULL)

{

CString cmd = L"(load \"my_lisp_file.fas\")))\n";

ads_queueexpr(cmd.GetBuffer());

}

}

B> USING sendStringToExecute version using a timer:
void MyDocReactor::documentCreated( AcApDocument *pDoc )

{

if (pDoc != NULL)

{

CDocument *cDoc = pDoc->cDoc();

POSITION pos = cDoc->GetFirstViewPosition();

CWnd *view = cDoc->GetNextView(pos);

view->SetTimer(ULTRA_TIMER,10000,TimerProc); // react after 10 seconds -> it
still crashes on good size drawings

}

}

// the TimerProc function
void CALLBACK EXPORT TimerProc(

HWND hWnd, // handle of CWnd that called SetTimer

UINT nMsg, // WM_TIMER

UINT_PTR nIDEvent, // timer identification

DWORD dwTime // system time

)

{

if (nIDEvent == ULTRA_TIMER)

{

CString cmd = L"(load\"my_lisp_file.fas\")))\n";

if (SendString(cmd) != Acad::eNoDocument)

KillTimer(hWnd,nIDEvent); // once it succeeds kill timer

}

}

// In the SendString function I am doing
pDocManager->activateDocument(pDoc, true); // a must

pDocManager->lockDocument(pDoc); // maybe a must but don't play with fate

pDocManager->sendStringToExecute(pDoc, sCommandLine, true, true, false);

pDocManager->unlockDocument(pDoc); // maybe a must but don't play with fate


4) Are you locking document in your's code?
Yes.

5) Are you remembering to destroy timer beforer sendStringToExecute?
I do it just after, but note that using ads_queueexpr is causing the same
problems.

Thanks heaps.

Charlie.

Message was edited by: Alexander Rivilis
0 Likes
Message 9 of 12

Anonymous
Not applicable
Hi, Charlie!

c> I think there is a function in my_lisp_file.fas that is causing the huge
c> delay in big drawings.

It is only if my_lisp_file.fas is autoexecution (e.g. after loading it is start)
You can easy test it. Open this "big" dwg-file and do (load "my_lisp_file.fas").
If AutoCAD hang - search for bug in my_lisp_file.fas
If AutoCAD do not hang - debug your's arx-file

c> I would use ads_queueexpr, it is simpler than SetTimer.

Yes. It is simpler but:
1) echo in command line
2) may be execute only in active document.

Best Regards,
Alexander Rivilis.
0 Likes
Message 10 of 12

Anonymous
Not applicable
I had used sendStringToExcecute() once, but not part of a reactor, have you
tried with (vl-load-com) (vl-load-all "yourFas.fas") or what if you loaded
in your entryPoint() in the AcRx::kInitAppMsg message using the (vl-load-all
filename) function?
0 Likes
Message 11 of 12

Anonymous
Not applicable
I didn't use vl, it needs the document to be well created for it to load any
lisp stuff, otherwise it would fail.

"Luis Esquivel" wrote in message
news:5309507@discussion.autodesk.com...
I had used sendStringToExcecute() once, but not part of a reactor, have you
tried with (vl-load-com) (vl-load-all "yourFas.fas") or what if you loaded
in your entryPoint() in the AcRx::kInitAppMsg message using the (vl-load-all
filename) function?
0 Likes
Message 12 of 12

Anonymous
Not applicable
I did a quick test using just (load "filename.fas") and works in the
documentActivated() and documentBecameCurrent() events, cannot make it load
in the documentCreated() event.



>I didn't use vl, it needs the document to be well created for it to load
any
>lisp stuff, otherwise it would fail.
0 Likes