Search code examples
vbamacroscatia

VBA macros for CATIA works on one computer, and doesn't work on another


I have a CATIA macro in VBA, that draws points by coordinates (from arrays). It works on my computer (Catia V5-R2014 and on my neigbours - two versions V5-R2014 and R21). But it doesn't work for colleges in a different city (they have version R21). Basically, my macro reads input data from file, calculates coordinates, writes them in out-file, and then draws these points. All steps except the last one work on either computer/version. But at the last step "their" Catia just doesn't plot anything, w/o any errors.

So the Subruotine for the last step is:

Sub PlotGeometry()
' Nmlp - number of points
Dim i As Integer

Dim oPartDocument As Document
Dim ohSPointCoord() As HybridShapePointCoord
Dim ohSPoints As HybridShapePointCoord
Dim bodies1 As Bodies
Dim body1 As Body

ReDim ohSPointCoord(0 To Nmlp)

Set oPartDocument = CATIA.Documents.Add("Part")
Set oPart = oPartDocument.Part
Set oPartBody = oPart.MainBody
Set oPlaneYZ = oPart.CreateReferenceFromGeometry(oPart.OriginElements.PlaneYZ)
' -- Draw Points
Dim ohSFactory As HybridShapeFactory
Set ohSFactory = oPart.HybridShapeFactory

For i = 0 To Nmlp
    Set ohSPointCoord(i) = ohSFactory.AddNewPointCoord(XM(i), YM(i), ZM(i))
    oPartBody.InsertHybridShape ohSPointCoord(i)
Next i

oPart.Update

End Sub

What can it be?


Solution

  • Perhaps at your site you have Hybrid Design enabled, and at the other site they do not.

    With Hybrid Design enabled, you would be able to add points to a Body. Not so if it is not enabled and you would get no error from your code.

    The setting is under Tools->Options->Infrastructure->Part Infrastructure->Part Document Tab->Enable hybrid design inside part bodies and bodies.

    For unexplained reasons, hybrid design being enabled is the default. However I do not recommend using it.

    If you just want to make your code work in both places then use a Geometrical Set to aggregate your points instead of the main body.

    Dim pointsBody as HybridBody
    Set pointsBody = oPart.HybridBodies.Add
    pointsBody.Name = "Points_Body"
    
    ...
    
    For i = 0 To Nmlp
        Set ohSPointCoord(i) = ohSFactory.AddNewPointCoord(XM(i), YM(i), ZM(i))
        pointsBody.AppendHybridShape ohSPointCoord(i)
    Next i