Message 1 of 2
Create constraint on two faces
Not applicable
06-08-2021
05:03 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone.
I'm new to Inventor API VBA.
I am trying to create two constraints on two details in an assembly.
I created a constraint on cylindrical faces.
Similarly, I created a constraint on two flat faces, but the wrong flat face is selected on the first detail.
I need to select a flat face inside the cut of the first part, but I do not understand how to do this.
Please help.
What am I doing wrong?
My code:
Imports System.Runtime.InteropServices
Public Class Form1
Dim oApp As Inventor.Application = GetInventorApplication()
''FUNCTION OF GETTING A REFERENCE TO Inventor
Function GetInventorApplication() As Inventor.Application
Dim InvApp As Inventor.Application
Try
InvApp = CType(Marshal.GetActiveObject("Inventor.Application"), Inventor.Application)
Catch ex As Exception
Dim InvType As Type = Type.GetTypeFromProgID("Inventor.Application")
InvApp = CType(Activator.CreateInstance(InvType), Inventor.Application)
InvApp.Visible = True
End Try
Return InvApp
End Function
Private Sub Create_Assembly(sender As Object, e As EventArgs) Handles Button1.Click
Call Create_Assembly_Procedure()
End Sub
Sub Create_Assembly_Procedure()
''CREATION OF ASSEMBLY DOCUMENT
Dim oAsDoc As Inventor.AssemblyDocument = oApp.Documents.Add(Inventor.DocumentTypeEnum.kAssemblyDocumentObject, oApp.GetTemplateFile(Inventor.DocumentTypeEnum.kAssemblyDocumentObject))
''OBTAINING OBJECT COMPONENTS
Dim oAsCompDef As Inventor.AssemblyComponentDefinition = oApp.ActiveDocument.ComponentDefinition
''INDICATION OF THE MATRIX
Dim oPositionMatrix As Inventor.Matrix = oApp.TransientGeometry.CreateMatrix
''CREATING A PARTS INLET
Dim sFileNameDetail_1 As String = "D:Details\Detail_1.ipt"
Dim sFileNameDetail_2 As String = "D:Details\Detail_2.ipt"
Dim sFileNameDetail_3 As String = "D:Details\Detail_3.ipt"
''PARAMETERS OF PARTS POSITION
Dim VectorDetail_2 As Inventor.Vector = oApp.TransientGeometry.CreateVector(3, 3, -5)
Dim VectorDetail_3 As Inventor.Vector = oApp.TransientGeometry.CreateVector(3, 3, 10)
''PARTS INPUT
Dim Detail_1 As Inventor.ComponentOccurrence = oAsDoc.ComponentDefinition.Occurrences.Add(sFileNameDetail_1, oPositionMatrix)
oPositionMatrix.SetTranslation(VectorDetail_2)
Dim Detail_2 As Inventor.ComponentOccurrence = oAsDoc.ComponentDefinition.Occurrences.Add(sFileNameDetail_2, oPositionMatrix)
oPositionMatrix.SetTranslation(VectorDetail_3)
Dim Detail_3 As Inventor.ComponentOccurrence = oAsDoc.ComponentDefinition.Occurrences.Add(sFileNameDetail_3, oPositionMatrix)
''SETTING THE CAMERA VIEW
Dim oCamera As Inventor.Camera = oApp.ActiveView.Camera
oCamera.ViewOrientationType = Inventor.ViewOrientationTypeEnum.kIsoTopRightViewOrientation
oCamera.Apply()
oApp.ActiveView.Fit()
''CONSTRAINT ON CYLINDRICAL FACES
Dim oAxisDetail1 As Inventor.Face
Dim oAxisDetail2 As Inventor.Face
Dim oFace As Inventor.Face
For Each oFace In Detail_1.SurfaceBodies(1).Faces
If oFace.SurfaceType = Inventor.SurfaceTypeEnum.kCylinderSurface Then
oAxisDetail1 = oFace
End If
Next
For Each oFace In Detail_2.SurfaceBodies(1).Faces
If oFace.SurfaceType = Inventor.SurfaceTypeEnum.kCylinderSurface Then
oAxisDetail2 = oFace
End If
Next
Dim oConstr As Inventor.AssemblyConstraint
oConstr = oAsCompDef.Constraints.AddMateConstraint(oAxisDetail1, oAxisDetail2, 0,
Inventor.InferredTypeEnum.kInferredLine,
Inventor.InferredTypeEnum.kInferredLine)
''CONSTRAINT ON FLAT FACES
Dim oFaceDetail1 As Inventor.Face
Dim oFaceDetail2 As Inventor.Face
For Each oFace In Detail_1.SurfaceBodies(1).Faces
If oFace.SurfaceType = Inventor.SurfaceTypeEnum.kPlaneSurface Then
oFaceDetail1 = oFace
End If
Next
For Each oFace In Detail_2.SurfaceBodies(1).Faces
If oFace.SurfaceType = Inventor.SurfaceTypeEnum.kPlaneSurface Then
oFaceDetail2 = oFace
End If
Next
oConstr = oAsCompDef.Constraints.AddMateConstraint(oFaceDetail1, oFaceDetail2, 0,
Inventor.InferredTypeEnum.kNoInference,
Inventor.InferredTypeEnum.kNoInference)
End Sub
End Class