Trying to get coordinate systems with VBA
Hello all,
I try to get the coordinate systems from a model (based on the following tutorial). However my VBA (so not VB!) script is as follows:
Public Function createHoleUDFInPart(ByVal placementModel As IpfcSolid, _
ByVal Name01 As String, _
ByVal csysName As String, _
ByVal Dim1 As Double, _
ByVal Dim2 As Double) _
As IpfcFeatureGroup
Dim csys As IpfcCoordSystem
Dim cSystems As IpfcModelItems
Dim i As Integer
Dim udfInstructions As IpfcUDFCustomCreateInstructions
Dim csysSelection As IpfcSelection
Dim csysReference As IpfcUDFReference
Dim references As CpfcUDFReferences
Dim variantDims As IpfcUDFVariantDimension
Dim variantDims2 As IpfcUDFVariantDimension
Dim variantVals As IpfcUDFVariantValues
Dim group As IpfcFeatureGroup
IpfcCoordSystem = Nothing
' On Error GoTo Try
Set cSystems = placementModel.ListItems(EpfcModelItemType.EpfcITEM_COORD_SYS)
For i = 0 To cSystems.Count - 1
If (cSystems.Item(i).GetName.ToString = csysName) Then
Set csys = cSystems.Item(i)
Exit For
End If
Next
If csys Is Nothing Then
MsgBox ("Coordinate System not found in current Solid")
End If
'======================================================================
'Instructions for UDF creation
'======================================================================
Set udfInstructions = CCpfcUDFCustomCreateInstructions.Create("Name01")
'======================================================================
'Make non variant dimensions blank to disable their display
'======================================================================
udfInstructions.DimDisplayType = EpfcUDFDimensionDisplayType.EpfcUDFDISPLAY_BLANK
'======================================================================
'Initialize the UDF reference and assign it to the instructions.
'The string argument is the reference prompt for the particular
'reference.
'======================================================================
Set csysSelection = CMpfcSelect.CreateModelItemSelection(csys, Nothing)
Set csysReference = CCpfcUDFReference.Create("Reference Coordinate System", csysSelection)
Set references = CpfcUDFReferences.Set(0, csysReference)
udfInstructions.references = references
'======================================================================
'Initialize the variant dimension and assign it to the instructions.
'The string argument is the dimension symbol for the variant dimension.
'======================================================================
Set variantDims = CCpfcUDFVariantDimension.Create("d6", Dim1)
Set variantDims2 = CCpfcUDFVariantDimension.Create("d7", Dim2)
Set variantVals = CpfcUDFVariantValues.Set(0, variantDims)
Set variantVals = CpfcUDFVariantValues.Set(1, variantDims2)
udfInstructions.VariantValues = variantVals
'======================================================================
'We need the placement model for the UDF for the call to
'CreateUDFGroup(). If you were placing the UDF in a model other than
'the owner of the coordinate system, the placement would need to be
'provided separately.
'======================================================================
Set group = placementModel.CreateUDFGroup(udfInstructions)
' createHoleUDFInPart = group
Try:
If Err.Number <> 0 Then
MsgBox "Process Failed : Unknown error occurred." + Chr(13) + _
"Error No: " + CStr(Err.Number) + Chr(13) + _
"Error: " + Err.Description, vbCritical, "Error"
End If
End FunctionPublic Function createHoleUDFInPart(ByVal placementModel As IpfcSolid, _
ByVal Name01 As String, _
ByVal csysName As String, _
ByVal Dim1 As Double, _
ByVal Dim2 As Double) _
As IpfcFeatureGroup
Dim csys As IpfcCoordSystem
Dim cSystems As IpfcModelItems
Dim i As Integer
Dim udfInstructions As IpfcUDFCustomCreateInstructions
Dim csysSelection As IpfcSelection
Dim csysReference As IpfcUDFReference
Dim references As CpfcUDFReferences
Dim variantDims As IpfcUDFVariantDimension
Dim variantDims2 As IpfcUDFVariantDimension
Dim variantVals As IpfcUDFVariantValues
Dim group As IpfcFeatureGroup
IpfcCoordSystem = Nothing
' On Error GoTo Try
Set cSystems = placementModel.ListItems(EpfcModelItemType.EpfcITEM_COORD_SYS)
For i = 0 To cSystems.Count - 1
If (cSystems.Item(i).GetName.ToString = csysName) Then
Set csys = cSystems.Item(i)
Exit For
End If
Next
If csys Is Nothing Then
MsgBox ("Coordinate System not found in current Solid")
End If
'======================================================================
'Instructions for UDF creation
'======================================================================
Set udfInstructions = CCpfcUDFCustomCreateInstructions.Create("Name01")
'======================================================================
'Make non variant dimensions blank to disable their display
'======================================================================
udfInstructions.DimDisplayType = EpfcUDFDimensionDisplayType.EpfcUDFDISPLAY_BLANK
'======================================================================
'Initialize the UDF reference and assign it to the instructions.
'The string argument is the reference prompt for the particular
'reference.
'======================================================================
Set csysSelection = CMpfcSelect.CreateModelItemSelection(csys, Nothing)
Set csysReference = CCpfcUDFReference.Create("Reference Coordinate System", csysSelection)
Set references = CpfcUDFReferences.Set(0, csysReference)
udfInstructions.references = references
'======================================================================
'Initialize the variant dimension and assign it to the instructions.
'The string argument is the dimension symbol for the variant dimension.
'======================================================================
Set variantDims = CCpfcUDFVariantDimension.Create("d6", Dim1)
Set variantDims2 = CCpfcUDFVariantDimension.Create("d7", Dim2)
Set variantVals = CpfcUDFVariantValues.Set(0, variantDims)
Set variantVals = CpfcUDFVariantValues.Set(1, variantDims2)
udfInstructions.VariantValues = variantVals
'======================================================================
'We need the placement model for the UDF for the call to
'CreateUDFGroup(). If you were placing the UDF in a model other than
'the owner of the coordinate system, the placement would need to be
'provided separately.
'======================================================================
Set group = placementModel.CreateUDFGroup(udfInstructions)
' createHoleUDFInPart = group
Try:
If Err.Number <> 0 Then
MsgBox "Process Failed : Unknown error occurred." + Chr(13) + _
"Error No: " + CStr(Err.Number) + Chr(13) + _
"Error: " + Err.Description, vbCritical, "Error"
End If
End Function
However I get stuck at the following line:
Set cSystems = placementModel.ListItems(EpfcModelItemType.EpfcITEM_COORD_SYS)
It gives me a compile error (Method or data member not found), which links to the .ListItems part. I don't seem to be able to solve this.
Any ideas?
Kind regards,
Jeroen

