CoCreate User Forum  

Go Back   CoCreate User Forum > Support > Customization
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 10-03-2013, 11:58 PM
fabrizio fabrizio is offline
Registered User
 
Join Date: Jan 2003
Location: Parma - Italy
Posts: 34
Invoking lisp code from a .NET add-in

Hi,
is there anybody who's experienced in using the COM and .NET API? I am going to write a customization for Modeling and I am considering the option of using this API instead of (or togheter with) the lisp IKit, as I think that for this particular task, writing a .NET program could have some advantages.

In particular, do you know if there's a way to invoke a lisp command from a .NET addin? In the documentation I found an example of a lisp dialog calling a .NET function that returns a value back to the lisp code... but I could not find any reference to .NET code invoking a lisp function or dialog.

Thank you in advance,
Fabrizio

Last edited by fabrizio; 10-04-2013 at 01:19 AM.
Reply With Quote
  #2  
Old 11-13-2013, 02:26 AM
fabrizio fabrizio is offline
Registered User
 
Join Date: Jan 2003
Location: Parma - Italy
Posts: 34
Re: Invoking lisp code with .NET API

After digging deeper into the .NET API doc, I have found a method in the Application class that does exactly what I was looking for. The method is:

Code:
public virtual object SendCommand(string str);
The documentation of this method also reports an example:

Code:
app.SendCommand("(delete_3d :all_at_top)");
So I have developed a test addin and added a menu button that invokes the call above. The result is that all the 3D models in the current OSDM session are actually deleted, but neither the viewport nor the browser are refreshed after the execution of the command. So the impression is that the command has no effect; but as soon as I click on the viewport or resize the browser they are refreshed and I can see that all the 3D models have actually been deleted.

Does anyone have an idea (or maybe just a hint) for the reason of this strange behavior?
Reply With Quote
  #3  
Old 11-13-2013, 06:49 AM
Andy Poulsen Andy Poulsen is offline
Administrator
 
Join Date: Apr 2003
Location: Fort Collins, Colorado
Posts: 273
Re: Invoking lisp code with .NET API

Quote:
Originally Posted by fabrizio View Post
After digging deeper into the .NET API doc, I have found a method in the Application class that does exactly what I was looking for. The method is:

Code:
public virtual object SendCommand(string str);
The documentation of this method also reports an example:

Code:
app.SendCommand("(delete_3d :all_at_top)");
So I have developed a test addin and added a menu button that invokes the call above. The result is that all the 3D models in the current OSDM session are actually deleted, but neither the viewport nor the browser are refreshed after the execution of the command. So the impression is that the command has no effect; but as soon as I click on the viewport or resize the browser they are refreshed and I can see that all the 3D models have actually been deleted.

Does anyone have an idea (or maybe just a hint) for the reason of this strange behavior?
Thanks for the update -- I'm glad it's working for you! The updates sometimes don't happen until there's some sort of user action (as you noticed). You can sometimes fool the system into thinking there has been user action by just sending an empty string to Modeling. So, in this case, you could try something like
Code:
app.SendCommand("(oli:sd-put-buffer "")");
though you'd need to escape the double quotes inside, of course.

I hope this helps!

andy
__________________
Andy Poulsen
AI MAXTools: Dream. Design. Done. It's that easy!
Add-ins bringing new functionality and speed to Creo Elements/Direct and CoCreate products. Now available for v17-v20+!
See them in action at www.ai-maxtools.com and then try them for yourself -- FREE!
Reply With Quote
  #4  
Old 11-25-2013, 07:37 AM
fabrizio fabrizio is offline
Registered User
 
Join Date: Jan 2003
Location: Parma - Italy
Posts: 34
Re: Invoking lisp code with .NET API

Hello Andy,
thank you for your kind reply. As you suggested, I have tried to send an empty string to the command buffer after the execution of the delete_3d command. This actually causes the viewport and the browser to update. But there's another problem with this technique: after the UI is updated, the confirm and cancel icons appear in the upper-left corner of the viewport (with Modeling 18.1). In other words, a command apparently remains "pending" after the execution of this code.

So I came up to this solution (C#) that executes the command, updates the UI and doesn't leave any open command in the end:
Code:
app.SendCommand("(progn (delete_3d :all_at_top) (oli:sd-put-buffer \"complete\"))");
Thank you very much for pointing me in the right direction.

Fabrizio
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 07:59 AM.



Hosted by SureServer    Forums   Modeling FAQ   Macro Site   Vendor/Contractors   Software Resellers   CoCreate   Gallery   Home   Board Members   Regional User Groups  By-Laws  

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.