sandertb Posted March 20, 2023 Share Posted March 20, 2023 Hi All, I want to update a record that exists across multiple libraries and drawings using a script. However, I noticed that no functions exist for either renaming a record field or deleting a record field. Are there any workaround for this? I do not want to attach a new record and remove the old one is because some symbols have text that is linked to a record, and as far I can tell this link will be removed when removing the old record. Does anybody have a suggestion on how to approach this challenge? Thanks! Quote Link to comment
Pat Stanford Posted March 20, 2023 Share Posted March 20, 2023 I don't think the functionality exists to do what you are trying to do. Actually, I think if you may even have problems doing this manually if you need to rename the field that is used in the Link Text to Record. @JBenghiat @Sam Jones do either of you have experience with editing/replacing record formats? Quote Link to comment
Sam Jones Posted March 20, 2023 Share Posted March 20, 2023 We'll need more specifics as to what you mean by "update" a record. Exactly, how do you want change what field in what record. Are the values (both field name and field value) being changed the same across all libraries? Does the record exist in libraries you do not want to change? Does the record exist outside of the libraries? There is probably a brute force method of collecting field values and field links, and then re-defining the the records and reassigning the links and values. I haven't done this, but tell us the specifics. Quote Link to comment
JBenghiat Posted March 20, 2023 Share Posted March 20, 2023 VS does not have the ability to delete or rename a field. I suspect Sam is correct -- the only solution is brute force: - Rename the old record - Create the new record - Attach the new record to the same objects as the old record - Copy all data from instances of the old record to new - Iterate over all text object in symbols, and re-link to the new record - Delete the old record The following object variables can help you work with linked text: ovTextIsLinkedToRecord = 680; // Boolean, read only - Public for VS ovLinkFormatUsed = 1350; // InternalIndex - the RefNumber of the format this links to ovLinkFieldIndex = 1351; // short - the index of the field of the format used 1 Quote Link to comment
sandertb Posted March 21, 2023 Author Share Posted March 21, 2023 Thanks for the quick responses! To elaborate, the old format consists of 8 fields such as product, brand, weight, power consumption, weight and location. As we have a custom legend tool that can translate symbol names to dutch, we would like to rename the product field to Product [ENG] without removing the values that currently exist, and add a new product [NL] field. Fields such as weight and power consumption are rarely used, and therefore we have decided to remove these fields alltogether. The location field is usually linked to text, and we would like again like to rename this field without removing the text links. I'll try the brute-force solution this week, and I'll keep you guys posted if this works. Regarding iterating over all text objects in symbols, I assume this only goes for symbol definitions right? Quote Iterate over all text object in symbols, and re-link to the new record Many thanks! Quote Link to comment
JBenghiat Posted March 21, 2023 Share Posted March 21, 2023 12 hours ago, sandertb said: Regarding iterating over all text objects in symbols, I assume this only goes for symbol definitions right? Correct. passing vs.FSymDef() to vs.ForEachObjectInList() is probably the best method. I believe you do have to recursively enter symbol folders. Quote Link to comment
sandertb Posted March 23, 2023 Author Share Posted March 23, 2023 @JBenghiatThankyou, I actually approached it with vs.BuildResourceList() and this seems to work too! Right now everything works aside from working with linked text. Currently I have this: for symbol in symbols: obj = vs.FInGroup(symbol) while obj != None: # Try if obj is Text and is linked to record if (vs.GetObjectVariableBoolean(obj, 680)): vs.AlrtDialog(vs.GetObjectVariableBoolean(obj, 680)) vs.AlrtDialog(vs.GetObjectVariableInt(obj, 1350)) vs.AlrtDialog(vs.GetObjectVariableInt(obj, 1351)) obj = vs.NextObj(obj) However, object variables 1350 and 1351 both return '0'. Am I using the variables wrong? Quote Link to comment
Pat Stanford Posted March 23, 2023 Share Posted March 23, 2023 No time to relearn this today but the marvelous @MullinRJ solved this for me back in 2016. Very well commented. HTH Quote Link to comment
sandertb Posted March 24, 2023 Author Share Posted March 24, 2023 Thanks Pat! This is quite a nice workaround, however I dont see yet how this would work in my situation. In our symbols text can be linked to two different fields, and I need to know which field it was linked to before. Am I missing something in the script? Quote Link to comment
JBenghiat Posted March 24, 2023 Share Posted March 24, 2023 Looks like the process is a little more complex. The link information is attached to a link object in the text object's aux list. This is only possible to access using python: kLinkType = 58 ovLinkFormatUsed = 1350 ovLinkFieldIndex = 1351 auxh = hText.aux hTextLink = vs.Handle(0) while hTextLink == vs.Handle(0) and auxh != vs.Handle(0): if auxh.type == kLinkType: hTextLink = auxh auxh = auxh.next if hTextLink != vs.Handle(0): recIdx = vs.GetObjectVariableInt(hTextLink, ovLinkFormatUsed) fieldIdx = vs.GetObjectVariableInt(hTextLink, ovLinkFieldIndex) recName = vs.Index2Name(recIdx) vs.AlrtDialog( 'Field: ' + recName + ' Index: ' + repr(fieldIdx) ) Quote Link to comment
Pat Stanford Posted March 24, 2023 Share Posted March 24, 2023 @JBenghiat Are you sure about the Python only? GetObjectVariableHandle(Hd, 703) returns a handle to the first object in the Aux List. Since in this case you are only reading the Aux List the VS version of your script should work (no time to check it right now to make sure I am not talking trash). I agree that there is no way in VS to create a new object in the Aux List and Python is required for that, but reading and modifying existing items should be possible in VS. Or am I missing something? 1 Quote Link to comment
JBenghiat Posted March 26, 2023 Share Posted March 26, 2023 On 3/24/2023 at 4:14 PM, Pat Stanford said: @JBenghiat Are you sure about the Python only? GetObjectVariableHandle(Hd, 703) returns a handle to the first object in the Aux List. Since in this case you are only reading the Aux List the VS version of your script should work (no time to check it right now to make sure I am not talking trash). I agree that there is no way in VS to create a new object in the Aux List and Python is required for that, but reading and modifying existing items should be possible in VS. Or am I missing something? Indeed, that should work. I think when Python came out, that was the only option, and I haven't looked back. 1 Quote Link to comment
sandertb Posted March 27, 2023 Author Share Posted March 27, 2023 I managed to get it working! Thanks for all the information, you guys are amazing! Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.