×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Listing all assemblies in a folder

Listing all assemblies in a folder

Listing all assemblies in a folder

(OP)
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
http://www.psi-cad.com

RE: Listing all assemblies in a folder

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

RE: Listing all assemblies in a folder

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 --)
... 

RE: Listing all assemblies in a folder

(OP)
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
http://www.psi-cad.com

RE: Listing all assemblies in a folder

Didier,

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

Regards, Joe

CODE --> DOS

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

RE: Listing all assemblies in a folder

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 --> (old)

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

CODE --> (new)

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

RE: Listing all assemblies in a folder

(OP)
Hi Joe,

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

TIA


Regards
Didier Psaltopoulos
http://www.psi-cad.com

RE: Listing all assemblies in a folder

Didier,

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

HTH, Joe

CODE --> DOS

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

RE: Listing all assemblies in a folder

(OP)
Hi Joe

Thanks a lot. I will try it tommorrow


Regards
Didier Psaltopoulos
http://www.psi-cad.com

RE: Listing all assemblies in a folder

(OP)
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
http://www.psi-cad.com

RE: Listing all assemblies in a folder

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 --> DOS

@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 --> DOS

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 --> DOS

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


Regards, Joe

RE: Listing all assemblies in a folder

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources