By Adam Nagy
There are 3 coordinate systems being used inside a drawing: Sheet, DrawingView and Model.
The Sheet and DrawingView coordinate systems are almost identical apart from their origin: they have the same axes and same scaling. The Model coordinate system is the coordinate system of the document that is being shown inside the drawing view.
The API makes it really easy to jump between the coordinate systems. There are functions like ModelToSheetSpace(), to transform a point from one coordinate system to the other. If you want to transform a direction then it's easier to use the transformation matrix, which is also provided, e.g. ModelToSheetTransform matrix, and use that to transform a vector using Vector.TransformBy(Matrix).
We can write a simple function which transforms the origin of the various coordinate systems and the model workpoint into sheet coordinate system, and draws a circle at each position. This might make it easier to see the relationship between them.
Sub DrawCircle(pt As Point2d, s As Sheet) Dim sk As DrawingSketch ' Sheet sketches are in Sheet coordinate system ' and DrawingView sketches are in DrawingView ' coordinate system If s.Sketches.count > 0 Then Set sk = s.Sketches(1) Else Set sk = s.Sketches.Add() End If If Not s.Parent.ActivatedObject Is sk Then sk.Edit End If Call sk.SketchCircles.AddByCenterRadius(pt, 1) End Sub Sub DrawCircles() Dim doc As DrawingDocument Set doc = ThisApplication.ActiveDocument Dim s As Sheet Set s = doc.ActiveSheet Dim tg As TransientGeometry Set tg = ThisApplication.TransientGeometry Dim v As DrawingView Set v = s.DrawingViews(1) ' (1) Show the origin of the sheet Call DrawCircle(tg.CreatePoint2d(), s) ' (2) Show origin of the DrawingView Call DrawCircle(v.DrawingViewToSheetSpace(tg.CreatePoint2d()), s) ' Same as 'Call DrawCircle(v.Position, s) ' (3) Show origin of Model coordinate system Call DrawCircle(v.ModelToSheetSpace(tg.CreatePoint()), s) ' (4) Show WorkPoint of model ' transformed to Sheet coordinate system Dim prt As PartDocument Set prt = v.ReferencedDocumentDescriptor.ReferencedDocument Dim wp As WorkPoint Set wp = prt.ComponentDefinition.WorkPoints("MyPoint") Call DrawCircle(v.ModelToSheetSpace(wp.Point), s) End Sub
There is also the Camera of the drawing view which is described with Model coordinates. In our case the Target is the middle of the box and Eye (the position of our eye looking at the model, described with Model coordinates) is in front of it along the (1, 1, 1) vector. Though the UpVector looks as if it's the same as the Model's Y axis, it points behind that axis and equals to (-1, 2, -1). The view direction, which points from the Eye to the Target, and the UpVector are always perpendicular.
Here is a nice post on Cameras: http://modthemachine.typepad.com/my_weblog/2013/09/working-with-cameras-part-1.html