Off the top of my head, I think the syntax of this line is wrong:
If (flag = 0) Then proptynew = part.PutPropertyEx("Attachment","some path")
I think it should be somehting like:
If (flag = 0) Then
You may also have to "commit" the part using part.Commit but I am not entirely positive about that.
No, such synrax is correct. We can miss "End IF" since there is only one line after "Then".
The PutPropertyEx method returns an object (IMGCPDBProperty), so you need to use the Set statement:
If (flag = 0) Then Set proptynew = part.PutPropertyEx("Attachment","some path")
Thank you very much. Yes, it does work. I know that "proptynew" is an object, so I defined it earlier as "Set proptynew = Nothing". I was wrong with it.
Oleg - would you mind posting the final script ?
'Note: <reference file with the full path> means that in fact I read this from pre-defined listfile.
'This listfile may have the following syntax:
'<part number1> <reference file1 with the full path>
'<part number2> <reference file2 with the full path>
Set app = GetObject (,"LibraryManager.Application")
Set lib = app.ActiveLibrary
Set fso = CreateObject ("Scripting.FileSystemObject")
Set logfile = fso.CreateTextFile (lib.Path & "\LogFiles\AddAttachment.txt", True)
Set pdbEditor = CreateObject("MGCPCBLibraries.PartsEditorDlg")
Set pdbDB = pdbEditor.OpenDatabaseEx(lib.FullName, False)
pdbEditor.Visible = False
Set PartitionsColl = pdbDB.Partitions
For Each partition In PartitionsColl
Set PartsColl = partition.Parts
For Each part In PartsColl
flag = 0
Set PropertiesColl = part.Properties
For Each propty In PropertiesColl
If (propty.Name = "Attachment") Then flag = 1
If (flag = 0) Then
Set proptynew = part.PutPropertyEx("Attachment", <reference file with the full path>)
logfile.WriteLine (partition.Name & ": " & part.Number & " - Attachment = " & <reference file with the full path>)
MsgBox "Done, see also AddAttachment.txt", 0, ""
Thanks a bunch, olsmir !!!!
For everybody's info, I ran into a problem yesterday that took me a little time to figure out what the problem really was (even though the error message was clear in the MGC BCD CMS shell).
Error:0x80040221 'Property is not defined.'
I had not thought about the fact that the property you are adding, MUST be defined in the Property Definition Editor beforehand.
Once that was overcome, I was able to solve the issue. I will post/upload my example to another thread (Help needed Script fill properties, to be updated later today), since the prerequisite was a little different from the one in this thread.