inventor好像没有全部显示的功能,在大型部件中,如果隐藏一个零件,往往要找很久才能显示回来。有谁能帮忙写一个ilogic程序实现此功能。API函数中有一个CreateVisibleOccurrenceFinder我发现只能准确找出显示部件,用来找隐藏部件好像不是很准确。下面是我目前用的一个很笨的方法,将所有部件全部操作一遍,此程序运行较慢,不太适合。
For Each occ As Object In Thisapplication.activedocument.componentdefinition.occurrences
occ.visible = False ,必须先隐藏再显示
occ.visible = True
Next
已解决! 转到解答。
点“全部可见”后确实当前部件的用户工作平面会全部可见,我也不清楚用inventor如何设置,如果你愿意用ilogic隐藏,以下是ilogic代码:
If ThisApplication.ActiveDocumentType <> Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then Exit Sub
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
On Error Resume Next
For Each TopPlane As Inventor.WorkPlane In oAsmDoc.ComponentDefinition.WorkPlanes
TopPlane.Visible = False
Next
For Each TopAxies As Inventor.WorkAxis In oAsmDoc.ComponentDefinition.WorkAxes
TopAxies.Visible = False
Next
这里我想提一个问题@smilinger,inventor当创建新工作平面的时候,很多工作平面就会显示出来,我知道inventor2022已经对这个问题作出了改进。之前版本仅仅靠对象可见性并不能真正的隐藏工作平面。之所以提出这个问题是因为很多工程师画图的时候在零件层级不愿意隐藏工作平面,而仅仅在装配体中关闭对象可见性。我写了一段ilogic程序想在总装配体中一次解决所有平面真正隐藏的问题,但是发现还是有个别平面无法被隐藏,这个问题一直很让我头疼。不过我注意到当视图表达被锁定的时候不能对可见性作出任何更改,不知道是不是这个问题。以下是我的代码:
Sub main()
If ThisApplication.ActiveDocumentType <> Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then Exit Sub
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
On Error Resume Next
For Each TopPlane As Inventor.WorkPlane In oAsmDoc.ComponentDefinition.WorkPlanes
TopPlane.Visible = False
Next
For Each TopAxies As Inventor.WorkAxis In oAsmDoc.ComponentDefinition.WorkAxes
TopAxies.Visible = False
Next
Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document
For Each oRefDoc In oRefDocs
'隐藏工作面WorkPlanes
For Each oPlane As Inventor.WorkPlane In oRefDoc.ComponentDefinition.WorkPlanes
oPlane.Visible = False
Next
'隐藏工作轴WorkAxes
For Each oAxe As Inventor.WorkAxis In oRefDoc.ComponentDefinition.WorkAxes
oAxe.Visible = False
Next
Next
RUsure = MessageBox.Show ( _
"如存在可见平面请继续执行隐藏:" _
& vbLf & "点击 '是' 继续隐藏" _
& vbLf & "点击 '否' 退出程序","iLogic - WorkPlanehide",MessageBoxButtons.YesNo)
If RUsure = vbNo Then
Return
Else
End If
For Each occ As Inventor.ComponentOccurrence In oAsmDoc.ComponentDefinition.Occurrences
Call Occ_hide(occ)
Next
For Each Asmdoc As Inventor.AssemblyDocument In ThisApplication.ActiveDocument.AllreferencedDocuments.OfType(Of Inventor.AssemblyDocument)
Call Document_hide(Asmdoc)
Next
Call Document_hide(oAsmDoc)
RUsure = MessageBox.Show ( _
"如存在可见平面请继续执行隐藏:" _
& vbLf & "点击 '是' 继续隐藏" _
& vbLf & "点击 '否' 退出程序","iLogic - WorkPlanehide",MessageBoxButtons.YesNo)
If RUsure = vbNo Then
Return
Else
End If
Call Subocc_hide(oAsmDoc.ComponentDefinition.Occurrences)
End Sub
Private Sub Document_hide(oAscDocument As Inventor.AssemblyDocument)
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oAscDocument.ComponentDefinition
Dim oOcc As ComponentOccurrence
For Each oOcc In oAsmCompDef.Occurrences
Dim oPlane As WorkPlane
For Each oPlane In oOcc.Definition.WorkPlanes
Dim oProxyPlane As WorkPlaneProxy
Call oOcc.CreateGeometryProxy(oPlane, oProxyPlane)
oProxyPlane.Visible =False
Next
Dim oworkaxe As Inventor.WorkAxis
For Each oworkaxis In oOcc.Definition.workaxes
Dim oproxyworkaxis As Inventor.WorkAxisProxy
Call oOcc.CreateGeometryProxy(oworkaxis, oproxyworkaxis)
oproxyworkaxis.Visible =False
Next
Next
End Sub
Private Sub Occ_hide(occ As Inventor.ComponentOccurrence)
Dim oworkplane As WorkPlane
Dim oProxyPlane As WorkPlaneProxy
For Each oworkplane In occ.Definition.workplanes
Call occ.CreateGeometryProxy(oworkplane, oProxyPlane)
oProxyPlane.Visible =False
Next
Dim oworkaxis As WorkAxis
Dim oproxyworkaxis As WorkAxisProxy
For Each oworkaxis In occ.Definition.workaxes
Call occ.CreateGeometryProxy(oworkaxis, oproxyworkaxis)
oproxyworkaxis.Visible =False
Next
End Sub
Private Sub Subocc_hide(occs As Inventor.ComponentOccurrences)
For Each occ As Inventor.ComponentOccurrence In occs
Call Occ_hide(occ)
If Not occ.SubOccurrences Is Nothing Then
Call Subocc_hide(occ.SubOccurrences)
End If
Next
End Sub
把ilogic规则前面加个if条件语句判断一下就可以了,改成如下:
Dim occ As Inventor.ComponentOccurrence For Each occ In Thisapplication.activedocument.componentdefinition.occurrences If occ.visible = False Then occ.visible = True End If Next
我也是头疼了很久,而且这些平面在所有视图(view)中都显示,还有一旦创建view后,新添加的零件在所有视图以及工程图中都会显示,做大型的项目,创建view后新增加的零件需要每个view再把新增加的零件隐藏掉才不会再之前已经做好的工程图中显示出来。非常头疼。
没想到我之前发的帖子已经有7000多浏览量,看来很多人还是需要这个功能,这里我补充一下ilogic的实现方法,进去视图点击右键还是稍微麻烦了一点,下面的ilogic设置外部规则自动运行后只要在窗口空白处点击右键就有这个功能
Class ThisRule
Sub main
If SharedVariable.Exists("ShowAll") Then Return
SharedVariable("ShowAll") = "ShowAll"
Dim mybutton As New MyButton(ThisApplication)
End Sub
End Class
Public Class MyButton
Private button_showall As ButtonDefinition
Private ThisApplication As Inventor.Application
Public Sub New(ThisApplication As Inventor.Application)
Me.ThisApplication = ThisApplication
Me.button_showall = ThisApplication.CommandManager.ControlDefinitions.AddButtonDefinition(
"全部显示",
"IneternalName_showall",
CommandTypesEnum.kShapeEditCmdType)
AddHandler button_showall.OnExecute, AddressOf OnCLick
AddHandler ThisApplication.CommandManager.UserInputEvents.OnContextMenu, AddressOf OnContextMenu
End Sub
Private Sub OnContextMenu(SelectionDevice As SelectionDeviceEnum, AdditionalInfo As NameValueMap, CommandBar As CommandBar)
If (ThisApplication.ActiveDocument.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject) Then Return
If ThisApplication.ActiveDocument.selectset.count <> 0 Then Return
CommandBar.Controls.AddButton(button_showall,2)
End Sub
Private Sub OnCLick
Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument
Dim oAssyDef As AssemblyComponentDefinition
oAssyDef = oAssyDoc.ComponentDefinition
Dim oMgr As RepresentationsManager
oMgr = oAssyDef.RepresentationsManager
Dim oViewRep As DesignViewRepresentation
oViewRep = oMgr.ActiveDesignViewRepresentation
oViewRep.ShowAll
End Sub
End Class