.NET

Reply
Distinguished Contributor
paul.ashley
Posts: 597
Registered: ‎10-20-2003
Message 1 of 8 (499 Views)
Accepted Solution

.NET call in LISP: Pause while waiting for user input?

499 Views, 7 Replies
08-07-2012 11:24 AM

 

I am having our VBA code (written by others now long gone) converted to .NET.  The .NET functions ideally should be called by our existing lisp functions that once called VBA routines.

 

My problem is that when lisp calls a .NET function that creates a dialog box asking for input, the lisp function keeps running and so doesn't receive the variables supposed to be set by the .NET function. 

 

If I run the all of the calls separately, everything works.  If they're combined in a single LISP function, all goes haywire.

 

Is there a way to pause after a lisp routine call of a .NET function to wait for input?

 

These functions produce the desired result when run separately but not when combined.

 

Run this .NET command:             

 

  (command "prefix”); sets a layer name prefix

 

Then run these LISP functions that look for a variable generated by user input in the .NET "prefix" function dialog box

 

  (layer_m "TEXTL") ; creates layer name in quotes with a prefix added

  (layer_m "MEDM")

  (layer_m "LITE")

 

 

 

Mentor
khoa.ho
Posts: 168
Registered: ‎09-15-2011
Message 2 of 8 (487 Views)

Re: .NET call in LISP: Pause while waiting for user input?

08-07-2012 12:53 PM in reply to: paul.ashley

I did a test to see the problem was not from a dialog box input. It was from user interaction with the AutoCAD Editor. I guess your .NET code may call Application.DocumentManager.MdiActiveDocument.Editor.GetXXX() that eventually open the door for all following LISP functions to go through, run in parallel with the ongoing .NET function. Just remove all editor inputs (GetPoint, GetEntity, GetString...) and your code may be fine. My code is working well with an OpenFileDialog to select a file but does not allow all following LISP functions to run.

Another easier way to do is to call LISP functions inside your .NET program at the end. Just use SendStringToExecute after the .NET function is finished. So we will not face this issue of concurrency in AutoLISP.

 

-Khoa

*Expert Elite*
dgorsman
Posts: 5,127
Registered: ‎10-12-2006
Message 3 of 8 (483 Views)

Re: .NET call in LISP: Pause while waiting for user input?

08-07-2012 01:04 PM in reply to: paul.ashley

Rather than defining a command in .NET and calling it as (command "MYCOMMAND"), consider defining a LISP function and calling it as (myCommand arg1 arg2...).

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
Adopt. Adapt. Overcome. Or be overcome.
A good question will be halfway to a good answer.


Distinguished Contributor
paul.ashley
Posts: 597
Registered: ‎10-20-2003
Message 4 of 8 (473 Views)

Re: .NET call in LISP: Pause while waiting for user input?

08-07-2012 02:22 PM in reply to: khoa.ho

I agree that the ideal route would be to put all in .NET, but as this entire effort is a stopgap on the way to Revit implementation, we're trying to do as little recoding as possible.  Since no one in our office knows .NET or has time to learn it, all we want to do is use our current lisp functions that call VBA modules - and wait for and accept the returned data - and substitute .NET clones of our current VBA commands.

 

I've done some web searches and see that there's a "lispfunction" concept in .NET that might help.  Unfortunately, I'm not the programmer.  We may try going this route first.

Distinguished Contributor
paul.ashley
Posts: 597
Registered: ‎10-20-2003
Message 5 of 8 (471 Views)

Re: .NET call in LISP: Pause while waiting for user input?

08-07-2012 02:23 PM in reply to: dgorsman

"Rather than defining a command in .NET and calling it as (command "MYCOMMAND"), consider defining a LISP function and calling it as (myCommand arg1 arg2...)."

 

I'm not sure what you mean by this.

Mentor
khoa.ho
Posts: 168
Registered: ‎09-15-2011
Message 6 of 8 (433 Views)

Re: .NET call in LISP: Pause while waiting for user input?

08-08-2012 07:49 AM in reply to: paul.ashley

I did a test with LispFunction to define a LISP function instead of a .NET method and saw it solved the problem of AutoLISP concurrency. Thank you for your hint!

Now you can run a single LISP file with those commands:

(Prefix); sets a layer name prefix
(layer_m "TEXTL") ; creates layer name in quotes with a prefix added
(layer_m "MEDM")
(layer_m "LITE")

.NET command does not work well with LISP functions whenever a user input is required in the AutoCAD Editor, it will let all following LISP functions behind this .NET command to run through. So just use all LISP functions will fix the issue.

To convert a .NET command to a LISP function, we need to use the following template:

[CommandMethod("Prefix")]
public static void PrefixCommand()
{
    // Implementation
}

[LispFunction("Prefix")]
public static ResultBuffer PrefixCommand(ResultBuffer buffer)
{
    var result = new ResultBuffer
        {
            new TypedValue()
        };
    // Implementation
    return result;
}

-Khoa

Distinguished Contributor
paul.ashley
Posts: 597
Registered: ‎10-20-2003
Message 7 of 8 (428 Views)

Re: .NET call in LISP: Pause while waiting for user input?

08-08-2012 07:53 AM in reply to: khoa.ho

Khoa, thanks for trying this out.  I'll pass it along to my programmers, who yesterday told me they'd done this before in some instances.

Mentor
khoa.ho
Posts: 168
Registered: ‎09-15-2011
Message 8 of 8 (422 Views)

Re: .NET call in LISP: Pause while waiting for user input?

08-08-2012 08:07 AM in reply to: paul.ashley

No problem Paul. Please let me know if all LISP functions may help.

 

-Khoa

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community