Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have written some code for turning on/off work planes and axis by selecting a part(s) and clicking the appropriate button and it works great for custom part files and assemblies. It errors though when you try to turn on or off planes or axis for a content center part (system.RuntimeType.forwardcalltoinvokemember 0x80004005). I assume it is because they are read only files. I can turn them on and off through the browser though. Is there a way programmatically to allow them to be turned on/off like I can do through the browser?
Program Form
Imports Inventor Imports System.Windows.Forms Public Class WFonandoff Dim thisapplication As Inventor.Application = g_inventorApplication Private Sub WFonandoff_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.TopMost = True End Sub Private Sub OPon_Click(sender As Object, e As EventArgs) Handles OPon.Click Dim AssyModel As AssemblyDocument = thisapplication.ActiveDocument Dim AssyModelDef As AssemblyComponentDefinition = AssyModel.ComponentDefinition If AssyModel.SelectSet.Count > 0 Then For Each obj As ComponentOccurrence In AssyModel.SelectSet Dim oPlane As WorkPlaneProxy Dim x As Integer Dim doc As Document = obj.ReferencedDocumentDescriptor.ReferencedDocument If Not cbALL.Checked Then If doc.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Or doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'part or sheetmetal Dim modeldef As PartComponentDefinition = obj.Definition For x = 1 To 3 Try Call obj.CreateGeometryProxy(modeldef.WorkPlanes.Item(x), oPlane) oPlane.Visible = True Catch ex As Exception MsgBox(ex.ToString) End Try Next ElseIf doc.SubType = "{E60F81E1-49B3-11D0-93C3-7E0706000000}" Then 'assembly Dim modeldef As AssemblyComponentDefinition = obj.Definition For x = 1 To 3 Call obj.CreateGeometryProxy(modeldef.WorkPlanes.Item(x), oPlane) oPlane.Visible = True Next ElseIf doc.SubType = "{28EC8354-9024-440F-A8A2-0E0E55D635B0}" Then 'weldment Dim modeldef As AssemblyComponentDefinition = obj.Definition For x = (modeldef.WorkPlanes.Count - 2) To modeldef.WorkPlanes.Count Call obj.CreateGeometryProxy(modeldef.WorkPlanes.Item(x), oPlane) oPlane.Visible = True Next End If Else If doc.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Or doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'part or sheetmetal Dim modeldef As PartComponentDefinition = obj.Definition For x = 1 To modeldef.WorkPlanes.Count Try Call obj.CreateGeometryProxy(modeldef.WorkPlanes.Item(x), oPlane) oPlane.Visible = True Catch ex As Exception MsgBox(ex.ToString) End Try Next ElseIf doc.SubType = "{E60F81E1-49B3-11D0-93C3-7E0706000000}" Then 'assembly Dim modeldef As AssemblyComponentDefinition = obj.Definition For x = 1 To modeldef.WorkPlanes.Count Call obj.CreateGeometryProxy(modeldef.WorkPlanes.Item(x), oPlane) oPlane.Visible = True Next ElseIf doc.SubType = "{28EC8354-9024-440F-A8A2-0E0E55D635B0}" Then 'weldment Dim modeldef As AssemblyComponentDefinition = obj.Definition For x = 1 To modeldef.WorkPlanes.Count Call obj.CreateGeometryProxy(modeldef.WorkPlanes.Item(x), oPlane) oPlane.Visible = True Next End If End If x = 0 Next AssyModel.Update() Else MessageBox.Show("No selections made. Please select components and try again.", "Selection", MessageBoxButtons.OK) End If End Sub Private Sub OPoff_Click(sender As Object, e As EventArgs) Handles OPoff.Click Dim AssyModel As AssemblyDocument = thisapplication.ActiveDocument Dim AssyModelDef As AssemblyComponentDefinition = AssyModel.ComponentDefinition If AssyModel.SelectSet.Count > 0 Then For Each obj As ComponentOccurrence In AssyModel.SelectSet Dim oPlane As WorkPlaneProxy Dim x As Integer Dim doc As Document = obj.ReferencedDocumentDescriptor.ReferencedDocument If Not cbALL.Checked Then If doc.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Or doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'part or sheetmetal Dim modeldef As PartComponentDefinition = obj.Definition For x = 1 To 3 Call obj.CreateGeometryProxy(modeldef.WorkPlanes.Item(x), oPlane) oPlane.Visible = False Next ElseIf doc.SubType = "{E60F81E1-49B3-11D0-93C3-7E0706000000}" Then 'assembly Dim modeldef As AssemblyComponentDefinition = obj.Definition For x = 1 To 3 Call obj.CreateGeometryProxy(modeldef.WorkPlanes.Item(x), oPlane) oPlane.Visible = False Next ElseIf doc.SubType = "{28EC8354-9024-440F-A8A2-0E0E55D635B0}" Then 'weldment Dim modeldef As AssemblyComponentDefinition = obj.Definition For x = (modeldef.WorkPlanes.Count - 2) To modeldef.WorkPlanes.Count Call obj.CreateGeometryProxy(modeldef.WorkPlanes.Item(x), oPlane) oPlane.Visible = False Next End If Else If doc.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Or doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'part or sheetmetal Dim modeldef As PartComponentDefinition = obj.Definition For x = 1 To modeldef.WorkPlanes.Count Call obj.CreateGeometryProxy(modeldef.WorkPlanes.Item(x), oPlane) oPlane.Visible = False Next ElseIf doc.SubType = "{E60F81E1-49B3-11D0-93C3-7E0706000000}" Then 'assembly Dim modeldef As AssemblyComponentDefinition = obj.Definition For x = 1 To modeldef.WorkPlanes.Count Call obj.CreateGeometryProxy(modeldef.WorkPlanes.Item(x), oPlane) oPlane.Visible = False Next ElseIf doc.SubType = "{28EC8354-9024-440F-A8A2-0E0E55D635B0}" Then 'weldment Dim modeldef As AssemblyComponentDefinition = obj.Definition For x = 1 To modeldef.WorkPlanes.Count Call obj.CreateGeometryProxy(modeldef.WorkPlanes.Item(x), oPlane) oPlane.Visible = False Next End If End If x = 0 Next AssyModel.Update() Else MessageBox.Show("No selections made. Please select components and try again.", "Selection", MessageBoxButtons.OK) End If End Sub Private Sub UPon_Click(sender As Object, e As EventArgs) Handles UPon.Click Dim AssyModel As AssemblyDocument = thisapplication.ActiveDocument Dim AssyModelDef As AssemblyComponentDefinition = AssyModel.ComponentDefinition If AssyModel.SelectSet.Count > 0 Then For Each obj As ComponentOccurrence In AssyModel.SelectSet Dim oPlane As WorkPlaneProxy Dim x As Integer Dim doc As Document = obj.ReferencedDocumentDescriptor.ReferencedDocument If doc.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Or doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'part or sheetmetal Dim modeldef As PartComponentDefinition = obj.Definition For x = 4 To modeldef.WorkPlanes.Count Call obj.CreateGeometryProxy(modeldef.WorkPlanes.Item(x), oPlane) oPlane.Visible = True Next ElseIf doc.SubType = "{E60F81E1-49B3-11D0-93C3-7E0706000000}" Then 'assembly Dim modeldef As AssemblyComponentDefinition = obj.Definition For x = 4 To modeldef.WorkPlanes.Count Call obj.CreateGeometryProxy(modeldef.WorkPlanes.Item(x), oPlane) oPlane.Visible = True Next ElseIf doc.SubType = "{28EC8354-9024-440F-A8A2-0E0E55D635B0}" Then 'weldment Dim modeldef As AssemblyComponentDefinition = obj.Definition For x = 1 To (modeldef.WorkPlanes.Count - 3) Call obj.CreateGeometryProxy(modeldef.WorkPlanes.Item(x), oPlane) oPlane.Visible = True Next End If x = 0 Next AssyModel.Update() Else MessageBox.Show("No selections made. Please select components and try again.", "Selection", MessageBoxButtons.OK) End If End Sub Private Sub UPoff_Click(sender As Object, e As EventArgs) Handles UPoff.Click Dim AssyModel As AssemblyDocument = thisapplication.ActiveDocument Dim AssyModelDef As AssemblyComponentDefinition = AssyModel.ComponentDefinition If AssyModel.SelectSet.Count > 0 Then For Each obj As ComponentOccurrence In AssyModel.SelectSet Dim oPlane As WorkPlaneProxy Dim x As Integer Dim doc As Document = obj.ReferencedDocumentDescriptor.ReferencedDocument If doc.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Or doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'part or sheetmetal Dim modeldef As PartComponentDefinition = obj.Definition For x = 4 To modeldef.WorkPlanes.Count Call obj.CreateGeometryProxy(modeldef.WorkPlanes.Item(x), oPlane) oPlane.Visible = False Next ElseIf doc.SubType = "{E60F81E1-49B3-11D0-93C3-7E0706000000}" Then 'assembly Dim modeldef As AssemblyComponentDefinition = obj.Definition For x = 4 To modeldef.WorkPlanes.Count Call obj.CreateGeometryProxy(modeldef.WorkPlanes.Item(x), oPlane) oPlane.Visible = False Next ElseIf doc.SubType = "{28EC8354-9024-440F-A8A2-0E0E55D635B0}" Then 'weldment Dim modeldef As AssemblyComponentDefinition = obj.Definition For x = 1 To (modeldef.WorkPlanes.Count - 3) Call obj.CreateGeometryProxy(modeldef.WorkPlanes.Item(x), oPlane) oPlane.Visible = False Next End If x = 0 Next AssyModel.Update() Else MessageBox.Show("No selections made. Please select components and try again.", "Selection", MessageBoxButtons.OK) End If End Sub Private Sub OAon_Click(sender As Object, e As EventArgs) Handles OAon.Click Dim AssyModel As AssemblyDocument = thisapplication.ActiveDocument Dim AssyModelDef As AssemblyComponentDefinition = AssyModel.ComponentDefinition If AssyModel.SelectSet.Count > 0 Then For Each obj As ComponentOccurrence In AssyModel.SelectSet Dim oAxis As WorkAxisProxy Dim x As Integer Dim doc As Document = obj.ReferencedDocumentDescriptor.ReferencedDocument If Not cbALL.Checked Then If doc.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Or doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'part or sheetmetal Dim modeldef As PartComponentDefinition = obj.Definition For x = 1 To 3 Call obj.CreateGeometryProxy(modeldef.WorkAxes.Item(x), oAxis) oAxis.Visible = True oAxis.AutoResize = True Next ElseIf doc.SubType = "{E60F81E1-49B3-11D0-93C3-7E0706000000}" Then 'assembly Dim modeldef As AssemblyComponentDefinition = obj.Definition For x = 1 To 3 Call obj.CreateGeometryProxy(modeldef.WorkAxes.Item(x), oAxis) oAxis.Visible = True oAxis.AutoResize = True Next ElseIf doc.SubType = "{28EC8354-9024-440F-A8A2-0E0E55D635B0}" Then 'weldment Dim modeldef As AssemblyComponentDefinition = obj.Definition For x = (modeldef.WorkAxes.Count - 2) To modeldef.WorkAxes.Count Call obj.CreateGeometryProxy(modeldef.WorkAxes.Item(x), oAxis) oAxis.Visible = True oAxis.AutoResize = True Next End If Else If doc.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Or doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'part or sheetmetal Dim modeldef As PartComponentDefinition = obj.Definition For x = 1 To modeldef.WorkAxes.Count Call obj.CreateGeometryProxy(modeldef.WorkAxes.Item(x), oAxis) oAxis.Visible = True oAxis.AutoResize = True Next ElseIf doc.SubType = "{E60F81E1-49B3-11D0-93C3-7E0706000000}" Then 'assembly Dim modeldef As AssemblyComponentDefinition = obj.Definition For x = 1 To modeldef.WorkAxes.Count Call obj.CreateGeometryProxy(modeldef.WorkAxes.Item(x), oAxis) oAxis.Visible = True oAxis.AutoResize = True Next ElseIf doc.SubType = "{28EC8354-9024-440F-A8A2-0E0E55D635B0}" Then 'weldment Dim modeldef As AssemblyComponentDefinition = obj.Definition For x = 1 To modeldef.WorkAxes.Count Call obj.CreateGeometryProxy(modeldef.WorkAxes.Item(x), oAxis) oAxis.Visible = True oAxis.AutoResize = True Next End If End If x = 0 Next AssyModel.Update() Else MessageBox.Show("No selections made. Please select components and try again.", "Selection", MessageBoxButtons.OK) End If End Sub Private Sub OAoff_Click(sender As Object, e As EventArgs) Handles OAoff.Click Dim AssyModel As AssemblyDocument = thisapplication.ActiveDocument Dim AssyModelDef As AssemblyComponentDefinition = AssyModel.ComponentDefinition If AssyModel.SelectSet.Count > 0 Then For Each obj As ComponentOccurrence In AssyModel.SelectSet Dim oAxis As WorkAxisProxy Dim x As Integer Dim doc As Document = obj.ReferencedDocumentDescriptor.ReferencedDocument If Not cbALL.Checked Then If doc.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Or doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'part or sheetmetal Dim modeldef As PartComponentDefinition = obj.Definition For x = 1 To 3 Call obj.CreateGeometryProxy(modeldef.WorkAxes.Item(x), oAxis) oAxis.Visible = False Next ElseIf doc.SubType = "{E60F81E1-49B3-11D0-93C3-7E0706000000}" Then 'assembly Dim modeldef As AssemblyComponentDefinition = obj.Definition For x = 1 To 3 Call obj.CreateGeometryProxy(modeldef.WorkAxes.Item(x), oAxis) oAxis.Visible = False Next ElseIf doc.SubType = "{28EC8354-9024-440F-A8A2-0E0E55D635B0}" Then 'weldment Dim modeldef As AssemblyComponentDefinition = obj.Definition For x = (modeldef.WorkAxes.Count - 2) To modeldef.WorkAxes.Count Call obj.CreateGeometryProxy(modeldef.WorkAxes.Item(x), oAxis) oAxis.Visible = False Next End If Else If doc.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Or doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'part or sheetmetal Dim modeldef As PartComponentDefinition = obj.Definition For x = 1 To modeldef.WorkAxes.Count Call obj.CreateGeometryProxy(modeldef.WorkAxes.Item(x), oAxis) oAxis.Visible = False Next ElseIf doc.SubType = "{E60F81E1-49B3-11D0-93C3-7E0706000000}" Then 'assembly Dim modeldef As AssemblyComponentDefinition = obj.Definition For x = 1 To modeldef.WorkAxes.Count Call obj.CreateGeometryProxy(modeldef.WorkAxes.Item(x), oAxis) oAxis.Visible = False Next ElseIf doc.SubType = "{28EC8354-9024-440F-A8A2-0E0E55D635B0}" Then 'weldment Dim modeldef As AssemblyComponentDefinition = obj.Definition For x = 1 To modeldef.WorkAxes.Count Call obj.CreateGeometryProxy(modeldef.WorkAxes.Item(x), oAxis) oAxis.Visible = False Next End If End If x = 0 Next AssyModel.Update() Else MessageBox.Show("No selections made. Please select components and try again.", "Selection", MessageBoxButtons.OK) End If End Sub Private Sub UAon_Click(sender As Object, e As EventArgs) Handles UAon.Click Dim AssyModel As AssemblyDocument = thisapplication.ActiveDocument Dim AssyModelDef As AssemblyComponentDefinition = AssyModel.ComponentDefinition If AssyModel.SelectSet.Count > 0 Then For Each obj As ComponentOccurrence In AssyModel.SelectSet Dim oAxis As WorkAxisProxy Dim x As Integer Dim doc As Document = obj.ReferencedDocumentDescriptor.ReferencedDocument If doc.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Or doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'part or sheetmetal Dim modeldef As PartComponentDefinition = obj.Definition For x = 4 To modeldef.WorkAxes.Count Call obj.CreateGeometryProxy(modeldef.WorkAxes.Item(x), oAxis) oAxis.Visible = True oAxis.AutoResize = True Next ElseIf doc.SubType = "{E60F81E1-49B3-11D0-93C3-7E0706000000}" Then 'assembly Dim modeldef As AssemblyComponentDefinition = obj.Definition For x = 4 To modeldef.WorkAxes.Count Call obj.CreateGeometryProxy(modeldef.WorkAxes.Item(x), oAxis) oAxis.Visible = True oAxis.AutoResize = True Next ElseIf doc.SubType = "{28EC8354-9024-440F-A8A2-0E0E55D635B0}" Then 'weldment Dim modeldef As AssemblyComponentDefinition = obj.Definition For x = 1 To (modeldef.WorkAxes.Count - 3) Call obj.CreateGeometryProxy(modeldef.WorkAxes.Item(x), oAxis) oAxis.Visible = True oAxis.AutoResize = True Next End If x = 0 Next AssyModel.Update() Else MessageBox.Show("No selections made. Please select components and try again.", "Selection", MessageBoxButtons.OK) End If End Sub Private Sub UAoff_Click(sender As Object, e As EventArgs) Handles UAoff.Click Dim AssyModel As AssemblyDocument = thisapplication.ActiveDocument Dim AssyModelDef As AssemblyComponentDefinition = AssyModel.ComponentDefinition If AssyModel.SelectSet.Count > 0 Then For Each obj As ComponentOccurrence In AssyModel.SelectSet Dim oAxis As WorkAxisProxy Dim x As Integer Dim doc As Document = obj.ReferencedDocumentDescriptor.ReferencedDocument If doc.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Or doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'part or sheetmetal Dim modeldef As PartComponentDefinition = obj.Definition For x = 4 To modeldef.WorkAxes.Count Call obj.CreateGeometryProxy(modeldef.WorkAxes.Item(x), oAxis) oAxis.Visible = False Next ElseIf doc.SubType = "{E60F81E1-49B3-11D0-93C3-7E0706000000}" Then 'assembly Dim modeldef As AssemblyComponentDefinition = obj.Definition For x = 4 To modeldef.WorkAxes.Count Call obj.CreateGeometryProxy(modeldef.WorkAxes.Item(x), oAxis) oAxis.Visible = False Next ElseIf doc.SubType = "{28EC8354-9024-440F-A8A2-0E0E55D635B0}" Then 'weldment Dim modeldef As AssemblyComponentDefinition = obj.Definition For x = 1 To (modeldef.WorkAxes.Count - 3) Call obj.CreateGeometryProxy(modeldef.WorkAxes.Item(x), oAxis) oAxis.Visible = False Next End If x = 0 Next AssyModel.Update() Else MessageBox.Show("No selections made. Please select components and try again.", "Selection", MessageBoxButtons.OK) End If End Sub Private Sub cbALL_CheckedChanged(sender As Object, e As EventArgs) Handles cbALL.CheckedChanged If cbALL.Checked Then UserWF.Visible = False Origin.Text = "Origin/User" Else UserWF.Visible = True Origin.Text = "Origin" End If End Sub End Class
Inventor Professional 2018.3.3
Vault Basic 2018
Visual Studio 2015
Solved! Go to Solution.