Iterate Through All Objects In Btw File Follow

0
Avatar
Legacy Poster

Hello,

 

I have a valid BTW file that I would like to inspect for data sources. It does not have any Named Data Sources but 2 Database Fields and 11 Object Values where the first two are Barcode elements. Is there a code snippet or two that will let me iterated though these collections.

 

I used the sample code in the White Paper but since I do not have any Named Data Sources the iteration did not loop over the desired objects. How can I use something similar to the following to inspect the Databases and Objects collections:

 

foreach (Object oObject in btFormat.Objects)

{

MessageBox.Show(" Read it", oObject.ToString());

}

 

Any advice will be truly appreciated on how to iterate the Databases and Objects collections.

 

Thanks!

 

 

 

 

 

 

 

 

3 comments

0
Avatar
Ian Cummings
Moderator
Comment actions Permalink

If you're using the .NET component then your only option is the use of names data sources.  However, if you use COM automation then you can make use of the DesignObject object.

 

'Declare a BarTender application variable 
Dim btApp As BarTender.Application 

'Declare a BarTender document variable 
Dim btFormat As BarTender.Format 

'Declare a BarTender design object variable 
Dim btObject As BarTender.DesignObject 

'Create a new instance of BarTender 
btApp = New BarTender.Application

'Set the BarTender application visible 
btApp.Visible = True

'Open a BarTender document 
btFormat = btApp.Formats.Open("c:\Format1.btw", False, "")

'Set the object variable 
btObject = btFormat.Objects.Item(1)

'Alternatively, use the name of the object if it is known 
'btObject = btFormat.Objects.Item("Barcode 1") 
'Display the name of the object 
MessageBox.Show(btObject.Name)

'End the BarTender process 
btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges) 

0
Avatar
Legacy Poster
Comment actions Permalink

Hello Support Manager,

 

Thanks for your suggestion. I tried it and it WORKED exactly as you illustrated! :D

 

May I indulge in two follow-up questions?

 

1. How can I use the foreach control to iterate through the objects? I was able to use the Count property with a for loop to perform this operation.

2. The first few Objects in my iteration were reported as Box 1. What does this Object represent in the BTW file?

 

Thanks.

 

The Data Sources are:

  • Embedded Data
  • Clock
  • External File
  • Visual Basic Script
  • Database Fields
    • Default.Field 1
  • Named Data Sources
    • <None>
  • Global Data Fields
    • <None>
  • Object Values
    • Barcode 1
    • Text 1
    • ...
    • Text 9
  • Printer Code Template Fields
    • <None>
0
Avatar
Domingo Rodriguez
Moderator
Comment actions Permalink

Could you also attach the BarTender document (.btw) and paste your code for us to examine? For attaching a file, click on "More Reply Options" button when replying in a new post, then follow the "Choose and Attach" multi-step selection for attaching the BarTender document.

Please sign in to leave a comment.