Programmatically Manage\Insert\Derive

Programmatically Manage\Insert\Derive

pierluigi.gulmini
Participant Participant
254 Views
1 Reply
Message 1 of 2

Programmatically Manage\Insert\Derive

pierluigi.gulmini
Participant
Participant

Hi,

I'm having troubles inserting an existing part or assembly into a new part (programmatically) with Derive option.

By using Inventor, to create a derived part you have to create a new part from scratch and then Manage\Insert\Derive.

 

I implemented the code below and it seems working fine to me, but it doesn't open the 'Derived Part' form:

pierluigigulmini_1-1652093979402.png 

 

bool InsertNotInteractiveDerived(const std::string filePath, const std::string extension)
{
bool res = false;
CComPtr<Document> pInvDoc = m_InvenApp->ActiveDocument;
CComQIPtr<PartDocument> pPartDoc(pInvDoc);
if (pPartDoc != NULL)
{
res = true;
_bstr_t bstrFilePath(filePath.c_str());
CComPtr<PartComponentDefinition> pPartCompDef = pPartDoc->ComponentDefinition;
CComPtr<ReferenceComponents> pRefComponents = pPartCompDef->ReferenceComponents;
if (extension == ".ipt")
{
HRESULT hres = S_OK;
CComPtr<DerivedPartComponents> pDerPartComponents = pRefComponents->DerivedPartComponents;
CComPtr<DerivedPartUniformScaleDef> pDerivedParUniformScaletDef = pDerPartComponents->CreateDefinition(bstrFilePath);
CComPtr<DerivedPartDefinition> pDerivedParDef;
hres = pDerivedParUniformScaletDef->QueryInterface(&pDerivedParDef);
if (FAILED(hres))
return false;
CComPtr<DerivedPartComponent> pDerPartComp = pPartDoc->ComponentDefinition->ReferenceComponents->DerivedPartComponents->Add(pDerivedParDef);
}
else
{
CComPtr<DerivedAssemblyComponents> pDerAssyComponents = pRefComponents->DerivedAssemblyComponents;
CComPtr<DerivedAssemblyDefinition> pDerivedAssyDef = pDerAssyComponents->CreateDefinition(bstrFilePath);
CComPtr<DerivedAssemblyComponent> pDerAssyComp = pPartDoc->ComponentDefinition->ReferenceComponents->DerivedAssemblyComponents->Add(pDerivedAssyDef);
}
}

return res;
}

 

What should I do for opening the 'Derived Part' form?
T&R

PS: I'm developing my application in C++, but also VBA answers will be fine (I'll try to convert them to C++ later) .

0 Likes
Accepted solutions (1)
255 Views
1 Reply
Reply (1)
Message 2 of 2

pierluigi.gulmini
Participant
Participant
Accepted solution

Ok, the solution is:

 

bool PlaceComponentCmd(const _variant_t fileName)
{
CComPtr<CommandManager> cmdMnager = m_InvenApp->CommandManager;
HRESULT hres = cmdMnager->PostPrivateEvent(kFileNameEvent, fileName);
if (FAILED(hres))
return EditorError;

CComPtr <ControlDefinitions> pCntrlDefs = cmdMnager->GetControlDefinitions();
std::string itemString = "PartDerivedComponentCmd"; // "AssemblyPlaceComponentCmd";
_bstr_t itemName(itemString.c_str());
_variant_t itemFromControlDef = itemName;

CComPtr <ControlDefinition> pCntrolDef = pCntrlDefs->GetItem(itemFromControlDef);

hres = pCntrolDef->Execute();
return hres == S_OK;
}

 

Cheers

0 Likes