cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Relations to get the first component in an assembly

STEVEG
21-Topaz I

Relations to get the first component in an assembly

Some of our assemblies our MFG guys make have only one component in it. That one component is of the released assembly from our designer engineers. I am trying to set up a few things automatically. In the relations of the top level assembly I want to make a parameter equal to the name of the one and only component. I.e.: The BOM for MFG_ASM has DES_ASM model only. The BOM for DES_ASM has DES_PRT1, DES_PRT2, DES_PRT3, etc.


I want to write a relation that saysthe parameter PARAM1 in MFG_ASM equals the file name of its only component DES_ASM. What is the syntax for it. For the life of me I can notget it to work and couldn'tfind the answer.

Steve G


This thread is inactive and closed by the PTC Community Management Team. If you would like to provide a reply and re-open this thread, please notify the moderator and reference the thread. You may also use "Start a topic" button to ask a new question. Please be sure to include what version of the PTC product you are using so another community member knowledgeable about your version may be able to assist.
2 REPLIES 2
STEVEG
21-Topaz I
(To:STEVEG)

I only received one response. Session ID. Going through a procedure to use it was working. However, Tom really cautioned me about using it and I appreciate the concern.

In the relation dialog box type NAME=REL_MODEL_NAME:<session_id>

So I was typing up the procedure and realized another way to get the info without using the session id. It involves using a batch file with a mapkey. And the batch file is pretty simple.

I created a mapkey that outputs the BOM.
The mapkey then calls a batch file that gets the name of the top-level assembly and puts it into a variable.
Then the batch file outputs to another text file all the relations I need which includes the name of the design assembly from that variable.
The mapkey then continues by going into the relations and importing the text file of the relations and verifies them.
Lastly it will delete these temporary text files.

Even if the user copies that asm and drw instead of using the template, the mapkey and batch file will update it all.

Maybe that is a little crude but it's the only sure way I can think of.

Steve G
STEVEG
21-Topaz I
(To:STEVEG)

Well I have already had a couple requests to share so here goes. I'm sure this could probably be coded a little better but this is what worked so I stuck with it. I hope it helps others as well. And if you can make it better please share.

After my mapkey exports the bom report then at the bottom is my batch file with an explanation immediately below.

Our mfg drawings always start with MAL. So the batch file looks in the directory for that file
dir /b mal*.bom.* > mal_bom_rpt.txt

The first 'for' statement gets the name of the file and puts it in a variable
for /f %%a in (mal_bom_rpt.txt) do set MALBOM=%%a

The BOM report is formatted, obviously, such that the highest level assembly is the first one listed so...
The second 'for' statement looks for the first line that has "Sub-Assembly".
If the second variable in that line equals "Sub-Assembly" then it sets the third variable to another variable to that name and will exit the loop so it won't read any other "Sub-Assemby" that is within it. That is the only way I know of to exit the loop if there are sub-sub-assemblies. Once it finds it then it exits by going to the next section
for /f "tokens=2-3" %%a in (%MALBOM%) do (
if %%a==Sub-Assembly (
set MANIFOLDASM=%%b
goto INFO)
)

The last part is to output the relations I need to a text file
:INFO
echo DESCRIPTION_LINE2="HF%MANIFOLDASM%" > C:\D_Drive\trails\mal_rel.txt
echo PROJECT_NUMBER=DESCRIPTION_LINE2 >> C:\D_Drive\trails\mal_rel.txt
echo DESCRIPTION=REL_MODEL_NAME >> C:\D_Drive\trails\mal_rel.txt

The mapkey continues and goes into the relations, clears out any existing info by using the Edit > Select All, Edit > Delete.
Then it uses the File > Import to import that text file and verifies the relations.
The last thing this mapkey does is deletes the three files.

The whole batch file put together:

C:
cd C:\D_Drive\%username%_workspace
dir /b mal*.bom.* > mal_bom_rpt.txt
for /f %%a in (mal_bom_rpt.txt) do set MALBOM=%%a

for /f "tokens=2-3" %%a in (%MALBOM%) do (
if %%a==Sub-Assembly (
set MANIFOLDASM=%%b
goto INFO)
)

:INFO
echo DESCRIPTION_LINE2="HF%MANIFOLDASM%" > C:\D_Drive\trails\mal_rel.txt
echo PROJECT_NUMBER=DESCRIPTION_LINE2 >> C:\D_Drive\trails\mal_rel.txt
echo DESCRIPTION=REL_MODEL_NAME >> C:\D_Drive\trails\mal_rel.txt


Steve G
Top Tags