Space Allocation - SpaceRoot - System.__ComObject casting

Mladen Radonić

Space Allocation - SpaceRoot - System.__ComObject casting

Hi, 

I am experiencing runtime (obj casting) problem even with the example code provided within the 3DX CATIA help, here:

 

Sub CATMain()
' 1- Model "Root" is already opened in the active editor
Dim SSMPrdEditor As Editor
Set SSMPrdEditor = CATIA.ActiveEditor

' 2- Retrieves active object
Dim oUIActiveObject As VPMRootOccurrence
Set oUIActiveObject = SSMPrdEditor.ActiveObject
' 3- Retrieves Space Root
Dim oListChildrenOccurrences As VPMOccurrences
Dim objectcount As Long
Set objectOccur = oUIActiveObject
Set oListChildrenOccurrences = objectOccur.Occurrences

Dim SsmSpaceRootObj As SsmSpaceRoot
Dim TempVPMInst As VPMInstance
Dim TempVPMOccur As VPMOccurrence
Dim TempVPMReference As VPMReference

objectcount = oListChildrenOccurrences.Count
For j = 1 To objectcount
Set TempVPMOccur = oListChildrenOccurrences.Item(j)
Set TempVPMInst = TempVPMOccur.InstanceOccurrenceOf
Set TempVPMReference = TempVPMInst.ReferenceInstanceOf

Dim name As String

name = TempVPMReference.GetCustomType

If TempVPMReference.GetCustomType = "SPP_SpaceRoot" Then
Set SsmSpaceRootObj = TempVPMReference
End If
Next

 

The problem is the same within both VBA and VB.NET.

The following line (not this particular example, but similar):

Debug.WriteLine("Type of RootOcc: " + ObjectOccur.ReferenceRootOccurrenceOf.GetCustomType + " - Named: " + ObjectOccur.ReferenceRootOccurrenceOf.Name) 

- produces:

"Type of RootOcc: VPMReference - Named: prd-88118771-00060527"

- but, the following:

Dim oRef As VPMReference
oRef = ObjectOccur.ReferenceRootOccurrenceOf
Debug.WriteLine(oRef.GetType.FullName)

- gives:

"System.__ComObject"

 

Regarding this particular example, the line:

      Debug.Print (name)
after the name has been assigned, gives out:
"SPP_SpaceRoot"    [of course]

- The error output in VS for VB.NET is:
"Exception thrown: 'System.InvalidCastException' in TestCatV6.exe
An unhandled exception of type 'System.InvalidCastException' occurred in TestCatV6.exe
Additional information: Unable to cast COM object of type 'System.__ComObject' to interface type 'SdeTypeLib.SsmSpaceRoot'."...

 

Any ideas, please?

 

regards, 

Mladen

Edited By:
Mladen Radonić[Subscriber Members] @ Apr 14, 2022 - 12:56 PM (Europe/Zagreb)

Mladen Radonić

RE: Space Allocation - SpaceRoot - System.__ComObject casting
(in response to Mladen Radonić)

RESOLUTION FOUND:  you need to have SAO or similar license  (Space Alloc App available) to have it work properly! :)

I didn't have one assigned for the particular 3DX install (having several versions on the machine currently)

Spent a whole day "debugging" this :(

Little Cthulhu

RE: Space Allocation - SpaceRoot - System.__ComObject casting
(in response to Mladen Radonić)

Thanks for sharing the solution.