c# insert ipt in assembly - user interaction

c# insert ipt in assembly - user interaction

Christian_1976
Enthusiast Enthusiast
879 Views
2 Replies
Message 1 of 3

c# insert ipt in assembly - user interaction

Christian_1976
Enthusiast
Enthusiast

Good morning everyone,
i'm rewriting in c# some of my very old tools written years ago in vba.

(Doing that using Inventor 2017 and visual studio 2015 )

I'm going quite well with the rewriting but i'm locked with inserting an ipt into an assembly giving to the user the opportunity to choose the displacing point.
(I can add component by adding it to the assembly document ComponentOccurrences, but no user interaction)

In Vba, the way that i used was calling Command manager like this:
Call ThisApplication.CommandManager.PostPrivateEvent(kFileNameEvent, sFile)
Call ThisApplication.CommandManager.StartCommand(kPlaceComponentCommand)

now i'm doing this:
m_InventorApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, sFile);
I can't find in CommandManager something that can replace the StartCommand.
I see in the api doc that there is a CreateDragContext as CommandManager method

I want to ask if:
-anybody knows if however is the right way to give to the user the control of where to place the new component in the assembly
-anybody knows how to do that in c#

 

thank you in advance

Christian

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

ekinsb
Alumni
Alumni
Accepted solution

What you've run into isn't a change from VBA to C# but is a change that was made in the API quite a while ago.  The StartCommand method has been retired.  You can still accomplish the same thing by first getting the CommandDefinition that represents the command and then executing it.  Below os some sample code that demonstrates what you're trying to do.

 

string filename = "C:/Temp/Tests/EllipsePart.ipt";

// Post the filename to the private event queue. 
invApp.CommandManager.PostPrivateEvent(Inventor.PrivateEventTypeEnum.kFileNameEvent, filename);

// Get the control definition for the Place Component command.
Inventor.ControlDefinition ctrlDef = invApp.CommandManager.ControlDefinitions["AssemblyPlaceComponentCmd"];

// Execute the command. 
ctrlDef.Execute();

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 3

Christian_1976
Enthusiast
Enthusiast

I'm deeply sorry to answer you only now, after a so long time, but i had to stop suddenly my task and i'm now review it all.

Your solution works, thank you a lot.

🙂

0 Likes