Page 1 of 1

Copy objects

Posted: Mon Jul 22, 2024 5:12 am
by Cara Delevingne
Hello!

I have STEP file. I am working in C#. I am trying to modify Selection sample. I need to save selected object(s) and the paste in different coordinates. The new location will be defined with a click.

I can select some objects. How can I implement the copying?

Thanks

Re: Copy objects

Posted: Wed Jul 24, 2024 1:56 am
by gerard12
Hi Cara

It is not hard. Have a look at the Selection sample. SelectionForm.OnSelection() > UpdatePageEntities(IList_DG iList) shows handling of object(s) selection by the user. See also: Selection.

You need to add something like (C#):

Code: Select all

IEntity_DG iEntityNew = iEntity.Clone();
IFrame_DG frame = iEntityNew.GetLocation();
VectDg vectBy;
// .... compute vectBy
frame.TranslateGlobal(vectBy);
Translate is little better here because you need to change the position along the screen and leave the same distance to the viewer.

Computing vectBy:

Code: Select all

IView_DG view = dgk.GetView();
PairIntDg positionPxBefore = view.ProjectToScreen(frame.Origin);
PairIntDg positionPxNewscreenLocation;		// User input for the new location
PairIntDg offsetPx = new PairIntDg(positionPxNewscreenLocation.first - positionPxBefore.first, positionPxNewscreenLocation.second - positionPxBefore.second);
VectDg vectBy = ScreenTo3DVector(offsetPx);	// See below

// This would be good to have in IView_DG
VectDg ScreenTo3DVector(IView_DG view, PairIntDg offsetPx)
{
	PointDg pt0 = view.ScreenTo3D(0, 0);
	PointDg pt1 = view.ScreenTo3D(offsetPx.first, offsetPx.second);
	return pt0.GetOffsetVector(pt1);
}