Decap automation C#

Decap automation C#

jens.slofstra!
Enthusiast Enthusiast
472 Views
1 Reply
Message 1 of 2

Decap automation C#

jens.slofstra!
Enthusiast
Enthusiast

Hi everyone,

I was wondering if decap automation is possible with C#.

I found a python script that works but I want to use the script in an revit addin which is in C#.

Python code below:

<location>/decap.exe –importWithLicence E:\decap text\Building 1\ Building 1

Can somebody get me in the right direction.

Anyway thanks 🙂

0 Likes
Accepted solutions (1)
473 Views
1 Reply
Reply (1)
Message 2 of 2

jens.slofstra!
Enthusiast
Enthusiast
Accepted solution

After some more searching I found a work around. DeCap runs via the command prompt. So I open command prompt with C# and then run the command for DeCap.

Preview below:

//Process Info
                var cmdInfo = new ProcessStartInfo
                {
                    RedirectStandardInput = true,
                    RedirectStandardOutput = true,
                    RedirectStandardError = true,

                    UseShellExecute = false,
                    FileName = "cmd.exe",
                };

                //Process
                var cmd = new Process();
                cmd.StartInfo = cmdInfo;
                cmd.Start();

                var outStream = cmd.StandardOutput;
                var inStream = cmd.StandardInput;

                //Command Line for DeCap
                inStream.WriteLine("cd C:\\Program Files\\Autodesk\\Autodesk Recap");
                var run = true;
                var cmdTask = Task.Run(() =>
                {
                        while (run)
                        {
                            try
                            {
                                Console.WriteLine(outstream.ReadLine());
                            }
                            catch { }
                            Thread.Sleep(20);
                            if (outStream.ReadLine().Contains("[R]"))
                            {
                                _logger.LogInformation(@"File Converted: {0}\{1}", _LAZProcessed, LAZFile.Name);
                                run = false;
                            }
                        }
                    }
                });

                inStream.WriteLine("{0}decap.exe{0} --importWithLicense {0}{1}{0} {0}{2}{0} {0}{3}{0}", '"', _LAZProcessed, LAZFile.Name, LAZFile.FullName);
                while (!cmdTask.IsCompleted)
                    Thread.Sleep(1000);
0 Likes