[SOLVED] Compensating "View Origin" differences

[SOLVED] Compensating "View Origin" differences

_CraigF
Contributor Contributor
264 Views
2 Replies
Message 1 of 3

[SOLVED] Compensating "View Origin" differences

_CraigF
Contributor
Contributor

Hi everyone,

I am trying to rotate an element around the project origin point to compensate for the rotation of the plan with respect to true north. This works fine for "new" views, but for original views, the rotation does not seem to occur around the origin point.

 

To investigate the issue, I used RevitLookup and discovered that for original views, the "Origin" property differs depending on whether the view is set to project north or true north. For new views, the origin is always (0,0,z).

 

How can I retrieve the correct origin values for original views in order to perform a translation of my element to account for this difference ?

 

 

ProjectLocation projectLoc = doc.ActiveProjectLocation;
ProjectPosition projectPos = projectLoc.GetProjectPosition(XYZ.Zero);
double northAngle = projectPos.Angle;
XYZ orig = XYZ.Zero;
Line rot = Line.CreateUnbound(orig, XYZ.BasisZ);
ElementTransformUtils.RotateElement(doc, filReg.Id, rot, northAngle);

 


Thanks 😉

0 Likes
Accepted solutions (1)
265 Views
2 Replies
Replies (2)
Message 2 of 3

Michael_Coffey_G
Contributor
Contributor

Why not just always use the Internal Origin (0,0,0)?

0 Likes
Message 3 of 3

_CraigF
Contributor
Contributor
Accepted solution

Thank you @Michael_Coffey_G , it partially helped me solve my problem !

 

Indeed, I realized that I needed to combine XYZ orig = XYZ.Zero; with activeView.Origin; to determine the translation I needed to apply.

This approach allowed me to correctly handle the differences in the origin point for "original views".

 

UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Document doc = uiDoc.Document;
View activeView = doc.ActiveView;
ProjectLocation projectLoc = doc.ActiveProjectLocation;
ProjectPosition projectPos = projectLoc.GetProjectPosition(XYZ.Zero);
double northAngle = projectPos.Angle;
XYZ orig = XYZ.Zero;
XYZ viewOrig = activeView.Origin;
XYZ trans = new XYZ(viewOrig.X, viewOrig.Y, 0);
XYZ transVector = new XYZ(trans.X, trans.Y, 0);
Line rot = Line.CreateUnbound(orig, XYZ.BasisZ);
XYZ rotTrans = RotateVectorByAngle(transVector, northAngle);
ElementTransformUtils.RotateElement(doc, filReg.Id, rot, northAngle);
ElementTransformUtils.MoveElement(doc, filReg.Id, -rotTrans);

 

 

 

 

 

 

0 Likes