thread560-419902
Following on from the previous thread, I noticed it ended with the author not knowing why they could not utilize the sections they added to the collection.
I wrote a macro which manipulates sections in a selection (which I have merged below with the code from the previous thread), and I found that (for some reason) the sections referenced by "oSelection.Item(i).Value" aren't really of the section type. I don't know what it is (maybe a reference), but I know I had to assign the contents of the selection to a variant-type variable,
,then utilize the name property and search iteratively through all the sections for that name.
This worked for me... but for some reason a few weeks after I wrote the code, CATIA now baulks at assigning the selection to a variant-type variable, i.e.
I cannot for the life of me figure out what happened. The error I get is 91: "Object variable or With block variable not set".
Looking up this error code, it suggests that either:
1. I attempted to use an object variable that isn't yet referencing a valid object.
2. I attempted to use an object variable that has been set to Nothing.
3. The object is a valid object, but it wasn't set because the object library in which it is described hasn't been selected in the References dialog box.
4. The target of a GoTo statement is inside a With block.
5. I specified a line inside a With block when I chose the Set Next Statement command.
It isn't 4. or 5. I don't think it is 3. as none of the References have changed (or at least all the obvious "CATIA V%..." are selected). It would seem that the ability to reference a section as a selection has been taken away, perhaps through a new revision rolled out unannounced.
Any ideas?
Following on from the previous thread, I noticed it ended with the author not knowing why they could not utilize the sections they added to the collection.
I wrote a macro which manipulates sections in a selection (which I have merged below with the code from the previous thread), and I found that (for some reason) the sections referenced by "oSelection.Item(i).Value" aren't really of the section type. I don't know what it is (maybe a reference), but I know I had to assign the contents of the selection to a variant-type variable,
Code:
Dim brepresentation as Variant
Set brepresentation = oSelection.Item(i).Value
,then utilize the name property and search iteratively through all the sections for that name.
Code:
Dim intSelCount as Integer
intSelCount = oSelection.Count
Dim brepresentation as Variant
Dim oDocument as Document
Dim scsDocument as Sections
Dim intSecCount as Integer
Dim secSelection as Variant
Set oDocument = CATIA.ActiveDocument
Set scsDocument = oDocument.Product.GetTechnologicalObject("Sections")
intSecCount = scsDocument.Count
For i = 1 To intSelCount
Set brepresentation = oSelection.Item(i).Value
For j = 1 To intSecCount
If scsDocument.Item(j).Name = brepresentation.Name Then
Set secSelection = scsDocument.Item(j)
End If
Next j
'' Utilise secSelection.
Next i
This worked for me... but for some reason a few weeks after I wrote the code, CATIA now baulks at assigning the selection to a variant-type variable, i.e.
Code:
Dim brepresentation as Variant
Set brepresentation = oSelection.Item(i).Value
I cannot for the life of me figure out what happened. The error I get is 91: "Object variable or With block variable not set".
Looking up this error code, it suggests that either:
1. I attempted to use an object variable that isn't yet referencing a valid object.
2. I attempted to use an object variable that has been set to Nothing.
3. The object is a valid object, but it wasn't set because the object library in which it is described hasn't been selected in the References dialog box.
4. The target of a GoTo statement is inside a With block.
5. I specified a line inside a With block when I chose the Set Next Statement command.
It isn't 4. or 5. I don't think it is 3. as none of the References have changed (or at least all the obvious "CATIA V%..." are selected). It would seem that the ability to reference a section as a selection has been taken away, perhaps through a new revision rolled out unannounced.
Any ideas?