Language = "VBSCRIPT"
' Purpose:       Get a Title Block and fill Entries
'
' Assumptions:   A Drafting document should be active
'
' Author:        M. Neukirchen
'
' Languages:     VBScript
' Version:       V5R9 SP2, V5R9 GA
' Reg. Settings: English (United States)
' ****************************************************************************
'**************************************************************************
' PROGRAM: Text_block
'**************************************************************************
'                        IBM Product Lifecyle Management Solutions
'                        Engineering e-Business
'
' (C) COPYRIGHT International Business Machines Corp. 2002
'**************************************************************************
'                	Erstellt: 01.09.2000      Name: M. Maier
'                	Update  : 20.07.2001      Name: M. Neukirchen
'			18.08.2001	V 2.1.1
'					Suppport of multiple sheets
'					Configuration Path to sInstallDir
'			05.11.2001	V 2.2.0   M. Neukirchen
'					Execute external program with ExecuteProcessus
'					Naming Convention according to Dassault Macros
'					Copy data from template to current sheet
'					exchange title block data
'			03.12.2001	V 2.2.1   M. Neukirchen
'					temp directory from environment
'			15.12.2001	V 2.3.0   M. Neukirchen
'					some compatibility with TeamPDM
'					Step1 : Drawing / Sheet fields
'			01.06.2002	V 2.3.1   M. Neukirchen
'					Error exchange frame fixed.
'			24.06.2002	V 2.3.2   M. Neukirchen
'					Re-activation of active view
'			02.08.2002	V 2.3.3   M. Neukirchen
'					regexp 					-> IBMReplace
'					\ 						-> / for Unix
'				    Split 					-> IBMSplit
'					VB file system object 	-> CATIA file system object
'					VB temp folder 			-> /tmp or VB special Folder on Windows
'					BackGroundView			-> integrated feedback from Helbling
'			01.10.2002	V 2.3.4   M. Neukirchen
'					Bugfix for parameters, copy of frames
'			03.10.2002  V 2.4.0
'					Parameter handling from M. Röcker
'					info on td1 compatibility
'			14.10.2002  V 2.4.1
'					Performance optimization, delete Parameters only if necessary
'
'
'**********************************************************************************


'-------------------------------------------------- change path for your installation ----------
const sInstallDir = "C:\data\data_actual\src\catia\title_block\v2.4.1"
'const sInstallDir = "/usr/DassaultSystemes/TBlock/v2.4.0"
const os = "windows"

'	Unix only
Const Wish_Command = "/usr/local/bin/wish8.3"
'------------------------------------------------------------------------------------------------

public fs 					as object
public communication_1	 	as string
public communication_2 		as string

public command_edit     	as string
public command_select  	 	as string
public work             	as string
Public sValues(100) 		As String
Public sNames (100) 		As String
public iNumNames 			as Integer

public DrwDocument   		as object
public DrwSheets     		as object
public DrwSelection  		as object
public DrwSheet      		as object
public DrwView       		as object
public DrwViewActive 		as object
public DrwViews      		as object
public DrwGeomElems  		as object
public DrwTexts      		as object
public ActiveWindow  		as object
public trace_dat     		as object

public cur_sheet_active		as object
public cur_view_active		as object
public cur_sheet_background as object
public iTitleblockTexts 	as integer

public call_method   		as string
public is_init       		as string
public td1_configured		as boolean
public num_td1_parms		as integer
public td1_parm_params	(100)
public td1_parm_ids		(100)
public td1_parm_visible	(100)
public td1_parm_sheet1	(100)

'-------------------------------------------------------------------------------
' ------------ Main Loop
'-------------------------------------------------------------------------------

Sub CATMain()
	msgbox "Hello World"
'	IBMinit
'	for i = 0 to drawing_count - 1
'	   msgbox args(i)
'	next 
'	IBM_exit
End Sub

'-------------------------------------------------------------------------------
' ------------ Add a new title block
'-------------------------------------------------------------------------------

Function CATDrw_AddTitleBlock (sMode as String) as String
	Dim CatiaFile as String
	IBMinit
	CatiaFile = IBMGetCatiaTemplate(sMode)
	CATDrw_AddTitleBlock = "ok"
	If CatiaFile = "cancelled" then
		CATDrw_AddTitleBlock = "cancelled"
		Exit Function
      Else
		IBMGetTitleBlock(CatiaFile)
	End If
End Function

'-------------------------------------------------------------------------------
' ------------ Call the Gui to edit title block entries
'-------------------------------------------------------------------------------

Sub CATDrw_EditTitleBlock()
	IBMinit
	ScanModel
	work = "calling edit"  			'if something goes wrong, avoid loop in main
	if iTitleblockTexts > 0 then		'has scan model found Title Block Texts
		ExecuteOS command_edit
		ModifyModel
	else
		iback = MsgBox ("No Title Block entries found in sheet, ok to delete background", vbOKCancel)
		if iback = vbOK then
			IBMinit
			CATRemoveAll
			CATDrw_AddTitleBlock("init")
			ScanModel
			ExecuteOS command_edit
			ModifyModel
		end if
	end if
End Sub
'-------------------------------------------------------------------------------
' ------------ change titel blocks
'-------------------------------------------------------------------------------

Sub CATDrw_ExchangeTitleBlock(sMode as String)
	Dim sCatiaFile as String
	IBMinit
	if CATCheckRef()=1 then
		sCatiaFile = IBMGetCatiaTemplate(sMode)
		if sCatiaFile = "cancelled" then
			exit sub
		end if
		ScanModel						'scan contents of title block
		CATRemoveAll					'clear background view in current model
		IBMGetTitleBlock(sCatiaFile)	'get the title block from template
'		IBMinit							'set the current drawing info active
		ModifyModel
	else
		msgbox "title identifier not found, change impossible"
	end if
End Sub

'-------------------------------------------------------------------------------
' ------------ Init everything
'-------------------------------------------------------------------------------

sub IBMinit ()
	HKOMM=chr(34)
	dim fields(20)
	if is_init = "initialised" then
	else
		is_init = "initialised"
		set fs = CATIA.FileSystem

		if os = "windows" then
			set fso = CreateObject("Scripting.FileSystemObject")
			sTempFolder = fso.GetSpecialFolder(2)
			set fso = nothing
		else
			sTempFolder = "/tmp"
		end if

		trace_dat_name = sTempFolder & "\cat_title_block_trace.txt"

		batch_config	   = sInstallDir & "\config\batch_sample.cfg"
		set args = WScript.Arguments
'		script_name = Wscript.ScriptFullName
'		script_directory = fso.GetFile(script_name).ParentFolder
'

		drawing_count = args.count 

		if not os = "windows" then
			trace_dat_name	= IBMReplaceChar (trace_dat_name, "\","/")
			batch_config	= IBMReplaceChar (batch_config	, "\","/")
		end if

		Set trace 		= fs.CreateFile(trace_dat_name,True)
	 	set trace_dat 	= trace.OpenAsTextStream("ForWriting")

		' check for td1 compatibility

		if fs.FileExists(batch_config) Then
			num_maps  = 0
			Set batch_in 		= fs.GetFile(td1_config)
		 	set batch_stream 	= batch_in.OpenAsTextStream("ForReading")
    		Do until bacth_stream.atEndOfStream
    	   		zeile = batch_stream.ReadLine
    	   		if not mid(zeile,1,1) = "'" then
           			num_fields = IBMSplit(fields,zeile, ";")
					batch_in		(num_maps) = fields(0)
					bacth_out		(num_maps) = fields(1)
           			num_maps 				   = num_maps + 1
           		end if
           	Loop
           	batch_stream.close
		end if

		Set DrwDocument 	= CATIA.ActiveDocument
		Set DrwSheets   	= DrwDocument.Sheets
  		Set DrwSelection	= DrwDocument.Selection
  		Set cur_sheet_active= DrwSheets.ActiveSheet
		Set DrwViews		= cur_sheet_active.Views
		Set cur_view_active = DrwViews.ActiveView

	end if


	Set DrwDocument 	= CATIA.ActiveDocument
	Set DrwSheets   	= DrwDocument.Sheets
  	Set DrwSelection	= DrwDocument.Selection
  	Set DrwSheet    	= DrwSheets.ActiveSheet
	Set DrwViews		= DrwSheet.Views
	Set DrwViewActive	= DrwSheet.Views.ActiveView

'	IBMActivateBackgroundView(DrwViews)
'	Set DrwBckView		= DrwViews.ActiveView
	Set DrwBckView		= IBMGetBackgroundView(DrwViews)

	Set DrwTexts		= DrwBckView.Texts
	Set DrwGeomElems	= DrwBckView.GeometricElements

end sub

'-------------------------------------------------------------------------------
' ------------ Execute an OS command
'-------------------------------------------------------------------------------

sub ExecuteOS(command)
	return = CATIA.SystemService.ExecuteProcessus(command)
end sub

'-------------------------------------------------------------------------------
' ------------ Clean all and go
'-------------------------------------------------------------------------------

Sub IBM_exit ()
'	cur_sheet_active.Activate -> activates 'Hintergrund' Mode
	cur_view_active.Activate
End Sub

'-------------------------------------------------------------------------------
' ------------ Copy a title block frame from another drawing
'-------------------------------------------------------------------------------

Sub IBMGetTitleBlock(CatiaFileName As String)

	Dim height as double
	Dim width  as double

  	CATIA.StatusBar = "IBMGetTitleBlock"

	set model = CATIA.Documents.Open(CatiaFileName)

 	Set FromDrwDocument = CATIA.ActiveDocument
  	Set FromDrwSheets   = FromDrwDocument.Sheets
  	Set FromSelection   = FromDrwDocument.Selection
  	Set FromDrwSheet    = FromDrwSheets.ActiveSheet
  	Set FromDrwViews    = FromDrwSheet.Views
	Set FromDrwWindow	= CATIA.ActiveWindow

    DrwSheet.PaperSize   = FromDrwSheet.PaperSize				'get setup info and copy
	if FromDrwSheet.Papersize = CatPaperUser then
		DrwSheet.SetPaperHeight(FromDrwSheet.GetPaperHeight())
		DrwSheet.SetPaperWidth (FromDrwSheet.GetPaperWidth())
	end if
	DrwSheet.Scale2      = FromDrwSheet.Scale2
	DrwSheet.Orientation = FromDrwSheet.Orientation

 	FromSelection.Add (IBMGetBackgroundView(FromDrwViews))

  	CATIA.ActiveDocument.Selection.Copy()
	CATIA.ActiveDocument.Selection.Clear()

 	DrwDocument.Activate
  	DrwSheet.Activate

	CATIA.ActiveDocument.Selection.Clear()
 	CATIA.ActiveDocument.Selection.Add (DrwViews)


  	CATIA.ActiveDocument.Selection.Paste()
	CATIA.ActiveDocument.Selection.Clear()

	FromDrwWindow.Close
	FromDrwDocument.Close

	DrwViewActive.Activate

End Sub

'-------------------------------------------------------------------------------
' ------------ Prompt the user for a title block frame
'-------------------------------------------------------------------------------

function IBMGetCatiaTemplate (sMode as String) as String
	if sMode = "init" then
      	ExecuteOS(command_select)
	end if
' 	set datei = fs.OpenTextFile(communication_2)
 	set data_set= fs.GetFile(communication_2)
 	set stream 	= data_set.OpenAsTextStream("ForReading")
       	IBMGetCatiaTemplate = stream.ReadLine
	stream.close
end function

'-------------------------------------------------------------------------------
' ------------ Scan the actual view for title block entries
'-------------------------------------------------------------------------------
sub ScanModel ()
'   Scan the model, try to find title block entries
'   Name of texts must start with cat_title_block
'	set datei = fs.CreateTextFile(communication_1,true)
 	set data_set= fs.CreateFile(communication_1, True)
 	set datei 	= data_set.OpenAsTextStream("ForWriting")

	Dim Texts 	As DrawingTexts
	Dim oView 	As Object
	Dim oText 	As Object
	Dim cSheets As Object
	Dim oSheet 	As Object
	Dim cDrawingParameters As Object
	Dim oParameter As Object
	Dim sReplString As String
	Dim sfound (20)
  	On Error Resume Next

	On Error goto 0

'	Get the active sheet
	Set oSheet = CATIA.ActiveDocument.Sheets.ActiveSheet
	datei.write "cat_active_sheet§" & oSheet.name & vbCrlf
	if td1_configured then
		datei.write "cat_configuration§td1" & vbCrLf
	end if

	Set cSheets = CATIA.ActiveDocument.Sheets

	iTitleblockTexts = 0

'	Get all sheets

	For Each oSheet In cSheets

		Set Views = oSheet.Views ' get the collection of views

'		check for 3d references
		links_found = 0
		For Each oView In Views
			if links_found = 0 then
				links_found = CATLinks (0, datei, oView, oSheet)
			else
				links_found = CATLinks (1, datei, oView, oSheet)
      		end if
		Next

		set oActiveView = Views.ActiveView

		set oView = IBMGetBackgroundView (Views)

		Set Texts = oView.Texts	' gets the collection of texts
		lBlock = 0
		if Texts.Count > 0 Then
			For Each oText In Texts
				name = oText.Name

'				Fits text to naming convention?
				If Left(name,15) = "TitleBlock_Text"  Or Left(name,18) = "RevisionBlock_Text" Then
					if lBlock = 0 Then
		        		lBlock = 1
						datei.Write "cat_sheet" & "§" & oSheet.name & "§" & oView.name  & vbCrLf
					End If
					iTitleblockTexts = iTitleblockTexts + 1
					datei.Write oText.name & "§" & IBMReplaceChar (oText.Text, vbLF, "%%") & vbCrLf
				End If

			Next
		End If

	Next
	datei.Write "cat_sheet_end" & vbCRLF

	datei.close
end sub

Function CATLinks(imode, datei, oView, oSheet) As Integer
  	CATLinks = 0

  '-------------------------------------------------------------------------------
  'How to fill in texts with data of the part/product linked with current sheet
  '-------------------------------------------------------------------------------
    	On Error Resume Next
    	Dim ProductDrawn As ProductDocument
    	Set ProductDrawn = oView.GenerativeBehavior.Document

    	If Err.Number = 0 Then
			CATLinks = 1
    		if imode = 0 then
				datei.Write "cat_generative_3dmodel" & "§" & osheet.Name & "§" & oView.Name & "§" & ProductDrawn.Parent.FullName  & vbCrLf
				datei.Write "cat_generative_sheet_Number" & "§" & ProductDrawn.PartNumber  & vbCrLf
				datei.Write "cat_generative_sheet_Title" & "§" & ProductDrawn.Definition  & vbCrLf
				datei.Write "cat_generative_sheet_Revision" & "§" & ProductDrawn.Revision  & vbCrLf
				datei.Write "cat_generative_sheet_Nomenclature" & "§" & ProductDrawn.Nomenclature  & vbCrLf
				datei.Write "cat_generative_sheet_Source" & "§" & ProductDrawn.Source  & vbCrLf

      			Dim ProductAnalysis As Analyze
		      	Set ProductAnalysis = ProductDrawn.Analyze
				datei.Write "cat_generative_sheet_Weight" & "§" & FormatNumber(ProductAnalysis.Mass,2) & vbCrLf
				datei.Write "cat_generative_sheet_Volume" & "§" & FormatNumber(ProductAnalysis.Volume,2) & vbCrlf
				datei.Write "cat_generative_sheet_WetArea" & "§" & FormatNumber(ProductAnalysis.WetArea,2) & vbCrlf
			else
				datei.Write "cat_generative_3dmodel" & "§" & osheet.Name & "§" & oView.Name & "§" & ProductDrawn.Parent.FullName  & vbCrLf

			end if
    	End If
    	Err.Clear
		on error goto 0

End Function


'-------------------------------------------------------------------------------
' ------------ Modify the title block entries
'-------------------------------------------------------------------------------

sub ModifyModel ()
	'  Scan the model, try to find title block entries
	'  Name of texts must be equal to names in data set
	Dim cTexts As DrawingTexts
	Dim obj as Text
	Dim oView As Object
	Dim cViews As Object
	Dim cSheets As Object
	Dim oSheet As Object
	Dim cDrawingParameters As Object
	Dim fields (20)
	Dim sParms(100)
	Dim sTexts(100)

	if fs.FileExists(communication_1) then
 		set data_set= fs.GetFile(communication_1)
 		set datei 	= data_set.OpenAsTextStream("ForReading")
	end if

	Set cSheets = DrwDocument.Sheets
	Set cDrawingParameters = DrwDocument.Parameters

	if td1_configured then	' initialise td1 related control variables
		parmDirtyFlag = false
		parmMissing   = false
		errorstring   = "Entry(ies) disconnected:" & vbCrLF
		errorparms    = "Parameter(s) missing:" & vbCrLF
	end if

    Do until datei.atEndOfStream
    	   	zeile = datei.ReadLine
           	num_fields = IBMSplit(fields,zeile, "§")
           	' separate variables
           	s_check = fields(0)

           	if s_check = "work" then
                   work = fields(1)

            elseif s_check = "cat_sheet" then
                   sheet_name 	= fields(1)
                   view_name  	= fields(2)
                   iNumNames	= 0

            elseif left(s_check,13) = "cat_sheet_end" then

					For blNr = 1 to cSheets.count  			'Get the right sheet
						if cSheets.item(blNr).name = sheet_name Then
							set oSheet = cSheets.item(blNr)
							Exit For
						end if
					Next


					Set cViews = oSheet.Views
					Set cTexts = IBMGetBackgroundView(cViews).Texts

					For Each obj In cTexts
						name = obj.Name
						For i = 1 to iNumNames
							If sNames(i) = name Then
								temp = sValues(i)
								sTemp = IBMReplaceChar(temp,"%%",vbLF)   'check for newlines
								if td1_configured then
							   		for j = 0 to num_td1_parms - 1 ' is parameter associated?
					        			if td1_parm_sheet1(i)="false" or blNr <> 1 then
								   			if obj.Name = td1_parm_ids(j) then   ' get parameter object
												found = false
								   				for each oParameter in cDrawingParameters
									   				if oParameter.Name = "Drawing\"&td1_parm_params(j) then
   														found = true
   														oParameter.ValuateFromString (sTemp) ' set Parameter Value
   														if not obj.Text = sTemp then ' mismatch of values
   															parmDirtyFlag = true
   															errorstring = errorstring & sheet_name & ":" & obj.Name & vbCrLf
   															obj.Text = sTemp
   														end if
'  														obj.InsertVariable 0, len(obj.Text)+1, oParameter
   														exit for
													end if
												next
												if not found then ' parameter is missing
													obj.Text = sTemp
													errorparms = errorparms & sheet_name & ":" & obj.Name & vbCrLf
											    	parmMissing = true
												end if
   											end if
					     	    		end if
   									next
   									if not found then ' edit the text anyway
   										obj.Text = sTemp
   									end if
								else
									obj.Text = sTemp
   								end if

							End If
						Next
					Next

            Else
           			iNumNames = iNumNames + 1
               		sNames (iNumNames) = fields(0)
           			sValues(iNumNames) = fields(1)
           	End If

	Loop
	datei.close

	if td1_configured then  ' do we have text entries, which have wrong entries
		if parmMissing then ' --> parms missing
			errorstring = errorparms & "Create and reconnect Parameters?"
		elseif parmDirtyFlag then ' --> disconnected
			errorstring = errorstring & "Reconnect Parameters?"
		end if
		if parmMissing or parmDirtyFlag then
			answer  = msgbox (errorstring, vbYesNo)
			if answer = vbYes then
				deleteTD1Parms
				createTD1Parms
			end if
		end if
	end if

	CATIA.StatusBar = "Modification done"
end sub


' check, if a suitable title block is in the model

Function CATCheckRef() As Integer
	CATCheckRef = 0
  	for i = 1 to DrwTexts.Count
    		If (Left(DrwTexts.Item(i).Name,11) = "TitleBlock_") Then
    			CATCheckRef = 1
    			Exit Function
    		end if
  	next
End Function

Sub CATRemoveAll()
'	DrwSelection.Clear()			'I don't understand it
'	DrwSelection.Add(DrwGeomElems)
'	DrwSelection.Add(DrwTexts)
'  	DrwSelection.Delete

End Sub

'-------------------------------------------------------------------------------
' ------------ Get the backgroung view
'-------------------------------------------------------------------------------

Function IBMGetBackgroundView (Views as object) as object
	Dim MyPrefix as CATBSTR
	Dim MyIdent as CATBSTR
	Dim MySuffix as CATBSTR
	Dim oView    as object

	MyPrefix = "                             "
	MyIdent  = "                             "
	MySuffix = "                             "

	For Each oView In Views
		oView.GetViewName MyPrefix,MyIdent, MySuffix

		if left (MyPrefix,15) = "Background View" then
			Set IBMGetBackgroundView=oView
			Exit Function
		end if
	Next
'   Background View not found, take item(2) --> Helbling info (thanx)
    IBMGetBackgroundView = Views.Item(2)
End Function

Function IBMBackgroundViewIsEmpty (Views as object) as Boolean
	num_elems = IBMGetBackgroundView(Views).GeometricElements.Count + IBMGetBackgroundView(Views).Texts.Count
	if num_elems = 1 then			'Hauptachse ist vorhanden
		IBMBackgroundViewIsEmpty = True
	else
		IBMBackgroundViewIsEmpty = False
	end if
end function

Function IBMReplaceChar (in_string, char_search, char_replace)
	out = ""
	ls = len(char_search)
	for i = 1 to len(in_string)
		if mid (in_string,i,ls) = char_search then
			out = out & char_replace
			i = i + ls - 1
		else
			out = out & mid (in_string,i,1)
		end if
	next
	IBMReplaceChar = out
end function


Function IBMSplit (out_field, text,char_split)
	numfields = 0
	out = ""
	for i = 0 to 20
		out_field (i) = ""
	next
	for i = 1 to len(text)
		if mid (text,i,1) = char_split then
			out_field (numfields) = out
			numfields = numfields + 1
			out = ""
		else
			if i = len(text) then
			    out = out & mid (text,i,1)
				out_field (numfields) = out
				numfields = numfields + 1
			else
				out = out & mid (text,i,1)
			end if
		end if
	next
	IBMSplit = numfields
End Function

Function IBMGetByName (cCollection, name) as object
	for each oElem in cCollection
	    if oElem.name = name then
	       set IBMGetByName = oElem
	       exit function
	    end if
	next
end function

Sub deleteTd1Parms
' Thanx to Martin Röcker!
' Kill existing parameters
  	CATIA.StatusBar = "Deleting Paramters"
  	on error resume next
  	Set cDrwParams = CATIA.ActiveDocument.Parameters
  	if err.number = 0 then
    'all Parameters defined in td1_config data set
		max_count = cDrwParams.count
		For idx = max_count to 1 step -1
			oParam = cDrwParams(idx)
      		if not oParam.readonly then
      			for i = 0 to num_td1_parms
      				if oParam.name = "Drawing\"&td1_parm_params(i) then
        				cDrwParams.remove(idx)
        				exit for
        			end if
         		next
  		    end if
    	next
  	end if
  	err.clear
'	msgbox "Delete Done"
  	on error goto 0
end sub

sub createTd1Parms()
	' Thanx to Martin Röcker!
  	CATIA.StatusBar = "Creating Parameters"

  	Set DrwDocument = CATIA.ActiveDocument
  	Set DrwSheets   = DrwDocument.Sheets
  	Set DrwParams   = CATIA.ActiveDocument.Parameters

    For blNr = 1 To CATIA.ActiveDocument.Sheets.Count
      	Set DrwSheet = DrwSheets.item(blNr)
		set oBack = IBMGetBackgroundView(DrwSheet.views)

		if blNr > 1 then	'New parameters may be available
           Set DrwParams   = CATIA.ActiveDocument.Parameters
		end if

   	   	for i = 0 to num_td1_parms - 1
       		for each oText in oBack.Texts
       			text_found = false
       			if oText.Name = td1_parm_ids(i) then
       				if oText.Text = "" then
       					oText.Text = " "
       				end if
		      		if blNr = 1 then   					'create Parameter only on sheet 1
 	       				set oParameter = DrwParams.createString(td1_parm_params(i), oText.Text)
        				if td1_parm_visible(i) = "false" then
          					oParameter.hidden = true
        				else
          					oParameter.hidden = false
        				end if
        			else
	  		        	set oParameter = DrwParams.GetItem (td1_parm_params(i))
        			end if
        			if td1_parm_sheet1(i)="false" then
    	    			oText.InsertVariable 0, len(oText.Text)+1, oParameter
    	    		end if
					text_found = true
					exit for

				end if
			next
			if not text_found then
    	    	msgBox "Field >" & td1_parm_ids(i) & "< not found on sheet " & blNr, vbInformation, "Text not on Drawing"
			end if
       	next

	next

  	On Error GoTo 0

end sub

sub createParmsIfNecessary()

	on error resume next
  	Set cDrwParams   = CATIA.ActiveDocument.Parameters
   	for i = 0 to num_td1_parms - 1
   		found = false
   		for each oParameter in cDrwParams
   			if oParameter.Name = "Drawing\"&td1_parm_params(i) then
   				found = true
   				exit for
   			end if
   		next
   		if not found then
			set oParameter = cDrwParams.createString(td1_parm_params(i), " ")
       		if td1_parm_visible(i) = "false" then
       			oParameter.hidden = true
       		else
       			oParameter.hidden = false
       		end if
       	end if
   	next

 	On Error GoTo 0

end sub
