-----Original Message-----
From: vincent mail [mailto:[EMAIL PROTECTED]]
Sent: Friday, August 02, 2002 6:36 AM
Subject: Re: [PDEV] protel basic scripting language

<snip>

in my schematic symbols i have already a field where i fill in this 
information. except that field does not get translated to the PCB data.

so my idea was to make a script that generates the pick and place , 
reads it and does a kind of 'cross-probe' with the schematic to retrieve 
this field

 <snip>


---------------

The following is a Protel script which fetches a schematic name; puts the
name in a file (to be passed to an executable which does most of the work)
runs the built in BOM which results in a .CSV file; the CSV file can be
parsed for part field information from the schematic.  The executable is
written in Pascal, but obviously could be C or whatever you would prefer (
possibly even ClientBasic, but methinks it is slow and my experience leads
me to not recommend it).
What I would do using this method: in ClientBASIC: invoke the BOM to
generate CSV; invoke Pick & Place report; call executable to parse CSV and
P&P report and generate output file as you require.


' Checkey.bas - ClientBasic macro for Protel 99 SE
' Compare schematic library_key against registered library_key 
' 
' Schematic must be in 'windows file system' DDB format
' 'csv_key.exe' v1.0  must be in c:\program files\design explorer 99 SE\ 
'
' 
'
Sub Main

Dim b      as Integer
Dim l      as Integer
Dim Fname  as String *255
Dim AFile  as String 
Dim BFile  as String

  
   ResetParameters
   
   AddStringParameter "DocumentType","SCH" 
   AddStringParameter "Prompt"',"Select Schematic for BOM report" 
   AddStringParameter "Dialog","ChooseDocument" 
   
   RunProcess "Client:RunCommonDialog" 
   
   GetIntegerParameter "Result", b
If b  Then
      GetStringParameter "FileName", Fname

'   Msgbox Fname     'diagnostic 

      ResetParameters
      AddStringParameter "DocumentName", Fname 
      RunProcess "Sch:ReportBOM" 
   
      ResetParameters
      RunProcess "Client:CloseDocument" 

      SetCursorBusy

'  Parse Filename string to get path
     b = InStr(1, Fname, "$RP") 'locate preceding field
     b = b + 4                    'set first char of path 
     l = InStr(1, Fname, "$RN") 'locate end of path 
     l = l - b                    'length of path 
     AFile = Mid(Fname, b, l) 'fetch path name 
     BFile = Mid(Fname, b, l) 'fetch path name for later use 
      
'  Parse Filename string to get schematic name 
     b = InStr(1, Fname, "$ON") 'locate preceding field
     b = b + 4                    'set first char of schematic name 
     l = InStr(1, Fname, "$ID") 'locate end of schematic name
     l = l - b                    'length of sch name 
     AFile = AFile + "\" + Mid(Fname, b, l) 'fetch schematic name

     l = Len(AFile)
     AFile = Mid(AFile, 1, (l-3))
     AFile = AFile + "sch" 'form lowercase extension for csv_key.exe
 
'   Msgbox AFile    'diagnostic  
    
     Open "C:\Program Files\Design Explorer 99 SE\bom_sch.tmp" For Output As
#1 
     Write #1, AFile 
     Close #1 
    
    
     ResetParameters
     RunApplication "C:\Program Files\Design Explorer 99 SE\csv_key.exe" 

     ResetCursor
  
Else 
      Msgbox "No File selected!!"   
End If

End Sub   
'---------------------------------------------------------------------------
-----------}



****************************************************************************
****************************************
Here is a subroutine (GetTokenFromCSVFormat) in Pascal which retrieves a
field from the CSV file

{---------------------------------------------------------------------------
-----------}
{ Report mismatched or missing Library Reference Keys from schematic ( CSV
file )    Revision 1.2 }
{                             }
{ Language : FreePascal v0.99.14  www.freepascal.org  }
{ }
{ v1.2 target: Protel99SE Schematic server -
}
{          schematic name passed in file BOM_SCH.TMP }
{          assume  bom_sch.tmp in C:\Program Files\Design Explorer 99 SE\  }
{  }
{          convert '*' in CSV to '' (null string) }
{  }      
{  }
{  30jan02 string variables converted to ansiString for
GetTokenFromCSVFormat }
{   }
{---------------------------------------------------------------------------
-----------}
{}
program CSV_Key;

type
    LibRefKeyStr = string[24];
    PartDescStr = string[32];
    DesignatorStr = string[6];

    FlagAry = array[1..650] of boolean;
    LibRefKeyAry = array[1..650] of LibRefKeyStr;
    PartDescAry = array[1..650] of PartDescStr;
    DesignatorAry = array[1..650] of DesignatorStr;

var
     AFile           : text;
     BFile           : text;
     CFile           : text;
     Str1            : ansiString;
     Str2            : string;
     Str3            : string;
     Str4            : string;
     FileName        : string;
     I,K,j,N,M,l     : integer;



     HoldPartDesc : PartDescAry;
     Checkbox : FlagAry;
     LibRefKey : LibRefKeyAry;
     HoldDesignator : DesignatorAry;

{---------------------------------------------------------------------------
-----------}
Function GetTokenFromCSVFormat(TokenNumber :Integer;CurrentLine
:ansiString):ansiString;
{ modified 22jan02 - works with comma in field                     }
{                  note - last field (sheet file name - 28) does not parse
correctly }
{  30jan02 string variables converted to ansiString for lines longer than
255 characters }      
var
    S1 : ansiString;
    j  : Integer;
    k  : Byte;
    L  : Integer;

begin
     S1:= CurrentLine;
     For j:= 1 To TokenNumber do
     begin
       if Pos(',',S1) <> 0 then k:= Pos('",',S1);
       L:= Length(S1);
       S1:= Copy(S1,k+2,L-(k+1));
     end;

     if Pos(',',S1) <> 0 then
     begin
          k:= Pos('",',S1);
          S1:= Copy(S1,1,k+1);
     end;
     
     if (Pos('"',S1) <> 0) And (Pos(',',S1) <> 0) then
     begin
        L:= Length(S1);
        S1:= Copy(S1,2,L-3);
     end;
 
     { If CSV field has default token (*) then convert to null string }
     if (S1 = '*') then 
     begin
          S1:= '';
     end;

     GetTokenFromCSVFormat := S1
     
end;

 

************************************************************************
* Tracking #: 1555C33BC27B804EA56CCEBAA8C636E6683A0F8D
*
************************************************************************

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* To post a message: mailto:[EMAIL PROTECTED]
*
* To leave this list visit:
* http://www.techservinc.com/protelusers/leave.html
*
* Contact the list manager:
* mailto:[EMAIL PROTECTED]
*
* Forum Guidelines Rules:
* http://www.techservinc.com/protelusers/forumrules.html
*
* Browse or Search previous postings:
* http://www.mail-archive.com/proteldevforum@techservinc.com
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Reply via email to