Jump to content

Renaming and deleting record fields


Recommended Posts

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!

Link to comment

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.

Link to comment

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
 

 

  • Like 1
Link to comment

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!

 

 



 

Link to comment
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.

 

Link to comment

@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?
 

Link to comment

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) )

 

Link to comment

@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?

  • Like 1
Link to comment
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.

  • Like 1
Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...