Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Extract Surface from another part in assembly

Status
Not open for further replies.

MShetty

Automotive
Feb 27, 2020
10
I am trying to extract a face from a part in an assembly without doing any changes to the original part. Manually, the workflow will look like this.

1. Activate the part where I want the extract
Step1_e3az9a.png


2. Select Create Datum option
CreateDatum_onu8d7.png


3. Pre-Select the Face I am trying to extract
FaceSelect_ccgvep.png


3. Create Extract

End Result looks like this
End_Result_u0eeq2.png


This way, an isolated extract of a face from Part.1 will be added inside Part.2.
But I am unable to achieve this. I tried to create reference from BREP of the selected face in Part.1 and then create an extract in Part.2, but it fails.
Any idea how I can achieve this via VBA?
 
Replies continue below

Recommended for you

What I have managed to do so far:
Code:
Sub CATMain()

Dim documents1 As Documents
Set documents1 = CATIA.Documents

Set sel = CATIA.ActiveDocument.Selection
Set selFace = sel.Item(1).Value             'Preselect the face

Dim partDocument1 As PartDocument
Set partDocument1 = documents1.Item("1.CATPart")

Dim part1 As Part
Set part1 = partDocument1.Part

Dim bodies1 As Bodies
Set bodies1 = part1.Bodies

Dim body1 As Body
Set body1 = bodies1.Item("PartBody")

Dim shapes1 As Shapes
Set shapes1 = body1.Shapes

Dim assemble1 As Assemble
Set assemble1 = shapes1.Item("Assemble.1")

Dim BREPName As String
BREPName = GetBrep(selFace.name)

Dim partDocument2 As PartDocument
Set partDocument2 = documents1.Item("2.CATPart")

Dim part2 As Part
Set part2 = partDocument2.Part

Dim hybridBodies2 As HybridBodies
Set hybridBodies2 = part2.HybridBodies

Dim reference1 As Reference
Set reference1 = part1.CreateReferenceFromBRepName(BREPName, assemble1)

Dim hybridShapeFactory2 As HybridShapeFactory
Set hybridShapeFactory2 = part2.HybridShapeFactory

Dim hybridShapeExtract2 As HybridShapeExtract
Set hybridShapeExtract2 = hybridShapeFactory2.AddNewExtract(reference1)

hybridShapeExtract2.PropagationType = 3

hybridShapeExtract2.ComplementaryExtract = False

hybridShapeExtract2.IsFederated = False

Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies2.Item(1)

hybridBody1.AppendHybridShape hybridShapeExtract2

part2.Update

Dim reference2 As Reference
Set reference2 = part2.CreateReferenceFromObject(hybridShapeExtract2)

Dim hybridShapeSurfaceExplicit1 As HybridShapeSurfaceExplicit
Set hybridShapeSurfaceExplicit1 = hybridShapeFactory2.AddNewSurfaceDatum(reference2)

hybridShapeFactory2.DeleteObjectForDatum reference2

hybridBody1.AppendHybridShape hybridShapeSurfaceExplicit1

part2.InWorkObject = hybridShapeSurfaceExplicit1

part2.Update


End Sub

Public Function GetBrep(MyBRepName As String) As String
    MyBRepName = Replace(MyBRepName, "Selection_", "")
    MyBRepName = Left(MyBRepName, InStrRev(MyBRepName, "));"))
    MyBRepName = MyBRepName + ");WithPermanentBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR29)"
    GetBrep = MyBRepName
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor