Merge all files in a directory from command line

Feel free to ask any question here
Post Reply
max72
Posts: 14
Joined: Fri Jul 31, 2015 9:47 pm

Merge all files in a directory from command line

Post by max72 »

Subject says all.
I would like to be able to run from command line a "merge all".
I would like to know if there is a simple way to do that.

Thanks in advance,
Massimo
max72
Posts: 14
Joined: Fri Jul 31, 2015 9:47 pm

Re: Merge all files in a directory from command line - and scaling intensity

Post by max72 »

A little update:
I was able to batch merge the files using the following commands (in a .bat file):

Code: Select all

echo|set /p= "C:\myccpath\cloudcompare.exe -SILENT -C_EXPORT_FMT E57 " > myrunfile.bat
for %%f in (%*) DO echo|set /p=-O  %%f >>myrunfile.bat
echo -MERGE_CLOUDS >>myrunfile.bat
myrunfile.bat

Drag and dropping the files in the bat file does the magic (change the ccpath to yours..).

Now I would also like to scale the intensity (0-1 range) to 0-65535. I tried the commands form the command line but I'm probably missing somthing.
Any suggestion?

Thanks in advance,
Massimo
daniel
Site Admin
Posts: 7470
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: Merge all files in a directory from command line

Post by daniel »

Thanks for the tip.

And for the second question, sadly there's no command for this right now. We will have to add this to the TODO list (we can probably add a new sub-option to the SF_ARITHMETIC option).
Daniel, CloudCompare admin
max72
Posts: 14
Joined: Fri Jul 31, 2015 9:47 pm

Re: Merge all files in a directory from command line

Post by max72 »

Thanks.
I have Faro files. They have the intensity range between 0 and 1 but I would like to share them using the laz format, so I have to scale the intensity.
At the moment I'm using Arena to "translate" them, but if I don't need to use the cloud in Arena a direct approach from the command line would be nicer and faster.
Anyway I really enjoy the power of the command line.
Thanks.
Massimo
mfloris
Posts: 12
Joined: Thu Sep 18, 2014 9:19 am

Re: Merge all files in a directory from command line

Post by mfloris »

If your cloud is an ASCII file you can easily do that with a VBScript

The following is an example of a script that reads all the *.asc files in a directory and creates a copy of the cloud skipping all the "NaN" lines, which are not supported by CloudCompare (the ShapeDrive 3D scanner outputs "NaN" for every pixel of its sensor that doesn't return a value)

Instead of the <<If Not point "Nan" Then >> etc. block you should split the string into a vector, access the element that corresponds to the intensity and multiply it by 65535 if I understood correctly what you need to do.

Hope it helps

Code: Select all


Dim fso, folder, files, strPath, strTxtFilName, point, outputFile

Set fso = CreateObject("Scripting.FileSystemObject")

Set objShell = CreateObject("Wscript.Shell")

strPath = objShell.CurrentDirectory &"\"

Set folder = fso.GetFolder(strPath)

Set files = folder.Files

For each folderIdx In files
    
	extension = fso.GetExtensionName(folderIdx.Name)

	If extension = "asc" Then
		
		strTxtFilName = fso.getbasename(folderIdx.Name)

		If not InStr(1, folderIdx.Name, "_NaN_parsed") > 0 Then
		
			Set listFile = fso.OpenTextFile(strPath & folderIdx.Name)
			
			Set outputFile = fso.CreateTextFile(strPath & strTxtFilName & "_NaN_parsed.asc", True)
		
			do while not listFile.AtEndOfStream 
		
				point = listFile.ReadLine()
		
				If not point = "NaN" Then
		
					outputFile.WriteLine(point)
		
				End If
			
			loop
			
			outputFile.Close
		
		End If
		
	End If
	
Next

max72
Posts: 14
Joined: Fri Jul 31, 2015 9:47 pm

Re: Merge all files in a directory from command line

Post by max72 »

Thanks!
I'm wondering if it would be possible to create a small wiki page with this kind of short scripts, that save so much time..
Massimo
Post Reply