Now it is time to build on the previous examples. This example does the following:
- Get the path of the User Language Program (ULP)
- It loops through all the parts
- As it loops it appends the part name to a file
dlgMessageBox("Do you want to count the parts?","Yes","No","Maybe"); //opens a dialog box: no matter what you answer it will count the parts.
//—— Get the ULP Path ——//
string ULP_Path;
char bkslash = '/';
int pos = strrchr(argv[0], bkslash);
if (pos >= 0)
{
ULP_Path = strsub(argv[0], 0, pos + 1);
}
//—— This is the loop that gets the parts and writes to file —–//
string FileLine;
int cnt=0;
output(ULP_Path + "ListOfParts.txt", "at")
{
if (schematic) schematic(S) //This nested set of loops cycle through all the parts and increment the count each pass through
{
S.parts(P)
{
P.instances(E)
{
printf(FileLine += E.name +"\n");
cnt++;
}
}
}
}
string result;
sprintf(result, "The parts count is %d", cnt);
dlgMessageBox(result, "+Yes", "No","Maybe"); // display the parts count in a dlgMessageBox
exit(0);
The result will look like this: ListOfParts.txt
0 Comments