DigiPara Liftdesigner LDX API
Loading...
Searching...
No Matches
PaperToWorld: Mark frame origin as characteristic point on the shaft

API method: ILDXSheetFrame5.CalculatePaperToWorld

 ' from Samples/Src/LDXAPIExamples/Example_LDXSheetFrame.vb

    <APIHelpAttribute(APIHelpModes.FireCalcModel Or APIHelpModes.LoadLD3File, {APIHelpModes.InputParaLDXDoc}, "", "LDXSheetFrame~CalculatePaperToWorld", "PaperToWorld: Mark frame origin as characteristic point on the shaft")>
 Public Shared Sub PaperToWorld(ByRef ldxDocument As DigiPara.LDX.LDXDocument)

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

     Dim ldxFrame As DigiPara.LDX.LDXSheetFrame = ldxDocument?.Sheets?.ActiveSheet?.ActiveSheetFrame
     If ldxFrame Is Nothing Then
         MsgBox("Please select a frame.")
         Exit Sub
     End If

     If ldxFrame.ViewType = DigiPara.LDX.SheetFrameViewType.shfvtDwg Then
         MsgBox("Please select a non-dwg frame.")
         Exit Sub
     End If

     ' create/find a characteristic point on the first shaft
     Dim ldxShaft As DigiPara.LDX.LDXShaft = ldxDocument.Shafts(0)
     If ldxShaft.Comp.ProfilePoints.Count = 0 Then
         ldxShaft.Comp.ProfilePoints.Add()
     End If
     Dim ldxPoint As DigiPara.LDX.LDXProfilePoint = ldxShaft.Comp.ProfilePoints(0)
     ldxPoint.PGP_MODE_ENUM = ldxPoint.PGP_MODE_ENUM Or DigiPara.LDX.ProfilePointModes.ppmDynamicDimensionPoint
     Dim pointPosition = ldxPoint.Comp.LocalMatrix.R ' we assume the first shaft's position is 0/0/0 and it is not rotated, so we can happily treat LocalMatix.R as world coordinates.

     ' clear frame geometry (for performance testing)
     ' frame.Comp.CalculateModel(DigiPara.LDX.CompCalculateModelModes.crvmNone)

     ' store frame origin in paper space (Z is irrelevant)
     pointPosition.X = ldxFrame.X0
     pointPosition.Y = ldxFrame.Y0

     ' transform to world space
     ldxFrame.CalculatePaperToWorld(pointPosition)

     ' to get from world space to paper space, use instead:
     ' frame.CalculateWorldToPaper(pointPosition)
     ' it can be used to determine where points in the world will land on
     ' the sheet and consequently to align two view frames so that certain
     ' geometry features overlap.

     ' in order for the point to actually stay there, we need to transfer the numbers to the points equations
     ldxPoint.SetEquation(DirectCast(DigiPara.LDX.ProfileEquationType.peqtLocalPositionX, Integer), pointPosition.X.ToString())
     ldxPoint.SetEquation(DirectCast(DigiPara.LDX.ProfileEquationType.peqtLocalPositionY, Integer), pointPosition.Y.ToString())
     ldxPoint.SetEquation(DirectCast(DigiPara.LDX.ProfileEquationType.peqtLocalPositionZ, Integer), pointPosition.Z.ToString())

     ' not required for final result: set points' global position
     ldxPoint.Comp.WorldMatrix.R = pointPosition

     ' select characteristic point; this should highlight a coordinate system
     ' just at the frame's origin.
     Try
         ldxDocument.Application.LockEvents(ldxDocument)
         ldxFrame.SelectedObjects.Clear()
         ldxFrame.SelectedObjects.Add(ldxPoint.Object.TreeName)
         ldxDocument.Sheets.ActiveSheet.UpdateSelection()
     Finally
         ' always call UnlockEvents in a Finally block
         ldxDocument.Application.UnlockEvents(ldxDocument)
     End Try
 End Sub