- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello Friends,
I would like to constraint work plane of "active assembly document" with the work plane of "placed component".
Here is the code which I wrote, but I'm getting error at syntax of "If oRefDoc.FullFileName = placedComponentFilename Then". The error is "Object variable or With block variable not set (Error 91)".
I cant recognize the problem. Please help me to resolve this issue.
Sub AddMateConstraintBetweenWorkPlanes()
Dim oApp As Inventor.Application
Set oApp = GetObject(, "Inventor.Application")
' Get the active assembly document
Dim oAssemblyDoc As AssemblyDocument
Set oAssemblyDoc = oApp.ActiveDocument
' Check if the active document is an assembly
If Not TypeOf oAssemblyDoc Is AssemblyDocument Then
MsgBox "Active document is not an assembly."
Exit Sub
End If
' Get the active assembly component definition
Dim oAssemblyDef As AssemblyComponentDefinition
Set oAssemblyDef = oAssemblyDoc.ComponentDefinition
' Get the work plane of the active assembly document
Dim oActiveAssemblyWorkPlane As WorkPlane
Set oActiveAssemblyWorkPlane = oAssemblyDef.WorkPlanes.Item("YZ Plane") ' Replace with the actual work plane name
' Find the placed component occurrence by its filename
Dim placedComponentFilename As String
placedComponentFilename = "4924306035.iam" ' Replace with the actual filename of the placed component
' Get the placed component occurrence
Dim oPlacedComponentOccurrence As ComponentOccurrence
Set oPlacedComponentOccurrence = oAssemblyDef.Occurrences.ItemByName("4924306035.iam") ' Replace with the actual occurrence name
' Get the work plane of the placed component
Dim oPlacedComponentWorkPlane As WorkPlane
Set oPlacedComponentWorkPlane = oPlacedComponentOccurrence.Definition.WorkPlanes.Item("YZ Plane") ' Replace with the actual work plane name
' Add the mate constraint between the two work planes
Dim oAssemblyConstraints As AssemblyConstraints
Set oAssemblyConstraints = oAssemblyDef.constraints
Dim oMateConstraint As mateConstraint
Set oMateConstraint = oAssemblyConstraints.AddMateConstraint(oActiveAssemblyWorkPlane, oPlacedComponentWorkPlane, 0)
' Clean up
Set oMateConstraint = Nothing
Set oAssemblyConstraints = Nothing
Set oPlacedComponentWorkPlane = Nothing
Set oPlacedComponentOccurrence = Nothing
Set oActiveAssemblyWorkPlane = Nothing
Set oAssemblyDef = Nothing
Set oAssemblyDoc = Nothing
Set oApp = Nothing
End Sub
Solved! Go to Solution.