iLogic CommandManager.Pick wont work when EoP-Marker is moved

iLogic CommandManager.Pick wont work when EoP-Marker is moved

Michael.RostZ454J
Contributor Contributor
529 Views
2 Replies
Message 1 of 3

iLogic CommandManager.Pick wont work when EoP-Marker is moved

Michael.RostZ454J
Contributor
Contributor

Hello.

 

I work on customer STEP-Files very often. So I have created an iLogic-rule that closes an hole "face" with an extrusion and places a threaded hole at the same position.

That works mostly well exept when the EoP-Marker ist moved, so that some already placed features are suppressed. So when it comes to the second "pick" for the circular entitie, nothing is selectable or is highlighted for selection.

 

Maybe someone knows, wheres the bug in my code.

Thanks for your help 🙂.

 

 

'Definition
Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oApp As Inventor.Application = ThisApplication
Dim Bohrungstiefe As Double
Dim Gewindetiefe As Double
Dim Steigung As Double
Dim Nennmass As String

'Definition der transienten Geometrie
Dim oTransGeom As TransientGeometry
oTransGeom = ThisApplication.TransientGeometry

'referenzieren der Komponenten Definition
Dim oCompDef As PartComponentDefinition
oCompDef = oDoc.ComponentDefinition

'nachdem Regel abgearbeitet ist, startet sie wieder von vorn
TheStart :
On Error GoTo ENDE

'Skizzenebene wählen	
Dim oFace As Object = Nothing
oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPlanarEntities, "Startfläche wählen")

'Skizze erstellen
Dim oSketch As PlanarSketch = Nothing
oSketch = oCompDef.Sketches.Add(oFace)
oSketch.Edit

'zu ersetzende Bohrung wählen
Dim oObject As Object = Nothing
oObject = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllCircularEntities, "Bohrungskante wählen")
Hole_Dia = oObject.geometry.radius*2*10 'Converted to Diameter and mm

'Endfläche der Bohrung wählen, entspricht auch der neuen Bohrungstiefe
Dim Endflaeche As Object = Nothing
Endflaeche = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Endfläche wählen")
Bohrungstiefe = (ThisApplication.MeasureTools.GetMinimumDistance(oFace, Endflaeche))*10

'Bohrungskante in Skizze projezieren
Call oSketch.AddByProjectingEntity(oObject)
oSketch.ExitEdit

'Profil für die Extrusion wählen
Dim oProfile As Profile = Nothing
oProfile = oSketch.Profiles.AddForSolid

'Bohrung verschließen mit einer Extrusion bis zu angewählten Endfläche
Dim oExtrudeDef As ExtrudeDefinition
oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kJoinOperation)
Call oExtrudeDef.SetToExtent(Endflaeche, kNegativeExtentDirection)
Dim oExtrude As ExtrudeFeature
oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)

'Skizzenpunkt in der erstellten Skizze als Zentrum der neuen Bohrung definieren
oSketch.Edit
oHoleCenter1 = ThisApplication.TransientObjects.CreateObjectCollection
oHoleCenter1.Add(oSketch.SketchPoints.Item(1))
oSketch.ExitEdit
'Skizze wird verwendet von der Extrusion und der neuen Bohrung
oSketch.Shared = True

'Anhand vom ursprünglichen Bohrungsdurchmesser ein Nennmaß für das Gewinde wählen
Select Case Hole_Dia
	Case <= 1.57
		Nennmass = "M2x0.4"
		Steigung = 0.4
	Case <= 2.01
		Nennmass = "M2.5x0.45"
		Steigung = 0.45
	Case <= 2.46
		Nennmass = "M3x0.5"
		Steigung = 0.5
	Case <= 3.24
		Nennmass = "M4x0.7"
		Steigung = 0.7
	Case <= 4.13
		Nennmass = "M5x0.8"
		Steigung = 0.8
	Case <= 4.92
		Nennmass = "M6x1"
		Steigung = 1
	Case <= 6.65
		Nennmass = "M8x1.25"
		Steigung = 1.25
	Case <= 8.38
		Nennmass = "M10x1.5"
		Steigung = 1.5
	Case <= 10.11
		Nennmass = "M12x1.75"
		Steigung = 1.75
	Case <= 13.84
		Nennmass = "M16x2"
		Steigung = 2
	Case <= 17.29
		Nennmass = "M20x2.5"
		Steigung = 2.5
	Case <= 20.75
		Nennmass = "M24x3"
		Steigung = 3
	Case <= 26.21
		Nennmass = "M30x3.5"
		Steigung = 3.5
	Case <= 31.67
		Nennmass = "M36x4"
		Steigung = 4
	Case <= 37.13
		Nennmass = "M42x4.5"
		Steigung = 4.5
	Case <= 42.59
		Nennmass = "M48x5"
		Steigung = 5
	Case <= 50.05
		Nennmass = "M56x5.5"
		Steigung = 5.5
	Case Else
		Nennmass = "M64x6"
		Steigung = 6
End Select

'Gewindetiefe festlegen
Gewindetiefe = Bohrungstiefe - 3 * Steigung

'Gewindebohrung erstellen
Dim oHoleTapInfo As HoleTapInfo
oHoleTapInfo = ThisApplication.ActiveDocument.ComponentDefinition.Features.HoleFeatures.CreateTapInfo(True, "ISO Metrisches Profil", Nennmass, "6H", False, Gewindetiefe/10)
BottomTipAngle = 140*PI/180
oBohrung2 = ThisApplication.ActiveDocument.ComponentDefinition.Features.HoleFeatures.AddDrilledByDistanceExtent(oHoleCenter1, oHoleTapInfo, Bohrungstiefe/10, PartFeatureExtentDirectionEnum.kPositiveExtentDirection, False, BottomTipAngle) 

'Sichtbarkeit der Skizze deaktivieren
oSketch.Visible = False

'Wenn erfolgreich, dann beginne wieder am Start mit der nächsten Bohrung
GoTo TheStart:

Return 
ENDE:

 

0 Likes
Accepted solutions (1)
530 Views
2 Replies
Replies (2)
Message 2 of 3

moveworkforward
Contributor
Contributor
Accepted solution

Hi @Michael.RostZ454J 

 

I have moved the sketch creating after all selection is complete and the problem is gone:

 

Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oApp As Inventor.Application = ThisApplication
Dim Bohrungstiefe As Double
Dim Gewindetiefe As Double
Dim Steigung As Double
Dim Nennmass As String

'Definition der transienten Geometrie
Dim oTransGeom As TransientGeometry
oTransGeom = ThisApplication.TransientGeometry

'referenzieren der Komponenten Definition
Dim oCompDef As PartComponentDefinition
oCompDef = oDoc.ComponentDefinition

'nachdem Regel abgearbeitet ist, startet sie wieder von vorn
TheStart :
On Error GoTo ENDE

'Skizzenebene wählen	
Dim oFace As Object = Nothing
oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPlanarEntities, "Startfläche wählen")

'zu ersetzende Bohrung wählen
Dim oObject As Object = Nothing
oObject = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllCircularEntities, "Bohrungskante wählen")
Hole_Dia = oObject.geometry.radius*2*10 'Converted to Diameter and mm

'Endfläche der Bohrung wählen, entspricht auch der neuen Bohrungstiefe
Dim Endflaeche As Object = Nothing
Endflaeche = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Endfläche wählen")
Bohrungstiefe = (ThisApplication.MeasureTools.GetMinimumDistance(oFace, Endflaeche))*10

'Skizze erstellen
Dim oSketch As PlanarSketch = Nothing
oSketch = oCompDef.Sketches.Add(oFace)
'oSketch.Edit

'Bohrungskante in Skizze projezieren
Call oSketch.AddByProjectingEntity(oObject)
'oSketch.ExitEdit

'Profil für die Extrusion wählen
Dim oProfile As Profile = Nothing
oProfile = oSketch.Profiles.AddForSolid

'Bohrung verschließen mit einer Extrusion bis zu angewählten Endfläche
Dim oExtrudeDef As ExtrudeDefinition
oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kJoinOperation)
Call oExtrudeDef.SetToExtent(Endflaeche, kNegativeExtentDirection)
Dim oExtrude As ExtrudeFeature
oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)

'Skizzenpunkt in der erstellten Skizze als Zentrum der neuen Bohrung definieren
oSketch.Edit
oHoleCenter1 = ThisApplication.TransientObjects.CreateObjectCollection
oHoleCenter1.Add(oSketch.SketchPoints.Item(1))
oSketch.ExitEdit
'Skizze wird verwendet von der Extrusion und der neuen Bohrung
oSketch.Shared = True

'Anhand vom ursprünglichen Bohrungsdurchmesser ein Nennmaß für das Gewinde wählen
Select Case Hole_Dia
	Case <= 1.57
		Nennmass = "M2x0.4"
		Steigung = 0.4
	Case <= 2.01
		Nennmass = "M2.5x0.45"
		Steigung = 0.45
	Case <= 2.46
		Nennmass = "M3x0.5"
		Steigung = 0.5
	Case <= 3.24
		Nennmass = "M4x0.7"
		Steigung = 0.7
	Case <= 4.13
		Nennmass = "M5x0.8"
		Steigung = 0.8
	Case <= 4.92
		Nennmass = "M6x1"
		Steigung = 1
	Case <= 6.65
		Nennmass = "M8x1.25"
		Steigung = 1.25
	Case <= 8.38
		Nennmass = "M10x1.5"
		Steigung = 1.5
	Case <= 10.11
		Nennmass = "M12x1.75"
		Steigung = 1.75
	Case <= 13.84
		Nennmass = "M16x2"
		Steigung = 2
	Case <= 17.29
		Nennmass = "M20x2.5"
		Steigung = 2.5
	Case <= 20.75
		Nennmass = "M24x3"
		Steigung = 3
	Case <= 26.21
		Nennmass = "M30x3.5"
		Steigung = 3.5
	Case <= 31.67
		Nennmass = "M36x4"
		Steigung = 4
	Case <= 37.13
		Nennmass = "M42x4.5"
		Steigung = 4.5
	Case <= 42.59
		Nennmass = "M48x5"
		Steigung = 5
	Case <= 50.05
		Nennmass = "M56x5.5"
		Steigung = 5.5
	Case Else
		Nennmass = "M64x6"
		Steigung = 6
End Select

'Gewindetiefe festlegen
Gewindetiefe = Bohrungstiefe - 3 * Steigung

'Gewindebohrung erstellen
Dim oHoleTapInfo As HoleTapInfo
oHoleTapInfo = ThisApplication.ActiveDocument.ComponentDefinition.Features.HoleFeatures.CreateTapInfo(True, "ISO Metrisches Profil", Nennmass, "6H", False, Gewindetiefe / 10)

BottomTipAngle = 140*PI/180
oBohrung2 = ThisApplication.ActiveDocument.ComponentDefinition.Features.HoleFeatures.AddDrilledByDistanceExtent(oHoleCenter1, oHoleTapInfo, Bohrungstiefe/10, PartFeatureExtentDirectionEnum.kPositiveExtentDirection, False, BottomTipAngle) 

'Sichtbarkeit der Skizze deaktivieren
oSketch.Visible = False

'Wenn erfolgreich, dann beginne wieder am Start mit der nächsten Bohrung
GoTo TheStart:

Return 
ENDE:

 

My Inventor Add-Ins:

Place Fasteners 

Quick Section View 

Message 3 of 3

Michael.RostZ454J
Contributor
Contributor

Hello @moveworkforward,

 

works for me as well. Thanks for your help.

0 Likes