Page 1 of 1

Change UCS

Posted: 11 Jan 2021, 18:32
by AnaCoutinho
Hi CAD VCL forum,

I've been trying to change an entity UCS in Delphi, but it doesn't seem to do what I want.

Before and after changing the UCS I use this command to see if the result changes:
iMatrix := FCADFile.Converter.GetUCS(v2Layout);

For example, changing X direction to Z direction, using the layout:
v2Layout.UCSOrigin := MakeFPoint(0, 0, 0);
v2Layout.UCSXDir := MakeFPoint(0, 0, 1);
v2Layout.UCSYDir := MakeFPoint(1, 0, 0);

When I open the file in AutoCAD the layout is still in WCS.
Since this does not change the directions, I have tried to change de Head vars by:
sgConsts.cnstSGHeadVarStruct.UCSORG := v2Layout.UCSOrigin;
sgConsts.cnstSGHeadVarStruct.UCSXDir := v2Layout.UCSXDir;
sgConsts.cnstSGHeadVarStruct.UCSYDir := v2Layout.UCSYDir;

Another way:
FHeadVarStruct: TsgHeadVarStruct;
FHeadVarStruct.UCSORG := v2Layout.UCSOrigin;
FHeadVarStruct.UCSXDir := v2Layout.UCSXDir;
FHeadVarStruct.UCSYDir := v2Layout.UCSYDir;

Using the rotation matrix:
rMatrix := v2Layout.RotMatrix;
rMatrix.V1[0] := 0;
rMatrix.V1[1] := 0;
rMatrix.V1[2] := 1;
rMatrix.V2[0] := 1;
rMatrix.V2[1] := 0;
rMatrix.V2[2] := 0;
rMatrix.V3[0] := 0;
rMatrix.V3[1] := 1;
rMatrix.V3[2] := 0;
v2Layout.SetRotMatrix(rMatrix);

This rotates the layout, but how can I rotate the UCS?

Thanks for your attention,
Ana

Re: Change UCS

Posted: 13 Jan 2021, 23:15
by support
Hello Ana,

Could you please attach an example AutoCAD file which contains the UCS you want to rotate?

Mikhail

Re: Change UCS

Posted: 14 Jan 2021, 21:34
by AnaCoutinho
Hello Mikhail,

Here's a simple example of an circle.

Thanks for your attention.
Ana

Re: Change UCS

Posted: 26 Jan 2021, 06:50
by support
Hello Ana,

It is possible to change the origin and axis directions for current UCS through the header variables:

Code: Select all

procedure UpdateUCS(AConverter: TsgDXFConverter; AUCSOrg, AUCSXDir, AUCSYDir: TFPoint);
var
  vHeadVarStruct: TsgHeadVarStruct;
begin
  vHeadVarStruct := AConverter.HeadVarStruct;
  vHeadVarStruct.UCSORG := AUCSOrg;
  vHeadVarStruct.UCSXDir := AUCSXDir;
  vHeadVarStruct.UCSYDir := AUCSYDir;
  AConverter.HeadVarStruct := vHeadVarStruct;
end;
The call

Code: Select all

UpdateUCS(FCADFile.Converter, MakeFPoint(100, 100, 0), MakeFPoint(0, 0, 1), MakeFPoint(1, 0, 0));
will give you the attached result.

Re: Change UCS

Posted: 26 Jan 2021, 22:32
by AnaCoutinho
Hello Mikhail,

Thank you for your response.

Is the resulted circle still in the XY plane after calling UpdateUCS?
Is it possible to rotate to another plane?

I'm very grateful for your example.
Best regards,
Ana Coutinho

Re: Change UCS

Posted: 27 Jan 2021, 03:35
by support
Hello Ana,

The circle in your DWG file is not in the XY plane initially, its center has coordinates (25, 25, -1). After calling UpdateUCS coordinates of the center change to (-1, -75, -75). If you open the resulting file in AutoCAD, you will see that the Y axis has X direction and the Z axis has Y direction, thus the current UCS is YZX.

Mikhail

Re: Change UCS

Posted: 27 Jan 2021, 21:56
by AnaCoutinho
ok, thank you very much.
I must have opened the previous file.

Best regards,
Ana