Okay, what it's supposed to do is delete all the current layers in the model unless the user says otherwise, and then add new layers and I'd like to populate the layers with items already in the model, and have it so that all future planes will go into ALL_PLANES, or axes will go in to ALL_AXIS etc.
'created by Chris
'last edited 15 JUL 2010
'The sum of the program is to provide a way to update the layers in Pro/Engineer
Private mLayerCount As Integer
Private mSession As IpfcBaseSession
Private mModel As IpfcModel
Private mMIOwner As IpfcModelItemOwner
Private mSolid As IpfcSolid
Private Sub btnUpdateLayers_click()
Dim Conn As IpfcAsyncConnection
Dim AsynConn As New CCpfcAsyncConnection
lDisplayAlerts = Application.DisplayAlerts
Application.DisplayAlerts = False
'unlock protection on sheet
ActiveSheet.Protect DrawingObjects:=False, Contents:=False, Scenarios:=False
On Error GoTo RunError
'select all cells
Cells.Select
' unlock all the cells
Selection.Locked = False
'connect to Pro/E
Set Conn = AsynConn.Connect("", "", ".", 20)
Set mSession = Conn.session
'retrieve model
Set mModel = session.CurrentModel
Set mSolid = CType(mModel, IpfcSolid)
'=========================================================== ====================
'Clear the Layers column
ActiveSheet.Range("A6:B100").Value = ""
Dim Layers As IpfcModelItems
Dim IndexItem As ipfcmodelitem
Dim ID As Long
Dim Layer As IpfcLayer
Set mMIOwner = mModel
'put all layers in a sequence
Set Layers = mMIOwner.ListItems(EpfcITEM_LAYER)
Sheets("sheet1").Cells(5, 2).Value = Layers.Count
Dim j As Integer
j = 6
'list layers on excel sheet
For ID = 0 To Layers.Count - 1
Set IndexItem = Layers.item(ID)
ActiveSheet.Cells(j, 1).Value = IndexItem.GetName()
ActiveSheet.Cells(j, 1).Select
Selection.Locked = True
j = j + 1
Next
'lock protection on sheet
ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False
'set Public value LayerCount to the number of layers in the model
mLayerCount = j - 1
'prompt user to check layers
MsgBox "Place an 'X' in the column next to the layers you wish to keep." & vbCrLf + _
"Press Continue when done.", vbInformation, "Select Layers to Keep"
'Enable the continue button, and disable the update layers button
Continue.Enabled = True
UpdateLayers.Enabled = False
RunError:
If Err.Number <> 0 Then
MsgBox "Process Failed : Unknown error occured." + Chr(13) + _
"Error No: " + CStr(Err.Number) + Chr(13) + _
"Error: " + Err.Description, vbCritical, "Error"
If Not Conn Is Nothing Then
If Conn.IsRunning Then
Conn.Disconnect (2)
Set Conn = Nothing
Set mSession = Nothing
Set AsynConn = Nothing
End If
End If
End If
'disconnect
Conn.Disconnect (2)
'cleanup
Set AsynConn = Nothing
Set Conn = Nothing
End Sub
'The rest of the code is automated
Private Sub btnContinue_click()
Dim Conn As IpfcAsyncConnection
Dim AsynConn As New CCpfcAsyncConnection
'connect to Pro/E
Set Conn = AsynConn.Connect("", "", ".", 20)
'=========================================================== ===========================================================
'Disable the Continue button
Continue.Enabled = False
'delete layers
Dim D As Integer
Dim Keep As String
Dim Layer As IpfcLayer
Set mMIOwner = mModel
For D = 6 To LayerCount
If Not ActiveSheet.Cells(D, 1).Value = "" Then
Keep = ActiveSheet.Cells(D, 2).Value
If UCase(Keep) <> "X" Then
Set Layer = mMIOwner.GetItemByName(EpfcITEM_LAYER, ActiveSheet.Cells(D, 1))
Layer.Delete
End If
End If
Next
'disable protection of the cells
ActiveSheet.Protect DrawingObjects:=False, Contents:=False, Scenarios:=False
'create new layers
Dim Annotations As IpfcLayer
Dim Axis As IpfcLayer
Dim Cosmetics As IpfcLayer
Dim Csys As IpfcLayer
Dim Curves As IpfcLayer
Dim Planes As IpfcLayer
Dim Points As IpfcLayer
Dim Surfaces As IpfcLayer
Dim Xsec As IpfcLayer
On Error Resume Next
Set Annotations = mModel.CreateLayer("ALL_ANNOTATIONS")
Set Axis = mModel.CreateLayer("ALL_AXIS")
Set Cosmetics = mModel.CreateLayer("ALL_COSMETICS")
Set Csys = mModel.CreateLayer("ALL_CSYS")
Set Curves = mModel.CreateLayer("ALL_CURVES")
Set Planes = mModel.CreateLayer("ALL_PLANES")
Set Points = mModel.CreateLayer("ALL_POINTS")
Set Surfaces = mModel.CreateLayer("ALL_SURFACES")
Set Xsec = mModel.CreateLayer("XSEC_DATUMS")
If Err.Number <> 0 Then
MsgBox "One or more layers already present."
End If
'add items to layers
Dim DatumPlaneList As IpfcFeatures
Dim AddFeature As ipfcmodelitem
Dim Pl As Long
'Put datum plane features into a sequence
Set DatumPlaneList = mSolid.ListFeaturesByType(False, EpfcFEATTYPE_DATUM_PLANE)
'run through each of the items from datumplanelist and add to layer ALL_PLANES (looping them)
For Pl = 0 To DatumPlaneList.Count - 1
Set AddFeature = DatumPlaneList.item(Pl)
'*********problem HERE \/
Planes.AddItem (AddFeature)
Next
UpdateLayers.Enabled = True
'Regenerate the model***
'haven't figured this one out yet either
'put message in pro/e message area to tell user that update layers completed
MsgBox "Update Layers Completed"
'disconnect
Conn.Disconnect (2)
'cleanup
Set AsynConn = Nothing
Set Conn = Nothing
Set mSession = Nothing
End Sub