is it posible to provide "OK" click to a native minitoolbar through API ?

is it posible to provide "OK" click to a native minitoolbar through API ?

liminma8458
Collaborator Collaborator
1,462 Views
13 Replies
Message 1 of 14

is it posible to provide "OK" click to a native minitoolbar through API ?

liminma8458
Collaborator
Collaborator

Hi, everyone,

I have an application scenario: in an assembly, "create in-place part", then create a workplane in the new part, based on the circular face on the other part in the same assembly.

 

In API help file, it states "WorkPlanes.AddByPlaneAndOffset Method" is not currently supported when creating a work plane within an assembly; and I don't want to use "WorkPlanes.AddFixed Method" either. The new workplane has to be adaptive. (what else method you can create an adaptive workplane in a part based on other part in an assembly?).

 

So I try the workaround to use native command of "PartPlanarPlaneWorkPlaneCmd", something like:

Set oface_assy_proxy = ThisApplication.CommandManager.Pick(...)

oSelectSet.Select oface_assy_proxy
Set odef = ThisApplication.CommandManager.ControlDefinitions.Item("PartPlanarPlaneWorkPlaneCmd")
Call odef.Execute2(True)

 

It works by using selectset to provide the native command with the referencing face. Then the minitoolbar appears,  is it possible to provide the OK click through API by default and the minitoolbar will not show at all ? (ThisApplication.SilentOperation = True has no effect in this case)

 

Capture5.PNG

 

 

 

Thanks
Limin
Inventor pro 2023 64 bit update 5.3; Windows 11 pro 64 bit version 24H2; Office 2013 64 bit

Download iCable in App Store to Create Cables Easily

0 Likes
Accepted solutions (1)
1,463 Views
13 Replies
Replies (13)
Message 2 of 14

WCrihfield
Mentor
Mentor

Judging by your use of "Set", you must be using VBA.

Since you're already familiar with using executing commands, here's a couple more for you.

See if these commands will work here for you.

AppContextual_OKCmd

AppContextual_DoneCmd

AppContextual_ApplyCmd

AppContextual_ContinueCmd

AppContinueCmd

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 14

liminma8458
Collaborator
Collaborator

WCrihfield,

I try:

Call ThisApplication.CommandManager.ControlDefinitions.Item("AppContextual_OKCmd").Execute

and all other options on your list. They don't work out. The minibusbar still shows up.

 

Thank you for the suggestion

Thanks
Limin
Inventor pro 2023 64 bit update 5.3; Windows 11 pro 64 bit version 24H2; Office 2013 64 bit

Download iCable in App Store to Create Cables Easily

Message 4 of 14

liminma8458
Collaborator
Collaborator

I mean the minitoolbar dialog still shows up and I have to click OK to finish.

Thanks
Limin
Inventor pro 2023 64 bit update 5.3; Windows 11 pro 64 bit version 24H2; Office 2013 64 bit

Download iCable in App Store to Create Cables Easily

0 Likes
Message 5 of 14

WCrihfield
Mentor
Mentor

OK. You will need to add the plane by regular code, instead of by executing commands.

Try this, as an example:

 

Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select a planar (flat) face to create a plane on.")
Dim oPlane As WorkPlane = oPDef.WorkPlanes.AddByPlaneAndOffset(oFace,0,False)

Oops. You need to create a WorkPlaneProxy inside of an assembly, not just a WorkPlane in a Part.

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 14

J-Camper
Advisor
Advisor

I've tried to do a similar thing before.  The issue with the commands is it won't call the next command until you finish the first.

 

There is a dirty work around which was brought up to me when I had a similar question about using commands, where you run a second thread to hit OK after a timer.  I abandoned the idea because I didn't like arbitrarily hitting OK after x time has passed.  It isn't a reliable way to do it because of varying computer speeds and other users' not being prompt enough to progress to the OK command before x time is passed.

 

Here is my post with the sample thread:

Message 2 in Thread 

0 Likes
Message 7 of 14

WCrihfield
Mentor
Mentor

Try this instead.

Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oFace As FaceProxy = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select a planar (flat) face to create a plane on.")
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oUVX As UnitVector = oTG.CreateUnitVector(1, 0, 0)
Dim oUVY As UnitVector = oTG.CreateUnitVector(0, 1, 0)
oADef.WorkPlanes.AddFixed(oFace.PointOnFace,oUVX,oUVY,False)

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 14

WCrihfield
Mentor
Mentor

That was the iLogic way.

This is the VBA way.

(Pesky 'Set' & new line stuff you have to deal with in VBA.) 😒

Dim oADoc As AssemblyDocument
Set oADoc = ThisApplication.ActiveDocument
Dim oADef As AssemblyComponentDefinition
Set oADef = oADoc.ComponentDefinition
Dim oFace As FaceProxy
Set oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select a planar (flat) face to create a plane on.")
Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry
Dim oUVX As UnitVector
Set oUVX = oTG.CreateUnitVector(1, 0, 0)
Dim oUVY As UnitVector
Set oUVY = oTG.CreateUnitVector(0, 1, 0)
oADef.WorkPlanes.AddFixed(oFace.PointOnFace,oUVX,oUVY,False)

  

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 9 of 14

liminma8458
Collaborator
Collaborator

My purpose is to create an part in an assembly, in which an Adaptive plane of the part is based on a circular face on another part in the assembly.  So the plane will follow if the circular face moves in the assembly.  WorkPlanes.AddByPlaneAndOffset method does not work in assembly; WorkPlanes.AddFixed Method works in assembly but the generated plane is not adaptive.

 

So I use a workaround to execute a native Inventor command ("PartPlanarPlaneWorkPlaneCmd")  through API. It works and only problem is I don't want the minitoolbar dialog to pop up. Instead, I want to accept "OK" by default in background and run through it.

 

I tried JCamper's method (SendKeys.Sendwait...). The dialog blinks for 1 second then go. It is better, but is there any way to make it no show at all?

 

The following is the code, and the models attached. Open the assembly then run the code you will see what I am looking for. Thanks everyone.

 

Public Sub create_workplane_from_assy_by_pick_faceproxy()

        Try

            ' Get the active document. This is an assembly.

            Dim oAsmDoc As AssemblyDocument

            oAsmDoc = ThisApplication.ActiveDocument

 

            ' Get a reference to the ComponentOccurrences collection.

            Dim oOccs As ComponentOccurrences

            oOccs = oAsmDoc.ComponentDefinition.Occurrences

 

            ' Create a part to insert. This creates the document

            ' invisibly so the end-user doesn't see anything happen.

            Dim oNewPartDoc As PartDocument

            oNewPartDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject,

    ThisApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject), False)

 

            ' Insert this part into the assembly automatically.

            'Just like the UI command "Create Component" (Create In-Place Component) under Assembly tab

            Dim oOcc As ComponentOccurrence

            oOcc = oOccs.AddByComponentDefinition(oNewPartDoc.ComponentDefinition,

    ThisApplication.TransientGeometry.CreateMatrix)

 

            'get into part in assembly mode to create an ADAPTIVE workplane in the part

            oOcc.Edit()

 

            Dim oSelectSet As SelectSet

            oSelectSet = oAsmDoc.SelectSet

            oSelectSet.Clear()

 

            Dim oface_assy_proxy As FaceProxy

 

            'Call the Pick method and set the filter to pick a planer face.

            oface_assy_proxy = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick a planar face")

            'kPartFacePlanarFilter

 

            oSelectSet.Select(oface_assy_proxy)

            Dim odef As Inventor.ButtonDefinition

 

            odef = ThisApplication.CommandManager.ControlDefinitions.Item("PartPlanarPlaneWorkPlaneCmd")

 

            Call odef.Execute2(True)  'will wait till pick finishes

 

            'not work. you still need click OK in the UI

            'ThisApplication.CommandManager.ControlDefinitions.Item("AppContextual_OKCmd").Execute2()

            'ThisApplication.CommandManager.ControlDefinitions.Item("AppContextual_DoneCmd").Execute()

            'ThisApplication.CommandManager.ControlDefinitions.Item("AppContextual_ApplyCmd").Execute()

            'ThisApplication.CommandManager.ControlDefinitions.Item("AppContinueCmd").Execute()

            'ThisApplication.CommandManager.ControlDefinitions.Item("AppContextual_ContinueCmd").Execute

 

            oOcc.ExitEdit(ExitTypeEnum.kExitToParent)

    End Sub

 

Thanks
Limin
Inventor pro 2023 64 bit update 5.3; Windows 11 pro 64 bit version 24H2; Office 2013 64 bit

Download iCable in App Store to Create Cables Easily

0 Likes
Message 10 of 14

J-Camper
Advisor
Advisor

If that's all you want to do, you can create a part template file with an adaptive plane in it.  Place that part template instead of blank template, set the occurrence to adaptive, and constrain in place.

0 Likes
Message 11 of 14

liminma8458
Collaborator
Collaborator

JCamper,

 

This is exactly what I did before. But the new way discussed above looks better fit our new process and specific need. If doable, it also open a door for many native inventor commands to be used directly in programming in a similar way, saving coding time.

 

Thanks again

Thanks
Limin
Inventor pro 2023 64 bit update 5.3; Windows 11 pro 64 bit version 24H2; Office 2013 64 bit

Download iCable in App Store to Create Cables Easily

0 Likes
Message 12 of 14

J-Camper
Advisor
Advisor

You will have to use separate threading to automate completion of those commands, the next line of code will not trigger until the previously called command is finished.  There may be a better way to synchronize threads, other than a timed key send, but I couldn't find anything useful when I was looking for a solution. 

 

The only other thing I can tell you is to make and Idea Post [Inventor Ideas Forum] about Expanding the Functionality of WorkPlanes Methods to work in Assemblies.  With enough support Autodesk might make it happen, and that would be the best way to accomplish that task through API.

0 Likes
Message 13 of 14

WCrihfield
Mentor
Mentor

FYI:

When you activate the oOcc.Edit(), that's what is making the dialog/mini-toolbar pop-up.  When you do that, is is expecting manual user interaction with the user interface, instead of by code, until you use the oOcc.ExitEdit.  The same goes for sketches.  When you activate the oSketch.Edit, it then is then expecting manual interaction, until you use the oSketch.ExitEdit.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 14 of 14

liminma8458
Collaborator
Collaborator
Accepted solution

I make a minor change from message 2 of https://forums.autodesk.com/t5/inventor-customization/ilogic-interact-with-dialog-box-and-or-help-co...

Threading.Thread.Sleep(10)

This will create an acceptable workaround at this moment which only have very short blink of dialog.

 

Thanks everyone

Thanks
Limin
Inventor pro 2023 64 bit update 5.3; Windows 11 pro 64 bit version 24H2; Office 2013 64 bit

Download iCable in App Store to Create Cables Easily

0 Likes