|
|
|
|
|
This tool was borne out of need for faster development of Pro/TOOLKIT functions. I wanted to have a type of test harness environment for my initial algorithmic ideas, but without having to go through a long process of seeing these ideas materialize. Those of you who worked with ACIS kernel will certainly know what I am getting at. The developers of ACIS created a nice test harness environment based on the scheme programming language (a dialect of LISP), where users could try their ideas and quickly get a sense whether their algorithms made any sense. Major advantages were; no compilation involved, quick and easy usage of functions, development of scripts (programs) that vendors can embed in their own software (which is what the developers of AutoCAD with a creation of Auto Lisp). My idea was to do something similar for Pro/TOOLKIT. Although, the scheme is a wonderful efficient small programming language, a descendent of LISP, its syntax and a lack of support forced me to choose something else. After a closer look at available options, I decided to embed the Python interpreter as my main engine. Python has a very strong support for a number of concepts important in rapid development of applications. Python (an open source project) is a vision of one man who nowadays gets help from a large number of volunteers. This revolution in development of modern programming languages is similar to that of Linux in operating systems area. Equipped with such a strong tool, I created a GUI around Pro/TOOLKIT functions that lets you call toolkit functions and create run time scripts. This is a development environment tailored specifically for working with Pro/TOOLKIT libraries. For those who are not proficient with writing programs yet, toolkit functions can be accessed through pop up windows. At this stage the most important toolkit functions (that I used in the past 5 years are wrapped and callable), but the goal is to expand it as much as possible when time permits. Besides wrapped toolkit calls, the system also contains some code from computational geometry that I needed for my research. Also there is a number of C functions developed which are also wrapped and which expand Pro/TOOLKIT's functionality. For example how often did you wish that Pro/TOOLKIT had an easy function to extract the assembly tree from the model? Overall, my aim is to expand the system further and develop a truly useful computational geometry tool based on Pro/TOOLKIT. The system was designed for my own use, but the goal is to offer it to the general public and make it more accessible to newcomers. On this page, when time permits, I will post some code fragments that demonstrate the usefulness of RTOOLKIT. For a quick look, shown bellow is a screen shot of the main panel where you can notice the Pro/E tree of an assembly example and the main scripting area where one enters the Python code. The area at the bottom shows available objects in the system.
Here are some short code fragments for you to get an idea how the system works. The examples bellow are for the model loaded in Pro/E in the above picture. After you opened the above assembly in RTOOLKIT, you may wish to get all of the components yourself even you see them in the assembly tree in RTOOLKIT. Here is how to do it. >>> cmps=ptk.asmcmps(handle) >>> cmps [181405112, 181405112, 181477928, 181722536, 181754488, 181926056] >>> for i in cmps: ... print ptk.mdlnmget(i) ... FRAME FRAME MOTOR MOTOR_PLATE REDUCER PUMP ptk.asmcmps() above finds out all of the components in the top assembly. With returned handles then, for example, you can inspect the names of the components with ptk.mdlnmget(). Now, the assembly may have some more elements in it, so why not try to get them all? No problem, with the easy Python language we'll just make a recursive call and go through all of the components. Define a function foo() like this and use it ... >>> def foo(complst): ... for i in complst: ... if 'PRT'==ptk.mdltypeget(i): ... print ptk.mdlnmget(i),'PRT' ... else: ... print ptk.mdlnmget(i),'ASM' ... foo(ptk.asmcmps(i)) ... >>> foo(cmps) FRAME PRT FRAME PRT MOTOR PRT MOTOR_PLATE PRT REDUCER ASM REDUCER_SKEL PRT PUMP ASM PUMP PRT But even that may be too slow! Why not just use the built in function in RTOOLKIT to get all of the components and their types at the same time, as well as their parents? >>> tree= ptk.treeget(handle) >>> tree [['PUMP_CHASSIS', 'ASM', [-1], 'ROOT'], ['FRAME', 'PRT', [13], 'PUMP_CHASSIS'], ['FRAME', 'PRT', [16], 'PUMP_CHASSIS'], ['MOTOR', 'PRT', [17], 'PUMP_CHASSIS'], ['MOTOR_PLATE', 'PRT', [20], 'PUMP_CHASSIS'], ['REDUCER', 'ASM', [66], 'PUMP_CHASSIS'], ['REDUCER_SKEL', 'PRT', [66, 38], 'REDUCER'], ['PUMP', 'ASM', [67], 'PUMP_CHASSIS'], ['PUMP', 'PRT', [67, 31], 'PUMP']] The output of ptk.treeget() is a list of lists collected with a C API call. No need to remind that this functionality doesn't exist in Pro/TOOLKIT. In just a few lines of code you found out all of the components in the assembly! Since you have their handles now you can go and search for other things. So let's look at some things like feature ids, but first ... >>> motor=cmps[2] >>> motor 181477928 >>> ptk.mdlnmget(motor) 'MOTOR' The third member of the cmps list (Python lists start with 0 index) is motor, so just check the name of the object to make sure ..., and now you can get all of the feature ids ... >>> fts=ptk.featids(motor) >>> fts [3, 1, 6, 8, 17, 106, 125, 162, 225, 373, 246, 374, 268, 269, 270] Why not get some info about dimension ids? Let's pick a feature id from the list, get the dimension ids and their values. >>> fts=ptk.featids(motor) >>> fts [3, 1, 6, 8, 17, 106, 125, 162, 225, 373, 246, 374, 268, 269, 270] Let's pick a feature from this list, say 268 and get all of the dimension ids. >>> dms=ptk.dimids(motor,268) >>> dms [28, 29, 30, 31, 32, 33, 34, 27] How about the values for these dimensions? >>> for i in dms: ... print ptk.dimval(motor,i) ... 13.0 9.0 0.25 1.0 120.0 7.0 1.5 4.75 Maybe you are wondering about loading more models into Pro/E and having them being accessed through Pro/RTOOLKIT. No problem, since RTOOLKIT is a multiple document environment, you just open another project and select the model you want to load. A new project panel comes up with a tree on the side. In this case I loaded the Motor part from the assembly (see bellow). Since this is a part, the tree displays all the features in the model (what you would expect in Pro/E anyway). Notice a highlighted feature in the tree "PROTRUSION" (id 17). Once you click on that item the system sends the event info to the shell for processing and you'll get the line 6 which gets you all of the children of that feature. Type chldrn and you'll get to see what the ids of the children are. Switching from the assembly panel to the part panel is seamless. The system keeps track of the focus and references so that you can interrogate the model of interest whenever you wish.
How about finding some engineering numbers for the motor in this assembly? >>> ptk.mpropget(handle,"")
{'dens': 1.0, 'princmom': [38298.444997824918, 74851.859844112609, 75930.610306907009],'mass': 2078.2171683315396, 'princaxes': [[0.99999988388596006, -0.00048190046549825258, 0.0],[0.00048190046308270527, 0.99999988356173153, -2.5465018488632267e-005], [0.0, 2.5464972776730142e-005, 0.99999999967576247]], 'area': 1012.0140121420926, 'vol': 2078.2171683315396, 'csysin': [[56250.433123747665, -2.84555087688409, 0.0], [-2.84555087688409, 19738.27245124157, 0.0], [0.0, 0.0, 18609.847268215177]], 'cginten': [[38298.453486553772, -17.615105493881753, 0.0], [-17.615105493881753, 74851.851356083673, 0.0], [0.0, 0.0, 75930.610306207091]], 'csysinten': [[38348.11971945675, 2.84555087688409, 0.0], [2.84555087688409, 74860.28039196285, 0.0], [0.0, 0.0, 75988.705574989232]], 'cofg': [0.063685928820107041, -0.15459133451558738, 0.0]} Again, no compilation involved, but a simple command that extracts all of the information needed. Here is the outline of the motor. >>> ptk.outlget(handle)
{'pt2': [14.125, 6.0, 6.5], 'pt1': [-9.5, -7.0, -6.5]}
How about finding a shortest distance between bounding boxes that enclose several features. The functionally usually needed by those working on machining applications. >>> ptk.f2fdist(handle,[246],[225]) 10.499999999999998 In this example I chose only one feature to be enclosed in the bounding box, but by providing several feature ids you can easily bound more and find the distance between the boxes. Note in the picture bellow that the command also draws the bounding boxes around features (in this example 2 holes) as well as the line that represents the shortest distance between them. Also is it is important to mention that this command contains a serious computational geometry algorithm as well as effort to program it. Again as a reminder, this functionality doesn't exist in Pro/TOOLKIT.
Or how about finding a bounding box of the motor in the assembly? Here is how to do it >>> ptk.bboxinassy(handle,[17]) [[-0.5, 0.25, -6.5], [23.125, 0.25, -6.5], [23.125, 0.25, 6.5], [-0.5, 0.25, 6.5], [-0.5, 13.25, -6.5], [23.125, 13.25, -6.5], [23.125, 13.25, 6.5], [-0.5, 13.25, 6.5]] The above are the coordinates of the bounding box. The command also draws the box (see bellow).
As you can see this frees you from low level programming tasks in C and that tedious loop; program, compile and execute. These are just short examples in the sea of endless possibilities.
|
||
|
|
|
|
|
Copyright @20XX Vin Yovanovich, All rights reserved. |
||