Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Extracting Surfaces from a Search

Status
Not open for further replies.

jzecha

Aerospace
Jan 20, 2016
236
I am running into a an error I have never seen before.

I want to search a product for visible faces, extract those faces, and join them all together.

The code fails on the oPart.Update, saying "Update Failed"

When I look at what was created in the model, it creates all the Extracts, but they need updated.

When I go to edit one of the extracts, it pops up with an Error stating:
Update Failed
An error occurred in GenericNaming treatment, the selected element may be not piecewise connected.
Please select another one.

Can someone please help me figure out the correct way to code this?

Code:
            Dim AssyFaceSelection As Selection
            Set AssyFaceSelection = oTopProductDocument.Selection

            AssyFaceSelection.Search "(Topology.CGMFace & Visibility=Shown),all"
            Debug.Print AssyFaceSelection.Count

            Dim oInitialJoin As HybridShapeAssemble
                      
            Dim FaceCount As Integer
            FaceCount = AssyFaceSelection.Count
            
            Set oInitialJoin = oHybridShapeFactory.AddNewJoin(Nothing, Nothing)
            oInitialJoin.SetConnex (False)

            For X = 1 To FaceCount
            
            Set oSelectedBodyRef = AssyFaceSelection.Item(X).Value
            
                Set oSurfExtract = oHybridShapeFactory.AddNewExtract(oSelectedBodyRef)
                    oSurfExtract.PropagationType = 3
                    oSurfExtract.ComplementaryExtract = False
                    oSurfExtract.IsFederated = False
                    oSurfExtract.Name = "Part Surface " & X
                    oHybridBody.AppendHybridShape oSurfExtract

            
                    oInitialJoin.AddElement oSurfExtract
            
            Next

            oHybridBody.AppendHybridShape oInitialJoin
            
            oPart.Update
 
Replies continue below

Recommended for you

Perform the operation manually, this will bring up a dialog with description of the error.
 
When I do this manually, I do not have a problem.

I perform the search, select all of the results.
Then click extract, the 27 results automatically populate into the "Elements to extract field" and I can hit "OK" and it works as expected.
 
Recheck if extract options that you check in code match those set with UI command.

Have you declared oSelectedBodyRef as Reference?
 
I checked and even recorded my approach and the extract settings are correct.
Also verified I declared it as Reference.

My best guess is that it has something to do with when I record it, it uses CreateReferenceFromBRepName.

The recorded section of the code I do not know how to interpret is:


Code:
Dim hybridShapeSurfaceExplicit1 As HybridShapeSurfaceExplicit
Set hybridShapeSurfaceExplicit1 = hybridShapes1.Item("Surface.7")

Dim reference1 As Reference
Set reference1 = part1.CreateReferenceFromBRepName("RSur:(Face:(Brp:(GSMBiDim.7;%2);None:();Cf11:());WithPermanentBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)", hybridShapeSurfaceExplicit1)
 
Maybe I am not understanding exactly what you are explaining.

I can Run this on a simple product Called "BoundingBox_Test_Product" that has a few random angles and plates in it.
It also has a part called "BoundingBox" that this code is trying to build the Extracts into.

This macro fails on the oPart.Update at the end.
It creates all the extracts, but they need to be updated.
When I go to click on one, it has the same error as before.

"Update Failed
An error occurred in GenericNaming treatment, the selected element may be not piecewise connected.
Please select another one."

Here is the full simplified code I can run.

I really appreciate the help, Please let me know what I am doing wrong

Code:
Sub CatMain()

    Dim oDocuments As Documents
    Set oDocuments = CATIA.Documents

    Dim oTopProductDocument As ProductDocument
    Set oTopProductDocument = oDocuments.Item("BoundingBox_Test_Product.CATProduct")
    
    Dim oProduct As Product
    Set oProduct = oTopProductDocument.Product
    
    Dim oPartDocument As PartDocument
    Set oPartDocument = oDocuments.Item("BoundingBox.CATPart")
    
    Dim oPart As Part
    Set oPart = oPartDocument.Part
    
    Dim oHybridBodies As HybridBodies
    Set oHybridBodies = oPart.HybridBodies

    Dim oHybridBody As HybridBody
    
    Set oHybridBody = oHybridBodies.Item("Bounding_Box_Product")
    
    oPart.InWorkObject = oHybridBody
    
    Dim oHybridShapeFactory As HybridShapeFactory
    Set oHybridShapeFactory = oPart.HybridShapeFactory

            Dim AssyFaceSelection As Selection
            Set AssyFaceSelection = oTopProductDocument.Selection
            'Set AssyFaceSelection = oPartDocument.Selection

            AssyFaceSelection.Search "(Topology.CGMFace & Visibility=Shown),all"                      
                      
            Dim hybridBody1 As HybridBody
            Set hybridBody1 = oHybridBodies.Item("External References")

            Dim hybridShapes1 As HybridShapes
            Set hybridShapes1 = hybridBody1.HybridShapes
                    
            Dim oFaceExtract As HybridShapeExtract
                      
            Dim FaceCount As Integer
            FaceCount = AssyFaceSelection.Count
            
            For X = 1 To FaceCount                                
                                
                                Dim oSurfExtractRef As Reference
                                Set oSurfExtractRef = AssyFaceSelection.Item(X).Value

                                Set oSurfExtract = oHybridShapeFactory.AddNewExtract(oSurfExtractRef)
                                oSurfExtract.PropagationType = 3
                                oSurfExtract.ComplementaryExtract = False
                                oSurfExtract.IsFederated = False
                                oSurfExtract.Name = "Part Surface " & X
                                oHybridBody.AppendHybridShape oSurfExtract
            
            Next            
            oPart.Update
ErrorHandler:

End Sub
 
Are gou saying that the resulting join and original faces are located in different CATParts? If so, you can't reference geometry from another document with VBA.

I suggest creating extract and join features in original part and then copying join to target part as result with Selection.PasteSpecial
 
That explains it, it wont work because they are in different parts.

For what I am doing, I will just have to figure out a different way, I do not want to create extracts in every part.

Thanks for the insight, I had no idea you couldn't do that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor