Skip to content

Instantly share code, notes, and snippets.

@WolfpackWilson
Last active July 9, 2020 18:07
Show Gist options
  • Save WolfpackWilson/9185e787b1dae488575e832f38cf0709 to your computer and use it in GitHub Desktop.
Save WolfpackWilson/9185e787b1dae488575e832f38cf0709 to your computer and use it in GitHub Desktop.
A small script to test extracting information from CATIA via Python [instead of VBA]
import win32com.client
def get_catia():
catia = win32com.client.Dispatch("CATIA.Application")
return catia
def main():
cat = get_catia()
doc = win32com.client.gencache.EnsureDispatch(cat.ActiveDocument)
part = doc.Part
print(part.Name)
bodies = part.Bodies
part_body = bodies.Item(1)
for i in range(1, part_body.Shapes.Count + 1):
print(part_body.Shapes.Item(i).Name)
if __name__ == '__main__':
main()
@WolfpackWilson
Copy link
Author

WolfpackWilson commented Jul 3, 2020

Notes for iterating through CATIA objects:

  • win32com.client.gencache.EnsureDispatch seems to be required for each new library object/interface.
  • Item attributes do not appear under <obj>._pro_map_get_ but under dir(<obj>).
  • There are at least two items that appear to refer to an ancestor in the object tree, Application and Parent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment