Message 1 of 6
Schubkastenerstellung automatisieren

Not applicable
07-15-2020
11:56 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Servus allerseits,
gibt es ein Möglichkeit, dass man per VBA einen Schubkasten automatisch erstellen lassen kann und per Eingabefeld die Maße des Kastens festlegen kann ? Bis jetzt bekomme ich es nur hin, dass ich automatisch ein Bauteil erstellen kann wobei ich die Maße per StringBox eingebe. Weiterhin würde ich gerne eine Gehrung an diese Erstellte Platte machen woran es momentan noch scheitert.
Vielleicht hat jemand ja einen Code der mir weiterhilft oder kann es mir zumindestens erklären wie ich vorgehen sollte.
Sub NeuePLatte()
'Fehlerbehebung
On Error GoTo Fehler
'Maßeingabe
Dim strInboxL As String
strInboxL = InputBox("Bitte Länge eingeben")
If strInboxL = "" Or "0" Then
Exit Sub
End If
Dim strInboxB As String
strInboxB = InputBox("Bitte Breite eingeben")
If strInboxB = "" Or "0" Then
Exit Sub
End If
Dim strInboxD As String
strInboxD = InputBox("Bitte Dicke / Tiefe eingeben")
If strInboxD = "" Or "0" Then
Exit Sub
End If
'Bauteilerstellung
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, _
ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject))
Dim oCompDef As PartComponentDefinition
Set oCompDef = oPartDoc.ComponentDefinition
Dim oSketch As PlanarSketch
Set oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes(3))
Dim oTransGeom As TransientGeometry
Set oTransGeom = ThisApplication.TransientGeometry
Dim oRectangleLines As SketchEntitiesEnumerator
Set oRectangleLines = oSketch.SketchLines.AddAsTwoPointRectangle( _
oTransGeom.CreatePoint2d(0, 0), _
oTransGeom.CreatePoint2d(strInboxL / 10, strInboxB / 10))
Dim oProfile As Profile
Set oProfile = oSketch.Profiles.AddForSolid
Dim oExtrudeDef As ExtrudeDefinition
Set oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kJoinOperation)
Call oExtrudeDef.SetDistanceExtent(strInboxD / 10, kNegativeExtentDirection)
Dim oExtrude As ExtrudeFeature
Set oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)
Dim Doc As Document
' Kante Bearbeiten (Gehrung)
'Speichern
Set Doc = ThisApplication.ActiveDocument
Call Doc.Save
Dim Antwort
Antwort = MsgBox("Soll die Datei geschlossen werden?" & vbCrLf & vbCrLf & "Hinweis!" & vbCrLf & "Wenn die Datei nicht geschlossen wird, kann sie nicht automatisch in einer Baugruppe plaziert werden.", vbYesNo)
If Antwort = vbYes Then
Dim Dcl As Document
Set Dcl = ThisApplication.ActiveDocument
Dcl.Close
If Antwort = vbNo Then
Exit Sub
End If
'evtl. Platzieren in Baugruppe
'Fehlerbehebung
Exit Sub
Fehler:
MsgBox ("Ein Fehler ist aufgetreten. Bitte erneut versuchen.")
Exit Sub
End If
End Sub
Hier einmal der Code mit dem ich das Bauteil erstelle.