×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Utilizing section selections in a macro

## Utilizing section selections in a macro

(OP)
thread560-419902: CATIA VBA select a planar section knowing its BREP name

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 --> VBA

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 --> VBA

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 --> VBA

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?

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

#### Resources

eBook â€“ How to Choose the Correct Corrosion Testing Method
When designing a metal component, engineers have to consider how susceptible certain alloys are to corrosion in the final productâ€™s operating environment. In a recent study by NACE (National Association of Corrosion Engineers), it was estimated that the direct and indirect costs of corrosion in the United States is approximately 6.2% of the GDP. In 2016, that cost exceeded \$1 trillion dollars for the first time. Download Now

Close Box

# Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!