Hallo zusammen,
habe vor ein paar Tagen schon einmal einen Beitrag erstellt, im dem ich bei einem Modell eines Delta-Roboters Schwierigkeiten hatte. Es geht darum, Längen einzelner Bauelemente (Streben) zu verändern und anschließend das Modell zu simulieren. Über das Einfügen neuer Bauteile komme ich leider nicht voran, da es immer wieder Fehler bei den Bedingungen gibt... Es soll auch über den VBA-Code funktionieren, in dem dort nach dem Kompilieren ein Fenster erscheinen sollte, in dem man die Länge ändern kann.
Jetzt habe ich die Fehlermeldung "Method 'SetImpl' of object 'Documents' failed". Klicke ich auf "Debug" springt der in die dritte Zeile:Set partDocument1 = CATIA.Documents.Item("Rods2.CATPart")
Der VBA-Code dazu sieht so aus:
Sub CATMain3()
Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.Documents.Item("Rods2.CATPart")
Dim part1 As Part
Set part1 = partDocument1.Part
Dim body1 As Body
Set body1 = part1.Bodies.Item("Corps principal")
Dim sketch1 As Sketch
Set sketch1 = body1.Sketches.Item("Esquisse.1")
Dim factory2D1 As Factory2D
Set factory2D1 = sketch1.OpenEdition()
Dim geometricElements1 As GeometricElements
Set geometricElements1 = sketch1.GeometricElements
Dim point2D1 As Point2D
Set point2D1 = geometricElements1.Item("Point.1")
Dim Value As String
Dim ValueDbl As Double
Dim Check As Boolean
Check = False
Do
Value = InputBox("Please input the desired value", "Value input")
If Value = vbNullString Then Exit Sub '
If IsNumeric(Value) Then
ValueDbl = CDbl(Value)
Check = True
Else
MsgBox "The value should be numerical", vbCritical, "Error"
End If
Loop Until Check = True
point2D1.SetData ValueDbl, 0#
Dim line2D1 As Line2D
Set line2D1 = geometricElements1.Item("Droite.1")
line2D1.SetData 0#, 0#, 1#, 0#
Dim constraints1 As Constraints
Set constraints1 = sketch1.Constraints
Dim constraint1 As Constraint
Set constraint1 = constraints1.Item("Longueur.2")
Dim length1 As Length
Set length1 = constraint1.Dimension
length1.Value = ValueDbl
sketch1.CloseEdition
part1.InWorkObject = sketch1
part1.UpdateObject sketch1
End Sub
Wäre wirklich super, wenn ihr mir helfen könnt.
MfG Felix
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP