Tuesday, February 11, 2014

Basic Setup: a way to increase productivity

                    
In order to increase productivity, it is not necessary to use the complex capabilities of the program, just by taking advantage of a proper set up and doing the modelling in the right manner there could be huge savings.                                   
                                              
Next will be the default settings:                              
- Millimeters as the default unit for all models.                                  
- Default Datum planes will be named as: Longitudinal, Horizontal and transversal           
- Template will have some basic parameters for creating BOMs in a more automated way                                 
Also this template should have an evaluate feature that will maintain the information of the dimension of the parts.                                  
A basic setup will allow the creation of multi-language BOMs                               
                                              
Part Template  
                               
Create a folder in the windows explorer where all template files will be stored. Then from ProE set this folder as the working directory                  
Create a new part                 
Name it as: template_part_01                      
Uncheck the 'use default template' option               
Click OK                    
Select 'empty' as template and click OK                 
A part file with an empty tree appears                     
Add a datum plane and automatically 3 are created                      
Rename them as: Horizontal, Longitudinal and Transverse                       
Add a coordinate system also, select the 3 planes for origin positioning and select Longitudinal plane as the normal for Z, transverse as the normal for X and Horizontal as the normal plane for Y.              
Change units of the system by selecting: File>Setup>model properties. A dialog box must appear and set as follows:                      
Select Material 'steel' because for our examples we will use normally mild steel 
Select Units and set 'mmKgSeg' in this case units will be millimeters, force in kilograms force and time in seconds           
Close the dialog box  
Now insert a feature for measuring entities. This is a feature that will allow us to measure dimensions for a plate automatically             
Select  Insert>model Datum>evaluate…    
Name the feature as: MDIM 
Create a measure parameter named L (for length)
Select 'Distance' and 'Plane' select the transverse plane and next again select 'Plane' and the transverse plane           
Create another measure parameter named W (for Width), in this case select Longitudinal plane           
Create one another measure parameter named T (for Thickness), in this case select Horizontal plane 
Check the status of the parameters just by selecting 'info' and should appear something similar to the image below.           
Click 'Done'   
Now add a relation for showing the measure parameters in the normal parameters                    
This relation should be added in the relations of part. Select tools>relations and a dialog box should appear     
Next snippet will assign measure parameters to regular parameters:        
/*** EVALUATE FEATURE ""MDIM"" EXTRACT DIMENSION FROM THE MODEL
/***  REORDER TO THE END OF THE FEATURE LIST
/***  REDEFINE AND REDO THE REQUIRE PARAMETERS
/* T=T:FID_MDIM
/* L=L:FID_MDIM
/* W=W:FID_MDIM"
Next one will create a new parameter named 'dimension' for keeping the string that will appear in the BOM    
/***  SET PARAMETER DIMENSION FOR BOM (PART LIST)
/*** PLATE, SHEET, FLAT OR SQUARE BARS, L-PROFILE
IF FLOOR(T)==T
    DIMENSION = ITOS(T)+""X""+ITOS(W)+""X""+ITOS(L)
 ELSE
    DIMENSION=ITOS(FLOOR(T))+"",""+ITOS((T-FLOOR(T))*10)+\
    ""X""+ITOS(W)+""X""+ITOS(L)
 ENDIF"
Next picture shows the dialog box with the code above explained, also you can check the variables    
Click OK        
Some other important variables will be defined as follows:            
ID: is a string that will be the identifier of the part    
DESCRIPTION: a string that have a text that describes the part (i.e. Support, bracket, etc.)     
DESCRIPTION_SP: a string that have a text that describes the part in spanish language          
DESCRIPTION_GE: a string with description in german language           
PREPARED: name of the person responsible for the design        
APPROVED: name of the person reviewing the design     
MASS: is a real number that will have the calculated mass of the part and will be assigned in a relation.          
Next commented relations can be used when necessary. 
/*MP_DENSITY=MASS_AUX/MP_VOLUME("""")
/*MASS=MP_MASS("""")"
Of course more information can be added to the template because this info will be used afterwards for creating BOMS automatically and the idea is this information to be generated automatically just by changing parameters in an upper structure.                
In this case and for our example this information is enough.                     
Save and close

Testing the Part template
                     
For testing our template, let's do next steps:           
Create a new part     
Name it as: testing_part        
Uncheck the 'use default template' option   
Click OK        
Select 'template_part_01' as template and click OK (look for the template in the working directory)     
The new part will 'inherit' all the setup we prepared in the template part.   
Create a protrusion as a box
Drag the MDIM feature and drop after the extrude feature you've just created, click on MDIM feature and right click mouse, next select 'edit definition'    
A redefine dialog box appears at right of the screen           
Be sure the references option is checked and then click on 'Done'           
Then the 'Measure parameters' dialog box appears on the left, select the 'redo' option   
Choose 'L' and redefine it as the distance between the 2 planes of the box in the longitudinal direction 
Choose 'W' and redefine it as the distance between the 2 planes of the box in the transversal direction
Choose 'T' and redefine it as the distance between the 2 planes of the box in the vertical direction       
Click done     
Regenerate the part  
Change the dimensions of the box to: 300mm Length, 220mm Width and 10mm Thickness     
Regenerate the part  
Open the parameters dialog box: tools>parameters and check the values (L,W,T,Dimension) are those you assigned to the extrude feature        
Change dimensions, regenerate and check accordingly in the parameters box.  
Save the part 

Assembly template                           

Create a new assembly                    
Name it as: template_assy_01                     
Uncheck the 'use default template' option               
Click OK                    
Select 'empty' as template and click OK                 
An assembly file with an empty tree appears (you should click settings>tree filters and select features for viewing features in the assembly's model tree)                    
Add a datum plane and automatically 3 are created                      
Rename them as: Horizontal, Longitudinal and Transverse                       
Add a coordinate system also, select the 3 planes for origin positioning and select Longitudinal plane as the normal for Z, transverse as the normal for X and Horizontal as the normal plane for Y.              
Change units of the system by selecting: File>Setup>model properties. A dialog box mut appear and set as follows:                       
Select Units and set 'mmKgSeg' in this case units will be millimeters, force in kilograms force and time in seconds           
Close the dialog box  
Some other important variables will be defined as follows:            
ID: is a string that will be the identifier of the part    
DESCRIPTION: a string that have a text that describes the part (i.e. Support, bracket, etc.)     
DESCRIPTION_SP: a string that have a text that describes the part in spanish language          
DESCRIPTION_GE: a string with description in german language           
PREPARED: name of the person responsible for the design        
APPROVED: name of the person reviewing the design     
MASS: is a real number that will have the calculated mass of the part and will be assigned in a relation.          
Next commented relations can be used when necessary. 
/*MASS=MP_MASS("")
Of course more information can be added to the template because this info will be used afterwards for creating BOMS automatically and the idea is this information to be generated automatically just by changing parameters in an upper structure.                
In this case and for our example this information is enough.                     
Save and close      

Testing the Assembly template
               
For testing our template, let's do next steps:           
Create a new assembly        
Name it as: testing_assy       
Uncheck the 'use default template' option   
Click OK        
Select 'template_assy_01' as template and click OK (look for the template in the working directory)    
The new part will 'inherit' all the setup we prepared in the template part.   
Save the part 

These templates defined here are very simple but you can create more complex ones. For example if you usually create paralelepipeds, a protrusion can be included in the template part or assembly, with the preferred material and units already setup.  

Thanks.              

Monday, February 10, 2014

Controlling a Box in CREO from MSExcel by using the VB API

Once the setup up part was finished, we are ready to test this API. In this simple example we are to use the capabilities for parameters the API has. In other exercise we will show something more sophisticated but based fundamentally in the very same ability of CREO for controlling a model via parameters.

The Box

Let's make in CREO a part with the name "box.prt", in it create a solid box with 3 dimensions (Length, Depth and Height).






Then Create 3 parameters for the 3 dimensions above mentioned. Let's name the variables as: LENGTH, DEPTH and HEIGHT





Now, in the "relations" dialog box, relate each parameter with the dimensions in the box





So we are ready from the side of CREO.

The Excel Side

Now on the side of Excel, let's create a new spreadsheet. and format it as is shown in next picture



Let's take advantage of the validation capabilities of Excel for restricting user inputs and avoid incorrect data to be passed to CREO API. So make the 3 dimensions to be more than 10 units and less than 800 units (let's say mm or inches). Also of course The values should be numeric. Next Image shows how it should look like when trying to enter a vale lower than 10 for HEIGHT Parameter.



Add a Button for connecting to CREO,



and insert the next snippet of code in the on-click event(This code allows for you to update the LENGTH from excel, DEPTH and HEIGHT are not updated as you can see in the code lines):

Private Sub UpdateCreo_Click()

Dim asyncConnection As IpfcAsyncConnection
Dim cAC As CCpfcAsyncConnection
Dim session As IpfcBaseSession
Dim model1 As IpfcModel
Dim px As IpfcParameterOwner
Dim p01, p02 As String
Dim p1 As IpfcParameter
Dim p2 As IpfcBaseParameter
Dim Mitem As CMpfcModelItem
Dim pv1 As IpfcParamValue

p01 = "LENGTH"
Range("D5").Select
p02 = ActiveCell.Text

Set cAC = New CCpfcAsyncConnection
Set asyncConnection = cAC.Connect(dbnull, dbnull, dbnull, dbnull)
Set session = asyncConnection.session
Set model1 = session.GetModel("BOX.PRT", EpfcMDL_PART)
Set px = model1
Set p1 = px.GetParam(p01)
Set p2 = p1
Set Mitem = New CMpfcModelItem
Set pv1 = Mitem.CreateDoubleParamValue(CDbl(p02))
p2.Value = pv1

asyncConnection.Disconnect (1)

End Sub


Test the button and this will allow you to update the box's LENGTH from Excel by using the VB API for PTC's CREO.

Thanks.



Thursday, February 6, 2014

Visual Basic API for PTC's CREO - Setup

In order to use this API (Application Programming Interface) it is necessary first to install this capability and do the proper setup in both Windows and the programming tool. MS Visual Studio can be used for programming and accessing the COM object but also Excel or other COM enabled tool.


Installing VB API


When Installing CREO Parametric be sure you select the VB API as is shown in the next picture:



If all installation process is done successfully then in the installation folder of CREO you´ll find a folder named "[Creo Path]\Common Files\M010\vbapi" [Creo Path] is the path you selected for installing CREO.



Is in this folder where most files related to VB API are located. There are many files inside but one that will be very useful with this API is the "vbug.pdf".


This document is very important and shows most of the contents for this API. Most of the procedures we are to see now are documented there but ours is a practical experiment you can follow.

Connecting MSExcel with CREO via VBAPI

In order to connect any application with CREO Parametric by means of this API, it is necessary to:

1- Set the PRO_COMM_MSG_EXE enviroment variable to the full path of the executable file pro_comm_msg.exe. which is located in:
 <creo_loadpoint>\Common Files\<datecode>\<machine type>\obj\pro_comm_msg.exe, where machine type is i486_nt for 32-bit Windows and x86e_win64 for 64-bit Windows installations.

For doing this, look in MSWindows for the Control Panel, then select System, then Advanced tab, then Environment variables an Add a new one PRO_COMM_MSG_EXE With the path explained before as the contents of the Value text box.

2- Register the COM Server. For doing this just run the "vb_api_register.bat" file located at <creo_loadpoint>/Parametric/bin.

Now each time an application tries to call Creo with the commands of this API, the server will automatically start.

3- Now on the side of the Excel Application, set project references for the VB API, Just select Tools and then References and Check the box for Creo Parametric VB API Type Library for Creo Parametric as shown in the following figure.


4- For Visual Basic .NET Environment, Click Project Properties Add Reference COM. and then, select Creo Parametric VB API Type Library for Creo Parametric as shown in the following figure.



More information on this can be found in the vbug.pdf or in the interactive help whose use is also shown in the vbug.pdf manual.

With this done we are ready for creating our first application.