Issue with vcHelpers.VcmFile

Hello everyone,

I tried to start creating a python script and used the snippets and tutorials. But I am always getting an error with the example of the vcHelpers.VcmFile API. I can’t change the metadata of a local component file. For example if I would like to change the description of a vcmx file.

Can someone help? Thank you very much.

from vcCommand import *
from vcScript import *
from vcHelpers.VcmFile import *

def letsprint(prop):
hProp = getProperty(‘Print’)
print (hProp.Value)

app = getApplication()
cmd = getCommand()

#Getting error on line 13 - ReferenceError: Method called without object.
cd = ComponentData(getComponent().Uri[8:])
cd.Description = ‘A high volume feeder’
print cd

The script is working if i remove the lines 13, 14 & 15

hello = cmd.createProperty(VC_STRING, ‘Print’)
prop = cmd.createProperty(VC_BUTTON,“btnPropName”)
prop.OnChanged = letsprint

def state():
executeInActionPanel()

cmd.addState(state)

@jouha can you help?

By the way we are using Delfoi.
I just saw that there are Delfoi scripts concerning vcHelpers. I don’t know how they affect the API.

Hi @DevJB

The issue is that getComponent() doesn’t exist in that context.
vcScript can be imported only in component scripts (PythonScript behaviour) .

Remove vcScript import.
Use the app.SelectionManager to get the selected component in the letsprint event handler and move the lines 13…15 under the same handler (letsprint function).

e.g.
selected_comp = app.SelectionManager.getSelection(VC_SELECTION_COMPONENT)
Note: Can be None

1 Like