Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IFRs on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listing all assemblies in a folder 1

Status
Not open for further replies.

PSI-CAD

Computer
Feb 13, 2009
997
I know how to use ugpc.exe to check that a part is an assembly or not
But
I am looking for a .bat file to check all part in a given folder

Thanks in advance if you have this kind of .bat file


Regards
Didier Psaltopoulos
 
Replies continue below

Recommended for you

Here is a windows command script that I use to list the assemblies found in a folder. It doesn't resolve which is the top level assembly, but you can look at the list and deduce from there. Maybe someone has a way to improve on it:

Code:
@echo off
set base="C:\Program Files\UGS\NX 7.5\"
set base_dir=%base:"=%
set UGII_BASE_DIR=%base_dir%
set UGII_ROOT_DIR=%base_dir%\UGIIset PATH=%base_dir%\ugii;%PATH%
if exist "%base_dir%\ugopen\ufvars.bat" call "%base_dir%\ugopen\ufvars.bat" "%base_dir%"
if "%DISPLAY%" == "" set DISPLAY=LOCALPC:0.0
REM Begin CODE
REM Jeff Markus, April 2009
REM
echo ===========================
echo MTC NX 5.0 Assembly File Determine
echo Scanning UG NX PRT files...
mkdir c:\temp\asmtemp
mkdir c:\temp\asmtemp\confirmed
for %%X in (*.prt) do (ug_inspect %%X  | find "no components? FALSE" > c:\temp\asmtemp\%%X & echo %%X >> c:\temp\asmtemp\%%X)
echo The following files are assemblies:
pushd
c:
cd c:\temp\asmtemp
for %%X in (*.prt) do (findstr /M FALSE %%X) > c:\temp\asmtemp\confirmed\%%~nxX
cd confirmed
for %%X in (*.prt) do (if %%~zX EQU 0 del %%X)
i:
popd
for %%X in (c:\temp\asmtemp\confirmed\*.prt) do (ugpc %%~nxX & echo --)
del c:\temp\asmtemp\*.prt
del c:\temp\asmtemp\confirmed\*.prt
rmdir c:\temp\asmtemp\confirmed
rmdir c:\temp\asmtemp
echo Scan complete.
pause

Let me know if it helps!

Jeff
 
Hi Jeff,

Thanks a lot, I adapt it and it works very well.

Could you help me more:

1°) i would like to be able to open all subfolder (have a look at the attached jpeg)
2°) by sending the result in list_ass.txt

Thanks in advance


Regards
Didier Psaltopoulos
 
Didier.

Insert the three lines after the exiting line containing popd.

Modify the next exiting line to match the last line below.

Regards, Joe

Code:
...
popd
setlocal ENABLEDELAYEDEXPANSION
set dir_list= 
for /d %%i in (*) do @(echo "%%i" && set dir_list=-p%%i !dir_list!)
for %%X in (c:\temp\asmtemp\confirmed\*.prt) do (ugpc !dir_list! %%~nxX > list_ass.txt & echo --)
...
 
Hi Joe,

Thanks for your help

I have just one problem: list_ass.txt contain only the last assembly

Where is the error in the below lines ?
___________________________________________________________
@echo off
mkdir asmtemp
mkdir asmtemp\confirmed
for %%X in (*.prt) do (ug_inspect %%X | find "no components? FALSE" > asmtemp\%%X & echo %%X >> asmtemp\%%X)
echo The following files are assemblies:
pushd
for %%X in (asmtemp\*.prt) do (findstr /M FALSE %%X) > asmtemp\confirmed\%%~nxX
for %%X in (asmtemp\confirmed\*.prt) do (if %%~zX EQU 0 del %%X)
i:
popd
setlocal ENABLEDELAYEDEXPANSION
set dir_list=
for /d %%i in (*) do @(echo "%%i" && set dir_list=-p%%i !dir_list!)
for %%X in (asmtemp\confirmed\*.prt) do (ugpc !dir_list! %%~nxX > list_ass.txt & echo --)
echo Scan complete.
pause
________________________________________________________________________


Regards
Didier Psaltopoulos
 
Didier,

This change should output a file for each assembly named with the assembly name and an appended _list_ass.txt

Regards, Joe

Code:
for %%X in (asmtemp\confirmed\*.prt) do (ugpc !dir_list! %%~nxX > %%~nX_list_ass.txt & echo --)
 
Hi Joe,

Something is wrong because the folder asmtemp\confirmed contain only the main ass_panther.prt

AND

have a look at the ass_panther_list_ass.txt. It's a little bit confused


Regards
Didier Psaltopoulos
 
Didier,

OK, the report shows that the original assembly (saved on f:\ had some components in sub directories of sub directories. So the original location is displayed when the components are not found in the immediate sub directories (as shown in the original image).

The ugpc.exe utility does not support the "..." notation to walk the directory tree like the "File-> Options -> Load Options" load options does.

Hopefully the code below will include the subordinate lower level(s) of sub directories in addition to the immediate sub directories.

This script is reporting for the assembli(es) in the top level directory and there will be a report file for each top level assembly (which will contain parts and sub assemblies from the sub directories). It is not intended to generate a report for each sub-assembly (which would be somewhat redundant if the top level assembly report works since the sub directory sub assemblies are listed in the report.)

HTH, Joe

Code:
for /d %%i in (*) do @(echo "%%i" && set dir_list=-p%%i !dir_list!)

Code:
for /r . %%i in (.) do @(set zz=%%i&&set xx=!zz:~0,-2!&&set dir_list=-p!xx! !dir_list!)

 
Hi Joe,

Could you add some indentation in the listing because component and assembly are mixed ?

TIA


Regards
Didier Psaltopoulos
 
Didier,

This will use 4 space indention - edit the "-s" value as desired.

HTH, Joe

Code:
for %%X in (asmtemp\confirmed\*.prt) do (ugpc -s4 !dir_list! %%~nxX > %%~nX_list_ass.txt & echo --)
 
Hi Joe,

The prog works well without sub folder [dazed]


Could you test the programm with my sub folders because the result is not good: the folder "confirmed" doesn't contain the list of sub assy !!!

The attached zip file contain some component ans sub assembly of my big assembly.


Thanks in advance


Regards
Didier Psaltopoulos
 
Didier,

I am glad you included your batch file. The leading "!" from (Dec 19 9:49) !dir_list! was missing.

I've revised the code to also generate a file of the components that could not be found in the directory or sub directories. The file is named with the assembly name and the _missing.txt suffix and extension. The file will show the path that was last used for the component when the assembly was most recently saved.

Code:
@echo off
@echo off
REM Begin CODE
REM Jeff Markus, April 2009
REM
mkdir asmtemp > nul 2>&1
mkdir asmtemp\confirmed > nul 2>&1
for %%X in (*.prt) do (ug_inspect %%X  | findstr /c:"no components? FALSE" > asmtemp\%%X & echo %%X >> asmtemp\%%X)
echo The following files are assemblies:
for %%X in (asmtemp\*.prt) do (findstr /M /c:"FALSE" %%X) > asmtemp\confirmed\%%~nxX
for %%X in (asmtemp\confirmed\*.prt) do (if %%~zX EQU 0 del %%X)
dir /b asmtemp\confirmed\*.prt
setlocal ENABLEDELAYEDEXPANSION
set dir_list=
for /d %%i in (*) do @(set dir_list=-p%%i !dir_list!)
for %%X in (asmtemp\confirmed\*.prt) do (ugpc -s4 !dir_list! %%~nxX > %%~nX_list_ass.txt 2> %%~nX_missing.txt& echo --)
echo Scan complete.
REM pause

I seemed to have failed in my explanation on Dec 19th (14:47) to communicate that the utility was not intended to generate separate files for all levels of sub assemblies.

If you want to use the utility to report on the top level assembly and to repeat that processing for each sub directory and process the assemblies in the sub directories you might consider using the following to invoke the existing utility "for an entire directory tree."

If the existing utility is named for instance, d:\tools\list_assy_in_dir.bat the code below will process the current directory (the normal behavior) and it will reinvoke the utility for each sub directory and report on any assemblies in the sub directories

Code:
for /d %i in (*) do @(pushd %i&& d:\tools\list_assy_in_dir.bat && popd)

Alternatively the name of the top level directory can also be included in the command. If, for example, the directory of the top level assembly were e:\directory\subdir\top_level_assy_directory


Code:
for /d e:\directory\subdir\top_level_assy_directory %i in (*) do @(pushd %i&& d:\tools\list_assy_in_dir.bat && popd)


Regards, Joe
 
Didier,

In my example I have the full path to the list_assy_in_dir.bat. In the screen shot it seems that there is no path to the the script specified. Please try specifying the path explicitly.

Thanks,
Joe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor