2016-10-18 21 views
0

VB.NETを使用して円を作成しようとしています。しかし、以下のコードを実行すると、このエラーが発生します。「保護されたメモリを読み書きしようとしましたが、これは他のメモリが壊れていることを示していることがよくあります。私がサークルを描こうとするとき。誰が何が起こっているのか考えていますか?VB.NETのCATIA自動化

Dim inCircle As HybridShapeCircleTritangent 

Dim testHB As MECMOD.HybridBody 

testHB = part1.FindObjectByName("Test HB") 


inCircle = hsf.AddNewCircleTritangent(part1.FindObjectByName("Line.1"), part1.FindObjectByName("Line.2"), part1.FindObjectByName("Line.3"), part1.FindObjectByName("Surf"), -1, 1, -1) 
inCircle.DiscriminationIndex = 1 
inCircle.BeginOfCircle = 1 
inCircle.TangentOrientation1 = -1 
inCircle.TangentOrientation2 = 1 
inCircle.TangentOrientation3 = -1 

inCircle.SetLimitation(1) 
testHB.AppendHybridShape(inCircle) 

答えて

0

円の入力項目の参照を作成しようとしましたか?

Dim reference2 As Reference 
Set reference2 = part1.CreateReferenceFromObject(part1.FindObjectByName("Line.1")) 

をそして

0

@Matheus Titarelliは、線や面への参照を必要とする程度正しい作成した参照を使用します。 これを試してみてください。 CreateReferenceFromObjectでFindObjectByNameを直接呼び出すのではなく、見つかった行(存在する場合)としてローカル変数を設定してから、参照を作成します。

@A。 Gharbi私はC#でCatiaの開発をすべて行っていますので、悲しいことに私はVB.netのコードをあなたと共有できるコードを持っていませんが、私が使用するC#のバージョンはあります。私はVB.netコードの大まかな翻訳を行いましたが、それをテストしていません。

VB.netコード(未テスト):

'-------------------------------------------------------------- 
Public Shared Function GetHybridShapeFactory(iPart As MECMOD.Part) As HybridShapeTypeLib.HybridShapeFactory 
    If iPart Is Nothing Then 
     Return Nothing 
    End If 

    Dim oHSF As HybridShapeTypeLib.HybridShapeFactory = Nothing 
    Try 
     oHSF = DirectCast(iPart.HybridShapeFactory, HybridShapeTypeLib.HybridShapeFactory) 
    Catch ex As Exception 
     Return Nothing 
    End Try 
    Return oHSF 
End Function 


'-------------------------------------------------------------- 
Public Shared Function AddNewCircleTritangent(ByRef iPart As MECMOD.Part, 
               ByRef iHB As MECMOD.HybridBody, 
               ByRef iLine1 As INFITF.AnyObject, 
               ByRef iLine2 As INFITF.AnyObject, 
               ByRef iLine3 As INFITF.AnyObject, 
               ByRef iSurface As INFITF.AnyObject, 
               ByVal iOri1 As Integer, 
               ByVal iOri2 As Integer, 
               ByVal iOri3 As Integer) As HybridShapeTypeLib.HybridShapeCircleTritangent 

    If (iPart Is Nothing) Or (iHB Is Nothing) Or 
     (iLine1 Is Nothing) Or (iLine2 Is Nothing) Or 
     (iLine3 Is Nothing) Or (iSurface Is Nothing) Then 
     Return Nothing 
    End If 

    Dim HSF As HybridShapeTypeLib.HybridShapeFactory = Nothing 
    HSF = GetHybridShapeFactory(iPart) 
    If HSF Is Nothing Then 
     Return Nothing 
    End If 

    ' Get the Reference of the first line 
    Dim refLine1 As INFITF.Reference = Nothing 
    Try 
     refLine1 = iPart.CreateReferenceFromObject(iLine1) 
    Catch ex As Exception 
     Return Nothing 
    End Try 
    If refLine1 Is Nothing Then 
     Return Nothing 
    End If 

    ' Get the Reference of the second line 
    Dim refLine2 As INFITF.Reference = Nothing 
    Try 
     refLine2 = iPart.CreateReferenceFromObject(iLine2) 
    Catch ex As Exception 
     Return Nothing 
    End Try 
    If refLine2 Is Nothing Then 
     Return Nothing 
    End If 

    ' Get the Reference of the third line 
    Dim refLine3 As INFITF.Reference = Nothing 
    Try 
     refLine3 = iPart.CreateReferenceFromObject(iLine3) 
    Catch ex As Exception 
     Return Nothing 
    End Try 
    If refLine3 Is Nothing Then 
     Return Nothing 
    End If 

    ' Get the Reference of the support surface 
    Dim refSurf As INFITF.Reference = Nothing 
    Try 
     refSurf = iPart.CreateReferenceFromObject(iSurface) 
    Catch ex As Exception 
     Return Nothing 
    End Try 
    If refSurf Is Nothing Then 
     Return Nothing 
    End If 

    ' Create the object, add it the Geometric set, and update the part. 
    Dim HSCTT As HybridShapeTypeLib.HybridShapeCircleTritangent = Nothing 
    Try 
     HSCTT = DirectCast(HSF.AddNewCircleTritangent(refLine1, refLine2, refLine3, refSurf, iOri1, iOri2, iOri3), HybridShapeTypeLib.HybridShapeCircleTritangent) 
     iHB.AppendHybridShape(HSCTT) 
     iPart.InWorkObject = HSCTT 
     iPart.Update() 
    Catch ex As Exception 
     Return Nothing 
    End Try 

    Return HSCTT 
End Function 

C#コード:

//-------------------------------------------------------------- 
public static HybridShapeTypeLib.HybridShapeFactory GetHybridShapeFactory(MECMOD.Part iPart) 
{ 
    if (null == iPart) 
    { 
     return null; 
    } 

    HybridShapeTypeLib.HybridShapeFactory oHSF = null; 
    try 
    { 
     oHSF = (HybridShapeTypeLib.HybridShapeFactory)iPart.HybridShapeFactory; 
    } 
    catch (Exception) 
    { 
     return null; 
    } 
    return oHSF; 
} 

//-------------------------------------------------------------- 
public static HybridShapeTypeLib.HybridShapeCircleTritangent AddNewCircleTritangent(MECMOD.Part iPart, 
                        MECMOD.HybridBody iHB, 
                        INFITF.AnyObject iLine1, 
                        INFITF.AnyObject iLine2, 
                        INFITF.AnyObject iLine3, 
                        INFITF.AnyObject iSurface, 
                        int iOri1, 
                        int iOri2, 
                        int iOri3) 
{ 
    if ((null == iPart) || (null == iHB) || 
     (null == iLine1) || (null == iLine2) || 
     (null == iLine3) || (null == iSurface)) 
    { 
     return null; 
    } 

    HybridShapeTypeLib.HybridShapeFactory HSF = null; 
    HSF = GetHybridShapeFactory(iPart); 
    if (null == HSF) 
    { 
     return null; 
    } 

    // Get the Reference of the first line 
    INFITF.Reference refLine1 = null; 
    try 
    { 
     refLine1 = iPart.CreateReferenceFromObject(iLine1); 
    } 
    catch (Exception) 
    { 
     return null; 
    } 
    if (null == refLine1) 
    { 
     return null; 
    } 

    // Get the Reference of the second line 
    INFITF.Reference refLine2 = null; 
    try 
    { 
     refLine2 = iPart.CreateReferenceFromObject(iLine2); 
    } 
    catch (Exception) 
    { 
     return null; 
    } 
    if (null == refLine2) 
    { 
     return null; 
    } 

    // Get the Reference of the third line 
    INFITF.Reference refLine3 = null; 
    try 
    { 
     refLine3 = iPart.CreateReferenceFromObject(iLine3); 
    } 
    catch (Exception) 
    { 
     return null; 
    } 
    if (null == refLine3) 
    { 
     return null; 
    } 

    // Get the Reference of the support surface 
    INFITF.Reference refSurf = null; 
    try 
    { 
     refSurf = iPart.CreateReferenceFromObject(iSurface); 
    } 
    catch (Exception) 
    { 
     return null; 
    } 
    if (null == refSurf) 
    { 
     return null; 
    } 

    // Create the object, add it the Geometric set, and update the part. 
    HybridShapeTypeLib.HybridShapeCircleTritangent HSCTT = null; 
    try 
    { 
     HSCTT = (HybridShapeTypeLib.HybridShapeCircleTritangent)HSF.AddNewCircleTritangent(refLine1, 
                          refLine2, 
                          refLine3, 
                          refSurf, 
                          iOri1, 
                          iOri2, 
                          iOri3); 
     iHB.AppendHybridShape(HSCTT); 
     iPart.InWorkObject = HSCTT; 
     iPart.Update(); 
    } 
    catch (Exception) 
    { 
     return null; 
    } 

    return HSCTT; 
} 
+0

お返事ありがとうございます!私はそれを試して、それは動作しませんでした。問題はユーザーの特権であると私には思われました。何らかの理由で、私が管理者でない場合、私はいくつかのプロパティにアクセスできません。なぜ私は理解していない... –