DigiPara Liftdesigner LDX API
Loading...
Searching...
No Matches
WorldToPaper: Align view frames in X direction

API method: ILDXSheetFrame5.CalculateWorldToPaper

Treename: Sheets.LdvSheet1.LdvFrame3.

 ' from Samples/Src/LDXAPIExamples/Example_LDXSheetFrame.vb

    <APIHelpAttribute(APIHelpModes.FireCalcModel Or APIHelpModes.LoadLD3File, {APIHelpModes.InputParaLDXDoc}, "Sheets.LdvSheet1.LdvFrame3.", "LDXSheetFrame~CalculateWorldToPaper", "WorldToPaper: Align view frames in X direction")>
 Public Shared Sub WorldToPaper(ByRef ldxDocument As DigiPara.LDX.LDXDocument)

     If ldxDocument Is Nothing Then
         MsgBox("Please load a document.")
         Exit Sub
     End If

     Dim ldxFrame1 As DigiPara.LDX.LDXSheetFrame = ldxDocument.GetLDXObject("Sheets.LdvSheet1.LdvFrame3.").LDXType
     If ldxFrame1 Is Nothing Then
         MsgBox("Relevant sheet frame not found. Please reload the .ld3 file.")
         Exit Sub
     End If

     Dim ldxFrame2 As DigiPara.LDX.LDXSheetFrame = ldxDocument.GetLDXObject("Sheets.LdvSheet1.LdvFrame2.").LDXType
     If ldxFrame2 Is Nothing Then
         MsgBox("Relevant sheet frame not found. Please reload the .ld3 file.")
         Exit Sub
     End If

     Dim ldxShaft As DigiPara.LDX.LDXShaft = ldxDocument.Shafts(0)

     ' and orientation in the direction we want to align them; we make one a plan view
     ldxFrame1.Reset(DigiPara.LDX.SheetFrameViewType.shfvtPlan,
                          DigiPara.LDX.SheetFrameViewDirections.shfvdToFromTop,
                          DigiPara.LDX.SheetFrameResetOptions.shfrrstInitText)
     ' and the other a front view. Alignment will be along X
     ldxFrame2.Reset(DigiPara.LDX.SheetFrameViewType.shfvtVertical,
                          DigiPara.LDX.SheetFrameViewDirections.shfvdToRearWall,
                          DigiPara.LDX.SheetFrameResetOptions.shfrrstInitText)
     ' alignment can only work if the two frames have the same scale
     ldxFrame2.Scale = ldxFrame1.Scale

     ' the car needs to be at the bottom for this alignment to work well
     Dim newCarMode As DigiPara.LDX.CarModes = (ldxShaft.Car.CarMode Or DigiPara.LDX.CarModes.carmPositionBottom) And Not DigiPara.LDX.CarModes.carmPositionTop
     If ldxShaft.Car.CarMode <> newCarMode Then
         ldxShaft.Car.CarMode = newCarMode
         ' only on change, we need to call CalculateModel, the frame changes take effect without
         ldxDocument.CalculateModel(DigiPara.LDX.CalculateModelModes.rcmCalcAndReport Or DigiPara.LDX.CalculateModelModes.rcmKeepCleanFrames)
     End If

     Dim carOriginPaperSpace1 As VBHideVec = New VBHideVec
     ' get car position in world space
     carOriginPaperSpace1.Set(ldxShaft.Car.Comp.WorldMatrix.R)
     ' move it to paper space
     ldxFrame1.CalculateWorldToPaper(carOriginPaperSpace1)

     ' get car position in world space (one line, alternative to the above)
     Dim carOriginPaperSpace2 As VBHideVec = New VBHideVec(ldxShaft.Car.Comp.WorldMatrix.R)
     ' move it to paper space
     ldxFrame2.CalculateWorldToPaper(carOriginPaperSpace2)

     ' the difference in car positions on the sheet
     Dim xOffset = carOriginPaperSpace1.X - carOriginPaperSpace2.X
     Dim yOffset = carOriginPaperSpace1.Y - carOriginPaperSpace2.Y

     ' to align frame2 to frame1, we simply have to add x/yOffset to its X0 and Y0
     ldxFrame2.X0 += xOffset
     ldxFrame2.Y0 += yOffset

     ' now they would be on top of each other, move the second frame up by
     ' roughly the first frame's height
     ldxFrame2.Y0 += ldxFrame1.Scale * ldxShaft.Room.DEPTH * 2
     ' another valid alignment choice would be to just never touch frame2.Y0 at all.
 End Sub