cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Share your scripts/hacks

TractorGuy
12-Amethyst

Share your scripts/hacks

I have been using my free time to study Python scripting so that I could automate tasks at work and improve efficiency. Several of my scripts have been written to make things eaiser in Pro/E so I figured I would go ahead and share them here:

bender

This script was written because several of my colleagues refuse to use Pro/Piping for hydraulic tubes/hoses. Because of this, we had no way of adding CNC bending data to the drawing without remodeling their parts in Pro/Piping. This script attempts to solve that problem by reading in a Pro/E point file and spitting out a CSV file containing the bend data (feed, bend, twist). It is still a work in progress, but I have posted the source code on GitHub:

https://github.com/HyGear/bender

diff-dwg

This script was written at the request of our purchasing department. They were having problems with understanding what changed between revisions on large/busy drawings. The solution was to write a script that compares the PDFs of the two drawings and outputs a JPEG with deleted items highlighted in red and new items highlighted in blue.

https://github.com/HyGear/diff-dwg

proe-snap

This is sort of a poor man's data management system (I use it when I'm away from the office and don't have access to the data management system). The script will scan your working directory and grab the latest revision of every part/assembly/drawing and place them in a subdirectory with the current time stamp. This allows you to grab snapshots during different phases of a design and also allows you to roll back to a specific point very easily.

https://github.com/HyGear/proe-snap

I would love to hear any feedback that people have on my scripts and I would love to see scripts/hacks from other people that help them get things done!

10 REPLIES 10

Creo supports Python?

Great contributions!

I don't know that it supports Python directly, but you can run Python scripts with the help of a mapkey.

David_M
5-Regular Member
(To:TractorGuy)

It should be possible to connect to Creo's COM API using Python. I am keen to see an example of this if anyone has one.

TractorGuy
12-Amethyst
(To:David_M)

Python supports win32 COM so it should be possible. Here are some examples with Perl which should be very similar to what Python can do:

http://inversionconsulting.blogspot.com/2008/06/proe-vb-api-not-just-for-visual-basic.html

sndong-mefane
5-Regular Member
(To:TractorGuy)

Any real example of Python/VB API script??

I tried myself without success:

import win32com.client as win32

asyncconn = win32.gencache.EnsureDispatch("pfcls.pfcAsyncConnection")

conn = asyncconn.Connect(None,None,None,None)

session = conn.Session

I am using ANACONDA, and I get the following error:

Import Error: No module Named IpfcAsyncConnection...

Creo point relabel

this script will generate a trail file wich when run will rename all labels in offset point table (must be open). I made a executable file for those who do not know anything of python.

Capture.PNG

https://github.com/Osiel-Gaona/creo_point_relabel

 

I've been doing similar work with Python. I export the tree of a part or assembly analyse it and write mapkeys that perform repetitive tasks. Of late we need to access the API in creo so that we can query the models more directly and I'm hoping even manipulate the cad data. From my reading there are Visual Basic API which can run asynchronous. I'm hoping that I can use this in Python.

Have you been able to do this?

I'm not sure if I understand correctly.

what I did is just copy the code of the trail file and figured out what part of the code corresponded to the label and then in python I used the code of the trail file and generate a new trail file with the new data.

 

We need more people like you. 👍

Top Tags