How-To: Copy a part and mirror it

In this article we’ll see how to:

  • Duplicate a Product Occurrence
  • Apply a matrix to mirror a part
  • Export the model containing the original part and it’s mirrored copy

Instructions

  • You can copy an entity using the method A3DAsmProductOccurrenceDeepCopy
  • You can mirror a part by adding a Scale transformation with a negative value
sHoopsExchangeLoader.Import(sImport);

	A3DAsmModelFileData sdata;
	A3D_INITIALIZE_DATA(A3DAsmModelFileData, sdata);
	A3DAsmModelFileGet(sHoopsExchangeLoader.m_psModelFile, &sdata);

	//copy PO;
	A3DAsmProductOccurrence* rootPo = sdata.m_ppPOccurrences[0];
	A3DAsmProductOccurrence* rootPoCpy;
	A3DAsmProductOccurrenceDeepCopy(sdata.m_ppPOccurrences[0], &rootPoCpy);

	//edit poroot
	A3DAsmProductOccurrenceData pocopydata;
	A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, pocopydata);
	A3DAsmProductOccurrenceGet(rootPoCpy, &pocopydata);

	//location to mirror 
	A3DMiscCartesianTransformation* newLocation = pocopydata.m_pLocation;
	A3DMiscCartesianTransformationData newLocationData;
	A3D_INITIALIZE_DATA(A3DMiscCartesianTransformationData, newLocationData);

	newLocationData.m_sScale.m_dX = 1;
	newLocationData.m_sScale.m_dY = 1;
	newLocationData.m_sScale.m_dZ = -1;

	newLocationData.m_sXVector.m_dX = 1.0;
	newLocationData.m_sXVector.m_dY = 0.0;
	newLocationData.m_sXVector.m_dZ = 0.0;

	newLocationData.m_sYVector.m_dX = 0.0;
	newLocationData.m_sYVector.m_dY = 1.0;
	newLocationData.m_sYVector.m_dZ = 0.0;
	newLocationData.m_ucBehaviour = kA3DTransformationScale;

	A3DMiscCartesianTransformationCreate(&newLocationData, &newLocation);

	// populating the PO Data Structure with the location
	pocopydata.m_pLocation = newLocation;

	A3DAsmProductOccurrenceEdit(&pocopydata, rootPoCpy);
	
	sdata.m_uiPOccurrencesSize++;
	sdata.m_ppPOccurrences = new A3DAsmProductOccurrence*[2];
	sdata.m_ppPOccurrences[0] = rootPo;
	sdata.m_ppPOccurrences[1] = rootPoCpy;

	A3DAsmModelFileCreate(&sdata, &sHoopsExchangeLoader.m_psModelFile);

	sHoopsExchangeLoader.Export(sExport);

Documentation for transformation matrix: Cartesian Transformation — HOOPS Exchange 2023 documentation