Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I had problem with reaching to iLogicVb via VB.NET
Function ApplyChamfer(chamferDistance As String)
Try
Dim oPDoc As PartDocument = g_inventorApplication.ActiveDocument
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oNamedEntities As NamedEntities = iLogicVb.Automation.GetNamedEntities(oPDoc)
Dim yzPlaneCrossing As Boolean
Dim xzPlaneCrossing As Boolean
Dim faceCounter As Integer = 1 ' Counters for naming faces and edges
Dim edgeCounter As Integer = 1 ' Counters for naming faces and edges
For Each oFace As Face In oPDef.SurfaceBodies.Item(1).Faces ' Iterate over all faces in the part body
yzPlaneCrossing = False
xzPlaneCrossing = False
For Each oEdge As Edge In oFace.Edges ' Check if face crosses the YZ plane and/or XZ plane
Dim startVertex As Vertex = oEdge.StartVertex
Dim stopVertex As Vertex = oEdge.StopVertex
Dim startX As Double = startVertex.Point.X
Dim stopX As Double = stopVertex.Point.X
Dim startY As Double = startVertex.Point.Y
Dim stopY As Double = stopVertex.Point.Y
If (startX < 0 And stopX > 0) Or (startX > 0 And stopX < 0) Or (Math.Abs(startX) < 0.01) Or (Math.Abs(stopX) < 0.01) Then ' Check if the edge crosses the YZ plane (x-coordinate crosses 0)
yzPlaneCrossing = True
End If
If (startY < 0 And stopY > 0) Or (startY > 0 And stopY < 0) Or (Math.Abs(startY) < 0.01) Or (Math.Abs(stopY) < 0.01) Then
xzPlaneCrossing = True
End If
Next
If yzPlaneCrossing And Not xzPlaneCrossing Then
Dim faceName As String = "faceForChamfer_" & faceCounter
Try
oNamedEntities.SetName(oFace, faceName)
Logger.Info("Assigned name to face: " & faceName)
Catch ex As Exception
MsgBox("Failed to assign name to face: " & ex.Message)
End Try
For Each oEdge As Edge In oFace.Edges
Dim startVertex As Vertex = oEdge.StartVertex
Dim stopVertex As Vertex = oEdge.StopVertex
Dim startZ As Double = startVertex.Point.Z
Dim stopZ As Double = stopVertex.Point.Z
If startZ = stopZ Then
Dim edgeName As String = "edgeForChamfer_" & edgeCounter
Try
oNamedEntities.SetName(oEdge, edgeName)
Logger.Info("Assigned name to edge: " & edgeName)
Catch ex As Exception
MsgBox("Failed to assign name to edge: " & ex.Message)
End Try
edgeCounter += 1
End If
Next
faceCounter += 1
End If
Next
Dim edge1 As Edge = oNamedEntities.FindEntity("edgeForChamfer_1")
Dim edge2 As Edge = oNamedEntities.FindEntity("edgeForChamfer_2")
Dim edge3 As Edge = oNamedEntities.FindEntity("edgeForChamfer_3")
Dim edge4 As Edge = oNamedEntities.FindEntity("edgeForChamfer_4")
Dim faceForChamfer2 As Face = oNamedEntities.FindEntity("faceForChamfer_2")
Dim faceForChamfer1 As Face = oNamedEntities.FindEntity("faceForChamfer_1")
Dim edgetoChamfer1 As EdgeCollection = ThisApplication.TransientObjects.CreateEdgeCollection()
Dim edgetoChamfer2 As EdgeCollection = ThisApplication.TransientObjects.CreateEdgeCollection()
edgetoChamfer1.Add(edge1)
edgetoChamfer1.Add(edge2) ' edgetoChamfer1.Add(oNamedEntities.Entities.Value("edgeForChamfer_2"))
edgetoChamfer2.Add(edge3)
edgetoChamfer2.Add(edge4)
Dim chamferEdge As ChamferFeature = oPDef.Features.ChamferFeatures.AddUsingDistance(edgetoChamfer1, chamferDistance, False, False, False)
Dim chamferEdge2 As ChamferFeature = oPDef.Features.ChamferFeatures.AddUsingDistanceAndAngle(edgetoChamfer2, faceForChamfer2, chamferDistance, "45", False, False)
Catch ex As Exception
MsgBox("Error during chamfer operation: " & ex.Message)
End Try
End Function
So I researched a bit then found out that I was able to reach in this way :
Dim oPDoc As PartDocument = CType(g_inventorApplication.ActiveDocument, PartDocument)
PartComponentDefinition = oPDoc.ComponentDefinition ' Obtain IiLogicAutomation instance
Dim iLogicAuto As IiLogicAutomation =CType(g_inventorApplication.Automation, IiLogicAutomation)
Dim oNamedEntities As NamedEntities = iLogicAuto.GetNamedEntities(oPDoc)
But it gives casting error.
I can use AttributeSets in order to reach those entities but is there any way to react to named entities by using IiLogicAutomation or iLogicVb somehow ?
Solved! Go to Solution.