Loading and Saving a stepfile using python API


In my use case I want to load a step-file of a component and save it using API and assign a new VCID to it.

I am able to successfully load the component but unable to save it using the methods like Save or savestate. Can anyone please help me with this.


vcComponent.save(file_uri) should do it.

Hey Este,

Thankyou very much for the reply.
I already tried saving it using vcComponent.save(file_uri) but I was unable to save it.I get a output stating that the comp is still a none type object.I am attaching the necessary screenshots.

1 Like

The load method fails to return the loaded component for some reason. I came up with a workaround that uses the app.OnComponentAdded event instead.

from vcScript import *

def component_added(component):
  global part2
  part2 = component

def button_pressed(arg):
  app.OnComponentAdded = component_added
  part = app.load(source_file)
  app.OnComponentAdded = None
  if part is not None:
  elif part2 is not None:
    print("Part is None")

app = getApplication()
comp = getComponent()
button = comp.getProperty("Button_1")
button.OnChanged = button_pressed
source_file = "file:///C:/Users/USERNAME/Downloads/test_file.step"
destination_file = "file:///C:/Users/USERNAME/Downloads/test_output.vcmx"

Just replace the USERNAME on those file locations with your own username.


Thankyou very much for the information Este. It worked with the workaround and a new VCID was given by the application.This resolves my issue.Thankyou

1 Like

Hi Este,

First of all,Thanks for your help previously.
A new issue has arised and I am unable to solve it and was hoping that you could help me out.

After saving the file and making sure a new VCID is assigned, I tried to load the component again with the VCID obtained.Unfortunately, I am not able to do so.I am attaching the screenshots for your referral.