dctene2
Mechanical
- Oct 22, 2024
- 2
Hello, I've hit a wall writing a macro and am humbly asking for some assistance.
Context:
Problem:
Proposed Solution:
Issue:
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:
Any help or insight would be greatly appreciated. Thank you everyone for your time.
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.
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.