Message 1 of 1
Punching tools positioning with offset
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone,
in this function I am currently looking for a sketch with a given name where inside there is a single constrained point and with dimensions defined in the parameters, to then insert a punch tool feature.
Sub Main
Dim sketchName As String = RuleArguments("sketchName")
Dim iFeatureName As String = RuleArguments("iFeatureName")
Dim offset As Integer = RuleArguments("offset")
Dim gradi As Integer = RuleArguments("gradi")
DeleteFeature(sketchName)
If iFeatureName = "0" or iFeatureName = "" Then Exit Sub
InsertPunch(sketchName, iFeatureName, offset, gradi)
End Sub
Sub DeleteFeature(Optional stringaRicerca As String = "")
Dim oFeatures As PartFeatures
Dim esegui As Integer
oFeatures = ThisApplication.ActiveDocument.ComponentDefinition.Features
If stringaRicerca = "" Then
esegui = MessageBox.Show("Eliminare tutte le lavorazioni presenti nella parte?", "ATTENZIONE", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
End If
If esegui = 6 Or stringaRicerca <> "" Then
For Each oFeature As PartFeature In oFeatures
If Left(oFeature.Name, Len(stringaRicerca)) = stringaRicerca Then
oFeature.Delete(True)
End If
Next
End If
End Sub
Sub InsertPunch(sketchName As String, iFeatureName As String, _
Optional offset As Integer = 0, Optional gradi As Integer = 270)
Dim iFeaturePath As String = "...\_iFeature\PunchTools\"
iFeatureName = iFeaturePath & iFeatureName & ".ide"
Try
Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument
Dim oSMDef As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition
Dim oSMFeats As SheetMetalFeatures = oSMDef.Features
oPTFeats = oSMFeats.PunchToolFeatures
Dim oPunchTool As iFeatureDefinition = oPTFeats.CreateiFeatureDefinition(iFeatureName)
Dim oCPoints As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
oSPts = oSMDef.Sketches.Item(sketchName).SketchPoints
For Each oSP As SketchPoint In oSPts
If oSP.HoleCenter Then
oCPoints.Add(oSP)
End If
Next
Dim rad As Double = gradi * Math.PI / 180
oPTF = oPTFeats.Add(oCPoints, oPunchTool, rad)
oPTF.Name = sketchName & "_" & oPTF.Name
Catch ex As Exception
Logger.Error("Lavorazione non creata. - MOTIVO: " & ex.Message & " - STACK: " & ex.StackTrace)
End Try
End Sub
now I would need to be able to insert that punching with a certain offset compared to the point present in the sketch, avoiding the creation of new points in the sketch so as not to insert more punches every time the rule runs with an offset different from the previous one.