Python API and visual manipulation

How to use the Python API to implement view manipulation functions that show global or focus on selected components?

The effect is equivalent to the first two items of the 3D world toolbar shown in the picture.

Hi,

FillSelected and FillWorld can be accessed in python using netCommand which calls for a .NET action item by its name and executes it. I tested it on 4.2 and FillSelected seems to work but FillWorld doesn’t for some reason. But you can work around that using selection manager. Below you see python functions that should do the trick in 4.2:

#---
def FillSelected():
  netcmd = app.findCommand('netCommand')
  netcmd.execute('FillSelected')
#---
def FillWorld():
  netcmd = app.findCommand('netCommand')
  sel = app.SelectionManager.getSelection(VC_SELECTION_COMPONENT)
  app.SelectionManager.setSelection(app.Components)
  netcmd.execute('FillSelected')
  app.SelectionManager.setSelection(sel)
#---

-k

Thank you very much for solving my problem!

Regarding the function of “fillView”, I solved it by the following methods. :slight_smile:

from vcScript import *

app = getApplication()

# focus on selected components
cmd = app.findCommand('netCommand')
cmd.execute("FillSelected")

# foucus on the whole layout
cmd2 = app.findCommand("fillView")
cmd2.execute()
app.render()

 

Oh, I didn’t know about fillView in python. Thanks for sharing it :slight_smile:

-k