Recent Posts

Pages: 1 2 [3] 4 5 ... 10
21
AutoLISP (Vanilla / Visual) / Re: Running External Programs
« Last post by MP on October 22, 2020, 05:40:14 PM »
Thank you, that did the trick

you're most welcome 👍

I am quite surprised at how well this is working

oh ye of little faith 🙃
22
AutoLISP (Vanilla / Visual) / Re: Running External Programs
« Last post by cmwade77 on October 22, 2020, 05:09:04 PM »
Use an instance of shell with the wait flag set to true (-1).
Bonus, set the visibility flag to 0 if you to hide execution.
The external program may override the latter.

e.g.

(progn
    (setq shell (vlax-create-object "WScript.Shell"))
    (vl-catch-all-apply 'vlax-invoke (list shell 'run "cmd.exe" 8 -1)))
    (alert "lol, there you are.")
    (vl-catch-all-apply 'vlax-release-object (list shell))
    (princ)
)


Thank you, that did the trick, I am actively getting there on my routine, I am quite surprised at how well this is working. I will eventually share the whole package, but there are a lot of pieces to it.
24
HI
TEST THIS

Code: [Select]


(vl-load-com)

(defun c:test (/ A11 A2 A3 ACDBBLOCKREFERENCE ATTDATA ATTRIBUTES^ ATTS LST PATTERN SS0)

 
 (if  (and
       (progn (initget 7)  (setq pattern(getint  "\nSpecify input NO : ")))
       (setq ss0 (ssget '((0 . "insert") (66 . 1))))
     )
  (progn
   
   
   (foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss0)))
;;;      (setq ename (mapcar'vlax-ename->vla-object(vl-remove-if 'listp (mapcar 'cadr (ssnamex ss0))))
    (setq AcDbBlockReference (vlax-ename->vla-object ename))
;;;    (setq attributes^ (vlax-invoke AcDbBlockReference 'GetAttributes))
    (progn
           (setq atts (vlax-invoke AcDbBlockReference 'getattributes))
           (foreach att atts
             (cond
                   ((wcmatch (vla-get-tagstring att) "DIAMETRU")
                    (setq a2 (vla-get-textstring att))
                   )
                   ((wcmatch (vla-get-tagstring att) "Lungimea")
                    (setq a3 (vla-get-textstring att))
                   )
             )
                 
           )
           (setq attdata (cons (list (atof a2) (atof a3) AcDbBlockReference) attdata))
         )
     )
;;;(setq attdata nil)
    ; sorts on 1st two items

   ;;BIGAL
      (setq lst (vl-sort attdata
'(lambda (a b)
    (cond
      ((< (car a) (car b)))
      ((= (car a) (car b)) (< (cadr a) (cadr b)))
    )
  )
)
)



   (foreach ename (mapcar 'caddr lst)
;;;      (setq ename (caDr (mapcar 'caddr lst)))
   
   
    (progn
           (setq atts (setq attributes^ (vlax-invoke ename 'GetAttributes)))
           (foreach att atts
;;;      (setq att (car atts))
     
             (cond ((wcmatch (setq a11(vla-get-tagstring att)) "Pozitia")
                     (vla-put-textstring att (RTOS pattern 2 0 ))
                   )
                   
                   
             )
                 
           )
     
           
         )
     (setq pattern (+ 1 pattern))
     )

   









   
  ); progn
 ); if

 (princ)
);



25
AutoLISP (Vanilla / Visual) / Re: Edit nested Text
« Last post by Biscuits on October 22, 2020, 02:28:33 PM »
Thanks guys. Both methods will be a great help.
Stay safe!
26
AutoLISP (Vanilla / Visual) / Re: Running External Programs
« Last post by cmwade77 on October 22, 2020, 02:25:05 PM »
What happens if you use Start?
I tried that and it kept launching another session of AutoCAD, no idea why.
27
.NET / Re: Background Workers
« Last post by John Kaul (Se7en) on October 22, 2020, 01:42:08 PM »
You can try poll(). Please note that my experience is in POSIX (c on unix) so I cannot be much help besides passing links and what not.

[ https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.poll?view=netcore-3.1 ]
28
.NET / Re: Background Workers
« Last post by MP on October 22, 2020, 01:31:48 PM »
Don’t know if this helps but ... I run multiple asynchronous console workers in the background, each launched by a manager that assigns a unique sentinel file to each worker process to create and populate with execution details as applicable when the worker has completed its task. The manager stays in a polling loop, performing the equivalent of a vba doevents call each nth iteration (so AutoCAD does not appear to have died) as well as looking for the sentinel files which flag completion, updating the screen if applicable with process percentages yada. If n seconds have been exceeded for a given worker it is assumed to have stalled, and subsequent measures can be taken including aborting the “wait” for said process to complete and / or killing it if applicable. The latter isn’t incorporated yet, tho I have written lisp code to kill processes in the past.

Lift what provides idea fodder, junk the rest. Cheers.
29
AutoLISP (Vanilla / Visual) / Re: Edit nested Text
« Last post by jtoverka on October 22, 2020, 01:09:29 PM »
Would like something like a command line version of find/replace.

I use this regularly. It has the option to find and replace block text. It is very robust. Although it is not command line, it can do multiple drawings in the background, and save a batch of find and replace options for the next time you run AutoCAD.

http://www.lee-mac.com/bfind.html
30
.NET / Background Workers
« Last post by jtoverka on October 22, 2020, 12:45:51 PM »
So to start,
I am aware that AutoCAD applications cannot have multiple threads running at the same time.
This is a hack that I am implementing and I only need to solve one tiny piece of the puzzle.

Before I go any further, I want to say that RealDWG is not in the cards for me at the moment.

So I am using accoreconsole.exe for my application. This is that console only command line interface. The idea is that I have the main application independent of AutoCAD running. When I need to perform an AutoCAD operation, I simply open the core console in the background (no console window displayed) and run the worker as an instance within the console. The worker needs to communicate back to the main Application. This is where I need help. The worker communicating to the main application. The main application needs to run code that only AutoCAD can execute.

So here is where I am at. I have a .NET Framework 4.7 project called LoadConsole with two files:
Program.cs
Code: [Select]
namespace LoadConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            LoadConsole.Console console = new LoadConsole.Console();
        }
    }
}

Console.cs
Code: [Select]
using System;
using System.Diagnostics;
using System.IO;

namespace LoadConsole
{
    /// <summary>
    /// Launches the accoreconsole and loads CAD UI.dll and opens main window
    /// </summary>
    public class Console
    {
        #region Fields

        private readonly Process coreprocess = new Process();

        #endregion

        #region Properties

        /// <summary>
        /// connected to loaded program in accoreconsole.
        /// </summary>
        public bool Connected { get; protected set; }

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of this class
        /// </summary>
        public Console()
        {
            try
            {
                string installpath = null;

                // Search the directory for the AutoCAD Console Application
                foreach (string file in Directory.GetFiles(@"C:\Program Files\Autodesk\", "accoreconsole.exe", SearchOption.AllDirectories))
                {
                    if (Path.GetFileName(file).Equals("accoreconsole.exe", StringComparison.OrdinalIgnoreCase))
                    {
                        installpath = file;
                        break;
                    }
                }

                // Set Process arguments
                coreprocess.StartInfo.Arguments = "/isolate";
                coreprocess.StartInfo.UseShellExecute = false;
                coreprocess.StartInfo.CreateNoWindow = true;
                coreprocess.StartInfo.RedirectStandardOutput = true;
                coreprocess.StartInfo.RedirectStandardInput = true;
                coreprocess.StartInfo.FileName = installpath;
               
                // Get worker dll, currently still the main application
                string loadDLL = Directory.GetCurrentDirectory() + "\\CAD UI.dll";

                // Start Process
                this.Connected = coreprocess.Start();

                // Load worker program
                if (this.Connected)
                {
                    using (StreamWriter writer = coreprocess.StandardInput)
                    {
                        writer.WriteLine("SECURELOAD 0");
                        writer.WriteLine("NETLOAD " + loadDLL);
                        writer.WriteLine("CAD_UI");
                        writer.Close();
                    }
                }
                else
                {
                    this.coreprocess.Close();
                    this.coreprocess.Dispose();
                }
            }
            catch
            {
                this.Connected = false;

                this.coreprocess.Close();
                this.coreprocess.Dispose();
            }
        }

        #endregion
    }
}

Right now, my CAD_UI.dll holds my main program. This can obviously execute AutoCAD code as it gets loaded into AutoCAD.

What I need is to use Worker.dll instead of CAD_UI.dll
CAD_UI will open as many instances of AutoCAD as deemed necessary, and it is necessary (I want to automate electrical drawings. 50~80 drawings per panel, 50~100 panels in a facility).
I would like all of my AutoCAD code in CAD_UI and Worker.dll is simply a communication interface between CAD_UI and AutoCAD. I am using every bit I can to squeeze as much performance as possible (side databases) and the like.
Pages: 1 2 [3] 4 5 ... 10