What's new

INSERT IN AN ASSEMBLY AN EXISTING PART OR ASSEMBLY

eendrigo

Member
INSERT IN AN ASSEMBLY AN EXISTING PART OR ASSEMBLY

Hi all,

Loock at the following code :

void CPartInsertAndAssemblySaveDlg::InsertAssembly()
{


IADSessionsPtr iSessions = NULL;

// Get all the open sessions in Alibre.

iSessions = m_pRoot->GetSessions ();

IADSessionPtr iSession = NULL;

iSession = iSessions->Item ((long)0);

IADAssemblySessionPtr assySession = NULL;


iSession->QueryInterface (&assySession);


IADOccurrencePtr rootOccurrence = NULL;

// Get the root of the assembly tree in the open session.

rootOccurrence = assySession->GetRootOccurrence ();

IADOccurrencesPtr occurrences = NULL;

// Get all the occurrences under the root occurrence.

occurrences = rootOccurrence->GetOccurrences ();

IADGeometryFactoryPtr geomFactory = NULL;

// Get the geometry factory from the session. This factory will be used to create
// a tranform which can be used to place a part inside the assembly.

geomFactory = iSession->GetGeometryFactory ();


IADTransformationPtr transf = NULL;

// Create a Identity transform for the part.

transf = geomFactory->CreateIdentityTransform ();

CString partName = CString ("BlockWithHole");
IADOccurrencePtr partOccurrence = NULL;
partOccurrence = occurrences->AddEmptyAssembly( partName.AllocSysString (), transf);

////

CString StrFilePath = "D:\\\\Alibre\\\\New Assembly (1).AD_ASM";

IADDesignSessionPtr objKettlePart;
objKettlePart=m_pRoot->OpenFile( StrFilePath.AllocSysString());

/// occurrences->Add( (VARIANT)objKettlePart, transf); ASSERT ???


}

I'ed modified the sample CPartInsertAndAssemblySaveDlg for adding an existing part-assembly bu the occurrences->Add( (VARIANT)objKettlePart, transf); instruction assert. I found the example in API's HELP in VB. Have I misundertood ? If I comment the instruction a new session is correctly opened displaing "D:\\\\Alibre\\\\New Assembly (1).AD_ASM".

Any suggestion ?

Ezio

:roll:
 

shubhab

Member


Hi Ezio,

This should work. You should be able to insert an existing part/ subassembly to a main assembly.

I am sure, you must have done this. But just trying to rule out some simple things first:
You have assigned occurrences->Add( (VARIANT)objKettlePart, transf) to an instance of IADOccurrence I believe. i.e.

partOccurrence = occurrences->Add( (VARIANT)objKettlePart, transf);

Thanks,
Shubha,
Alibre, Inc.
 

eendrigo

Member


Hi Shubha,

I found my solution. Here is :

VARIANT vtPart;
VariantInit (&vtPart);
index.vt = VT_LPSTR;

index.bstrVal = "C:\\\\ALIBRE\\\\EZIO\\\\AAA.AD_PRT";
iOccurences->Add( vtPart, transf);

This works fine.

I realized the drive name ( C:) must provide otherwise the instruction asserts :

index.bstrVal = "\\\\ALIBRE\\\\EZIO\\\\AAA.AD_PRT";
iOccurences->Add( vtPart, transf);

crash;

Thankyou.

Ezio

:wink:
 
Top