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!

Macro To Extract A Surface In Space (& Understanding Selection Object)

dctene2

Mechanical
Oct 22, 2024
2
Hello, I've hit a wall writing a macro and am humbly asking for some assistance.

Context:
I have a CATProduct composed of a single CATPart that represents an assembly of several flat panels. The CATPart contains several Part Bodies that each represent a single panel in the assembly. To describe the assembly, imagine a bookshelf without any backing. So essentially, it is a box frame with panels inside that represent the shelves.​

Problem:
I want to recreate the assembly but with each panel being its own CATPart within the same Product.​

Proposed Solution:
I've created a Seed Model CATPart that represents a single panel. This Seed Model is a Pad whose sketch is a projection of the boundary of an isolated planar surface. The isolated surface is in a Geometrical Set labeled "External References". For the purposes of simplicity, the planar surface is a simple rectangle.

The macro I am writing will insert a "New From" version of the Seed Model into the Product and prompt the user to select a planar surface in space. The intent is to select a face on the original multi-body CATPart that will then be extracted into the Seed Part and replace the isolated surface. As a result, the Pad is then updated to represent one of the panels in space.​

Issue:
Establishing the selected surface as a usable object in the Macro code​

The issue, I believe, is caused by the selected Planar Face being a feature of a CATPart that is not the active part (The Seed Model is the active part in this example). I am not sure how to get this Planar Face feature (i.e. the selected surface) into my new part.

Note that if I select a surface on the active part, it creates the Extract with no issue.

Below is the part of the code where I try to select a planar surface to be extracted into the New From part. It results in an empty Extract in the tree but with an error:

Extract.2 | Invalid, empty or missing input element. One mandatory input element is invalid, empty, or missing. There is no solution for this operation.​

Code:
Sub CATMain()
[indent]Dim oDoc As Document
Set oDoc = CATIA.ActiveDocument

Dim oSelection
Set oSelection = oDoc.Selection

Dim arraySelection(0)
arraySelection(0) = "Planar Face"

dim Status
Status = oSelection.SelectElement2(arraySelection, "Select a Planar Face...", False)

If (InStr(1, Status, "Normal") > 0 Then
[indent]Dim selectedObject
Set selectedObject = oSelection.Item(1).Reference

Dim partDoc1 As PartDocument
Set partDoc1 = oDoc.Application.Documents.Item("Seed_Model.CATPart")

Dim part1 As Part
Set part1 = partDoc1.Part

Dim hsf1 As HybridShapeFactory
Set hsf1 = part1.HybridShapeFactory

Dim hse1 As HybridShapeExtract
Set hse1 = hsf1.AddNewExtract(selectedObject)

hse1.PropagationType = 3
hse1.ComplementaryExtract = False
hse1.IsFederated = False

Dim hbs1 As HybridBodies
Set hbs1 = part1.HybridBodies

Dim hb1 As HybridBody
Set hb1 = hbs1.Item("External References")

hb1.AppendHybridShape hse1

part1.InWorkObject = hse1

part1.Update
[/indent]
End If

oSelection.Clear
[/indent]
End Sub

Any help or insight would be greatly appreciated. Thank you everyone for your time.
 
Replies continue below

Recommended for you

I think you should create the extract in your Assembly CATPart. Then copy-paste the selection into the new part.

regards,
LWolf
 
Solved exactly the same problem couple of months ago. Follow LWolf's advice and create extract in the source part.
 
Solved! I created the extract within the source part, copied it, pasted special "As Result" in the target part, then deleted the extract from the source part. Thank you!
 

Part and Inventory Search

Sponsor