Run Half Section View Command in Assembly through API

By Barbara Han

Issue
I would like to run the Half Section View command from the Inventor assembly. If this is no direct API, how can I find the command and run it from the API?
Solution

First of all, you may want to know what command in API world is for “Half Section View” command in UI. You can get all commands’ information using below several lines of VBA code:

Sub printCmdInfo()
    Dim oControlDef As ControlDefinition
    Open "c:\1.txt" For Output As #1
    Dim s As String
   
    For Each oControlDef In ThisApplication.CommandManager. _
    ControlDefinitions
        s = oControlDef.InternalName & ":" & _
        oControlDef.DescriptionText
        Write #1, s
    Next
    Close #1
End Sub

Open the C:\1.txt file created by above code, you can find the name for the Half Section View command in Assembly environment is “AssemblyHalfSectionViewCmd”.

If you have a plane selected before running above line, there will be no user interaction needed when you executing above line. If this is not the case, you can select a work plane via API too, for example:

Dim assm As AssemblyDocument
Set assm = ThisApplication.ActiveDocument
ThisApplication.ActiveDocument.SelectSet.Select assm.ComponentDefinition.WorkPlanes.Item(4)

Then you can call this command programmatically like this:

ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyHalfSectionViewCmd").Execute

The Offset dialog will pop up after calling above line of code, you can set a value in the Offset dialog then exit it by SendKeys method, for example:

SendKeys "0.02"
SendKeys "{ENTER}"


Comments

2 responses to “Run Half Section View Command in Assembly through API”

  1. Klaas De Smedt Avatar
    Klaas De Smedt

    This is exactly what i was looking for, many thanks!

  2. Klaas De Smedt Avatar
    Klaas De Smedt

    SendKeys does not work on my configuration:
    – Windows 7 – 64 bit
    – Inventor 2012 – 64 bit
    Could it be that sendKeys not works in Windows 7?
    Or because of the 64 bit Inventor?
    Is there an alternative that can be used?

Leave a Reply to Klaas De SmedtCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading