Catia:2D点到3D点

时间:2019-01-10 06:14:15

标签: vba catia

我有一个Catia零件,其中在不同平面上有一些草图。我需要能够将这些草图转换为3D点,然后将其复制到新的零件文档中。 我试图在VB脚本中使用“搜索和选择”命令,以便使用宏拾取草图中的所有2D点并将其转换为3D点,但无济于事。

Sub CATMain()

Set oSel = CATIA.ActiveDocument.Selection

strArray(0)=”Part”

Msgbox “Please select parts to join.”

sStatus = oSel.SelectElement3(strArray, “Select parts”, False, CATMultiSelTriggWhenUserValidatesSelection, false)

iCount = oSel.Count

For i= 1 to iCount

Set myObject2 = oSel.Item(i).value

oSel.Search “Name=Point,sel”

ReDim copies(iCount)

For k=1 to iCount
Set copies(k)=oSel.Item(k).Value
oSel.Add copies(k)
oSel.Copy


Next ‘k
Next ‘i


Set part2 = CATIA.Documents.Add(“CATPart”)

part2.Product.PartNumber = “My New Part”

Dim GSet1 As HybridBody
Set GSet1 = part2.Part.HybridBodies.Item(1)
GSet1.Name = “My Geometry”

Set partDocument2= CATIA.ActiveDocument
Dim ActSel As Selection
Set ActSel=partDocument2.Selection
ActSel.Add GSet1

ActSel.PasteSpecial(“CATPrtResultWithOutLink” )


ActSel.Clear

End Sub

1 个答案:

答案 0 :(得分:0)

您必须分解草图以获取可以复制的内容

反汇编命令在VB中通过HybridShapeFactory.AddNewDatums方法公开。

Option Explicit


Sub CATMain()


Dim oPart As part
Set oPart = CATIA.ActiveDocument.part

Dim oHSF As HybridShapeFactory
Set oHSF = oPart.HybridShapeFactory

Dim sx As Sketch
Set sx = oPart.HybridBodies.item("Geometrical Set.1").HybridSketches.item("Sketch.1")


'make a temporary body
Dim targetGS As HybridBody
Set targetGS = oPart.HybridBodies.add
targetGS.name = "TMP_BODY___DELETE_ME"

'create a datum curve from the sketch
Dim sxRef As Reference
Set sxRef = oPart.CreateReferenceFromObject(sx)

'make a zero-translate from the sketch
'This is required because AddNewDatums functions needs a HybridShape feature
Dim oZero As HybridShapeTranslate
Set oZero = oHSF.AddNewTranslate(sxRef, oHSF.AddNewDirectionByCoord(0#, 0#, 1#), 0#)

Call targetGS.AppendHybridShape(oZero)
Call oPart.UpdateObject(oZero)

'now do the disassembly    
Dim oZeroRef As Reference
Set oZeroRef = oPart.CreateReferenceFromObject(oZero)

'un-datum the curve by making a zero translate

    Dim domains() As Variant
    domains = oHSF.AddNewDatums(oZeroRef)

    Dim i As Integer
    For i = 0 To UBound(domains)
        Call targetGS.AppendHybridShape(domains(i))
    Next

    Call oPart.Update


'now we can copy the resulting points...

    Dim oSel As Selection
    Set oSel = CATIA.ActiveDocument.Selection

    Call oSel.add(targetGS)
    Call oSel.Search("'Generative Shape Design'.Point,sel")


    'copy paste into the new part

  MsgBox ("There are " & oSel.count & " points ready to copy")
    < YOUR COPY PASTE CODE GOES HERE>
    'delete the temporary geo set

    Call oHSF.DeleteObjectForDatum(oPart.CreateReferenceFromObject(targetGS))

End Sub