Making Sub Assembly Planes Visible in an Assembly

Making Sub Assembly Planes Visible in an Assembly

zachary.watsonTTAEZ
Participant Participant
661 Views
3 Replies
Message 1 of 4

Making Sub Assembly Planes Visible in an Assembly

zachary.watsonTTAEZ
Participant
Participant

Hi there,

 

I was looking to make a macro using inventor VBA in which I can select a part or subassembly in a part, toggle the macro, and all the work planes for that part become visible. I am having a hard time finding the right field in which the selected parts plane visibility is located in the inventor object tree. Could anyone help point me in the right direction?

 

Thanks!

0 Likes
Accepted solutions (1)
662 Views
3 Replies
Replies (3)
Message 2 of 4

Andrii_Humeniuk
Advisor
Advisor

Hello. Please try this code:

 

Dim oDoc As Document = ThisApplication.ActiveDocument
If TypeOf oDoc Is AssemblyDocument Then
	Dim oAssDoc As AssemblyDocument = oDoc
	Dim oComp As ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, _
		"Select component...(Press ESC to cancel)")
	If oComp Is Nothing Then Exit Sub
	Dim oCompDef As ComponentDefinition = oComp.Definition
	oCompDef.WorkPlanes.Item(1).Visible = True
	oCompDef.WorkPlanes.Item(2).Visible = True
	oCompDef.WorkPlanes.Item(3).Visible = True
Else
	MessageBox.Show("Active document is not AssemblyDocument.", "Error!",MessageBoxButtons.OK,MessageBoxIcon.Error)
End If

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 3 of 4

WCrihfield
Mentor
Mentor
Accepted solution

Hi @zachary.watsonTTAEZ.  If you are wanting a VBA macro that you can run, where you can either pre-select an assembly component, or select the component after you run the macro, then turn all of that components WorkPlanes on, then the VBA code below should work OK for you.  Your wording was a little difficult to understand though, so I was not sure if the component that you select may actually represent a sub assembly itself.  If that is the case, then you will want to change the selection filter from "kAssemblyLeafOccurrenceFilter" to "kAssemblyOccurrenceFilter", because the 'Leaf' version will only allow you to select components that represent parts, not assemblies, but it will also allow you to select components that are down within other components that represent sub assemblies.

Sub PickCompTurnOnWPlanes()
    If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then
        Call MsgBox("An Assembly must be 'Active' to use this Macro.", vbCritical, "")
        Exit Sub
    End If
    Dim oADoc As AssemblyDocument
    Set oADoc = ThisApplication.ActiveDocument
    Dim oOcc As ComponentOccurrence
    If oADoc.SelectSet.Count > 0 Then
        If TypeOf oADoc.SelectSet.Item(1) Is ComponentOccurrence Then
            Set oOcc = oADoc.SelectSet.Item(1)
        End If
    End If
    If oOcc Is Nothing Then
        Set oOcc = ThisApplication.CommandManager.Pick(kAssemblyLeafOccurrenceFilter, "Select a component.")
    End If
    If oOcc Is Nothing Then Exit Sub
    If oOcc.Suppressed Then Exit Sub
    Dim oWPlanes As WorkPlanes
    Set oWPlanes = oOcc.Definition.WorkPlanes
    Dim oWPlane As WorkPlane
    For Each oWPlane In oWPlanes
        If oWPlane.Visible = False Then oWPlane.Visible = True
    Next
    Call oADoc.Update2(True)
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 4

zachary.watsonTTAEZ
Participant
Participant

Thanks for the help guys! Both of these options work in their own way and helped get me off the ground to get this macro moving.

0 Likes