![]() |
Using IDL interfaces, the PPR
Document is available for Automation interfaces to access Manufacturing
Assembly. The automation interfaces to the Manufacturing Assembly are the following: |
|
|
||
Subsequent some excerpts of Visual Basic how to access the Manufacturing Assemblies: | ||
Dim myActivity As Activity myActivity = <get Activity> Dim myItem As Item Set myItem = myActivity.Items.Item(1) Dim obj As MfgAssembly Set obj = mySel.FindObject("DNBIAMfgAssembly")
Dim myName As String myName = obj.MAName
Dim newName As String newName = "NewMAName" obj.MAName = newName
Dim myPart As String myPart = obj.MAPartNumber
Dim newPartNumber As String newPartNumber = "NewPartNumber" obj.MAPartNumber = newPartNumber
Dim MAtype As String If MA.MAType = manufacturingAssembly Then MAtype = "Manufacturing Assembly" Else MAtype = "Manufacturing Kit" End If
Dim Number As Long Number = MA.Count Fetch the assigned parts of the MA Dim j As Long For j = 1 To MA.Count Dim it As Item Set it = MA.Item(j) Dim ItemName As String ItemName = it.Name Next
Dim myProducts As PPRProducts Set myProducts = DELMIA.ActiveDocument.PPRDocument.Products Dim Part As Item Set Part = myProducts.Item(2) MA.AddPart(Part)
Dim myProducts As PPRProducts Set myProducts = DELMIA.ActiveDocument.PPRDocument.Products Dim Part As Item Set Part = myProducts.Item(2) MA.RemovePart(Part) |
||
![]() |
Script Example |
|
Example 1: |
||
This script is an example how to use all Manufacturing Assembly Automation Interfaces | ||
PrerequisiteCreate following PPR items
Create a CATScript: |
||
1. |
Select the Tools > Macro > Macros and create a new CATScript
|
|
2. | Execute following script (Tools > Macro > Macros..>select the new created CATScript> Run) | |
Option Explicit Language = "VBSCRIPT" Sub CATMain() MsgBox "Select an activity" Dim sFilter(0) sFilter(0) = "Activity" Dim This_Sel As Selection Set This_Sel = DELMIA.ActiveDocument.Selection Dim sStatus As String sStatus = This_Sel.SelectElement2(sFilter, "Select an activity", True) Dim Act As Activity Set Act = This_Sel.Item(1).Value display_items Act change_items Act display_items Act End Sub Sub display_items(myActivity As Activity) Dim i As Long Dim mymessg As String mymessg = mymessg & "List of Manufacturing Assemblies" & vbCrLf & vbCrLf For i = 1 To myActivity.Items.Count Dim myItem As Item Set myItem = myActivity.Items.Item(i) Dim mySel As Selection Set mySel = DELMIA.ActiveDocument.Selection mySel.Add myItem On Error Resume Next ' Filter out Products Dim prod As Product Set prod = mySel.FindObject("CATIAProduct") If Err.Number <> 0 Then On Error GoTo 0 Dim MA As MfgAssembly Set MA = mySel.FindObject("DNBIAMfgAssembly") Dim MAName As String MAName = MA.MAName Dim MAPartNbr As String MAPartNbr = MA.MAPartNumber Dim MAtype As String If MA.MAtype = manufacturingAssembly Then MAtype = "Manufacturing Assembly" Else MAtype = "Manufacturing Kit" End If Dim Number As Long Number = MA.Count mymessg = mymessg & MAName & vbCrLf mymessg = mymessg & " Part Number: " & MAPartNbr & vbCrLf mymessg = mymessg & " Type: " & MAtype & vbCrLf mymessg = mymessg & " Number of Parts: " & Number & vbCrLf Dim j As Long For j = 1 To Number Dim it As Item Set it = MA.Item(j) mymessg = mymessg & " Item: " & it.Name & vbCrLf Next mymessg = mymessg & vbCrLf End If Next MsgBox (mymessg) End Sub Sub change_items(myActivity As Activity) Dim i As Long For i = 1 To myActivity.Items.Count Dim myItem As Item Set myItem = myActivity.Items.Item(i) Dim mySel As Selection Set mySel = DELMIA.ActiveDocument.Selection mySel.Add myItem On Error Resume Next ' Filter out Products Dim prod As Product Set prod = mySel.FindObject("CATIAProduct") If Err.Number <> 0 Then On Error GoTo 0 Dim MA As MfgAssembly Set MA = mySel.FindObject("DNBIAMfgAssembly") Dim myProducts As PPRProducts Dim myRes As PPRResources Dim Part As Item If MA.MAtype = manufacturingAssembly Then MA.MAName = "NewMA2" MA.MAPartNumber = "NewMA2Part" Set myProducts = DELMIA.ActiveDocument.PPRDocument.Products Set Part = myProducts.Item(1) MA.RemovePart (Part) Set Part = myProducts.Item(2) MA.AddPart (Part) Else MA.MAName = "NewMK2" MA.MAPartNumber = "NewMK2Part" Set myProducts = DELMIA.ActiveDocument.PPRDocument.Products Set Part = myProducts.Item(2) MA.RemovePart (Part) Set Part = myProducts.Item(1) MA.AddPart (Part) Set myRes = DELMIA.ActiveDocument.PPRDocument.Resources Set Part = myRes.Item(2) MA.RemovePart (Part) Set Part = myRes.Item(1) MA.AddPart (Part) End If End If Next End Sub |
||
First a list of the items will be shown before the changes.
Then the changes are applied and a list box is shown.
|
||
Example 2: |
||
All assigned Products of an Activity are fetched, independently if they are direct assigned, or as assigned parts of a Manufacturing Assembly | ||
Prerequisite |
||
Create following PPR items
|
||
Execute following script (Tools > Macro > Macros..>select the new created CATScript> Run) | ||
Option Explicit Language = "VBSCRIPT" Sub CATMain() MsgBox "Select an activity" Dim sFilter(0) sFilter(0) = "Activity" Dim This_Sel As Selection Set This_Sel = DELMIA.ActiveDocument.Selection Dim sStatus As String sStatus = This_Sel.SelectElement2(sFilter, "Select an activity", True) Dim Act As Activity Set Act = This_Sel.Item(1).Value display_Act Act End Sub Sub display_Act(myActivity As Activity) Dim i As Long Dim mymessg As String mymessg = mymessg & "List of Products of an Activity" & vbCrLf For i = 1 To myActivity.Items.Count Dim myItem As Item Set myItem = myActivity.Items.Item(i) display_Item myItem, mymessg Next MsgBox (mymessg) End Sub Sub display_Item(myItem As Item, mymessg As String) Dim mySel As Selection Set mySel = DELMIA.ActiveDocument.Selection mySel.Add myItem On Error Resume Next ' Filter out Products Dim prod As Product Set prod = mySel.FindObject("CATIAProduct") If Err.Number = 0 Then mymessg = mymessg & prod.Name & vbCrLf Else On Error GoTo 0 Dim MA As MfgAssembly Set MA = mySel.FindObject("DNBIAMfgAssembly") Dim Number As Long Number = MA.Count Dim j As Long For j = 1 To Number Dim it As Item Set it = MA.Item(j) display_Item it, mymessg Next End If End Sub |
||
|
Notes |
|
|