|
DigiPara Liftdesigner LDX API
|
API method: ILDXDocument5.GetLDXObject
2 code examples follow.
' from Samples/Src/LDXAPIExamples/Example_LDXDocument.vb
Private Shared Sub CheckPromises2(ldxObject As DigiPara.LDX.LDXObject, treeName As String, variableName As String)
Dim subObject As DigiPara.LDX.LDXObject = ldxObject.GetObjectByRelativeName(treeName)
If (IsNothing(subObject)) Then
Return
End If
Dim value = subObject.GetValue(variableName)
Dim directValue = ldxObject.GetValue(treeName + variableName)
System.Diagnostics.Debug.Assert(value = directValue)
End Sub
Private Shared Sub CheckPromises(ldxDocument As DigiPara.LDX.LDXDocument, treeName As String, variableName As String)
If Not treeName.StartsWith("Me.") And Not treeName.StartsWith("Document.") Then
If Not treeName.Contains("Parent.") And False Then
CheckPromises(ldxDocument, "Parent." + treeName, variableName)
CheckPromises(ldxDocument, treeName + "Parent.", variableName)
End If
CheckPromises(ldxDocument, "Me." + treeName, variableName)
CheckPromises(ldxDocument, "Me.Me." + treeName, variableName)
CheckPromises(ldxDocument, "Document." + treeName, variableName)
CheckPromises(ldxDocument, "Document.Document." + treeName, variableName)
CheckPromises(ldxDocument, "Document.Me." + treeName, variableName)
CheckPromises(ldxDocument, "Me.Document." + treeName, variableName)
End If
Dim ldxObject As DigiPara.LDX.LDXObject = ldxDocument.GetLDXObject(treeName)
If (IsNothing(ldxObject)) Then
System.Diagnostics.Debug.Assert(Not ldxDocument.HasObject(treeName))
Else
System.Diagnostics.Debug.Assert(ldxDocument.HasObject(treeName))
End If
Dim altObject1 = ldxDocument.Object.GetObjectByRelativeName(treeName)
System.Diagnostics.Debug.Assert(Object.ReferenceEquals(ldxObject, altObject1))
Dim altObject2 = ldxDocument.Object.GetFirstObjectByRelativeAsteriskName(treeName)
System.Diagnostics.Debug.Assert(Object.ReferenceEquals(ldxObject, altObject2))
Dim fullName As String = treeName + variableName
Dim value1 = ldxDocument.GetValue(fullName)
Dim value2 = ldxDocument.Object.GetValue(fullName)
System.Diagnostics.Debug.Assert(value1 = value2)
If IsNothing(ldxObject) Then
Return
End If
CheckPromises2(ldxDocument.Object, treeName, variableName)
CheckPromises2(ldxObject, variableName, "")
treeName.Split()
End Sub
<APIHelpAttribute(APIHelpModes.FireCalcModel Or APIHelpModes.LoadLD3File, {APIHelpModes.InputParaLDXApp}, "", "LDXDocument~GetLDXObject", "Find Objects (No visible effect, code and checks only)")>
Public Shared Sub FindObjects(ByRef ldxApplication As DigiPara.LDX.LDXApplication)
Dim ldxDocument = ldxApplication.ActiveDocument
If ldxDocument Is Nothing Then
MsgBox("Active document not found!")
Exit Sub
End If
' from the document level, you can fetch objects by their treename
Dim ldxCar As DigiPara.LDX.LDXObject = ldxDocument.GetLDXObject("Shaft0.Car.")
System.Diagnostics.Debug.Assert(ldxCar.ObjectId = DigiPara.LDX.ObjectId.idCar)
' the alternative function GetFirstLDXObjectByAsterisk supports pattern matching; a * ONLY substitutes trailing indices.
Dim ldxShaft As DigiPara.LDX.LDXObject = ldxDocument.GetFirstLDXObjectByAsterisk("Shaft*.")
System.Diagnostics.Debug.Assert(ldxShaft.ObjectId = DigiPara.LDX.ObjectId.idShaft)
Dim ldxSheetFrame As DigiPara.LDX.LDXObject = ldxDocument.GetFirstLDXObjectByAsterisk("Sheets.LdvSheet*.LdvFrame*.")
System.Diagnostics.Debug.Assert(ldxSheetFrame.ObjectId = DigiPara.LDX.ObjectId.idSheetFrame)
Dim ldxLandingDoor As DigiPara.LDX.LDXObject = ldxDocument.GetFirstLDXObjectByAsterisk("Shaft*.Entries*.E*.ShaftDoor.")
System.Diagnostics.Debug.Assert(ldxLandingDoor.ObjectId = DigiPara.LDX.ObjectId.idLandingDoor)
' from any object, you can fetch objects by their relative name
Dim ldxCarFrame As DigiPara.LDX.LDXObject = ldxCar.Object.GetObjectByRelativeName("Frame.")
System.Diagnostics.Debug.Assert(ldxCarFrame.ObjectId = DigiPara.LDX.ObjectId.idCarFrame)
' some relative paths have special meaning; they can be arbitrarily part of relative names,
' but only really make sense in the beginning.
'"Me." just designates the called object itself:
Dim ldxCar2 As DigiPara.LDX.LDXObject = ldxCar.GetObjectByRelativeName("Me.")
System.Diagnostics.Debug.Assert(ldxCar Is ldxCar2)
' "Parent." designates the parent object:
Dim ldxShaft2 As DigiPara.LDX.LDXObject = ldxCar.GetObjectByRelativeName("Parent.")
System.Diagnostics.Debug.Assert(ldxShaft2 Is ldxShaft)
' "Shaft." designates the parent shaft, no matter how deep in the hierarchy we are:
Dim ldxShaft3 As DigiPara.LDX.LDXObject = ldxCarFrame.GetObjectByRelativeName("Shaft.")
System.Diagnostics.Debug.Assert(ldxShaft3 Is ldxShaft)
' During some processes, if there is no parent shaft, "Shaft." also refers to the currently processed shaft.
' "LdvFrame." and "LdvSheet." refer to the parent sheet and frame:
Dim ldxSheetFrame2 As DigiPara.LDX.LDXObject = ldxSheetFrame.GetObjectByRelativeName("LdvFrame.") ' in this case, the frame returns itself
System.Diagnostics.Debug.Assert(ldxSheetFrame2 Is ldxSheetFrame)
Dim ldxSheet As DigiPara.LDX.LDXObject = ldxSheetFrame.GetObjectByRelativeName("LdvSheet.") ' in this case, the frame returns itself
System.Diagnostics.Debug.Assert(ldxSheet.ObjectId = DigiPara.LDX.ObjectId.idSheet)
' those, too, during processes such as dynamic sheet loading, can refer to the currently processed sheet and frame.
' "FloorLevel." returns the logically most relevant floor level to an object.
' For children of a floor level, this will always be the parent floor level.
' For children of an entry, this will always be the floor level the entry is on.
' For other objects, the value is unspecified and should not be relied upon.
Dim ldxFloorLevel1 As DigiPara.LDX.LDXObject = ldxLandingDoor.GetObjectByRelativeName("FloorLevel.")
System.Diagnostics.Debug.Assert(ldxFloorLevel1.ObjectId = DigiPara.LDX.ObjectId.idFloorLevel)
Dim ldxFloorLevel2 As DigiPara.LDX.LDXObject = ldxShaft.GetObjectByRelativeName("FloorLevel.")
System.Diagnostics.Debug.Assert(ldxFloorLevel2 Is ldxFloorLevel1)
Dim ldxFloorLevel3 As DigiPara.LDX.LDXObject = ldxCar.GetObjectByRelativeName("FloorLevel.")
System.Diagnostics.Debug.Assert(ldxFloorLevel3.ObjectId = DigiPara.LDX.ObjectId.idFloorLevel)
' "NearestFloorLevel." does not care about the logical hierarchy and returns the floor level the object is closest to (its base point needs to be higher than the floor level lower concrete edge)
Dim ldxFloorLevel4 As DigiPara.LDX.LDXObject = ldxLandingDoor.GetObjectByRelativeName("NearestFloorLevel.")
System.Diagnostics.Debug.Assert(ldxFloorLevel4 Is ldxFloorLevel1)
Dim ldxFloorLevel5 As DigiPara.LDX.LDXObject = ldxCar.GetObjectByRelativeName("NearestFloorLevel.")
System.Diagnostics.Debug.Assert(ldxFloorLevel5.ObjectId = DigiPara.LDX.ObjectId.idFloorLevel)
' Of course, a floor level should always return itself
Dim ldxFloorLevel6 As DigiPara.LDX.LDXObject = ldxFloorLevel5.GetObjectByRelativeName("FloorLevel.")
System.Diagnostics.Debug.Assert(ldxFloorLevel6 Is ldxFloorLevel5)
Dim ldxFloorLevel7 As DigiPara.LDX.LDXObject = ldxFloorLevel5.GetObjectByRelativeName("NearestFloorLevel.")
System.Diagnostics.Debug.Assert(ldxFloorLevel7 Is ldxFloorLevel5)
' For any object in an array (such as floor levels), "Next." and "Previous." can be used to iterate in the array
' (Not really the best method performance wise, mind, but useful for dynamic dimensions where string lookup is the only
' available way to look around)
Dim ldxFloorLevel8 As DigiPara.LDX.LDXObject = ldxFloorLevel5.GetObjectByRelativeName("Next.")
System.Diagnostics.Debug.Assert(ldxFloorLevel8 IsNot Nothing)
Dim ldxFloorLevel9 As DigiPara.LDX.LDXObject = ldxFloorLevel8.GetObjectByRelativeName("Previous.")
System.Diagnostics.Debug.Assert(ldxFloorLevel9 IsNot Nothing)
System.Diagnostics.Debug.Assert(ldxFloorLevel9 Is ldxFloorLevel5)
' Tests the various methods of finding objects and values in the document
CheckPromises(ldxDocument, "Shaft0.Car.", "CW")
CheckPromises(ldxDocument, "", "Shaft0.Car.CW")
CheckPromises(ldxDocument, "Shaft0.Car.", "Me.DisplayName")
CheckPromises(ldxDocument, "Shaft0.Car.", "Me.DisplayValue")
CheckPromises(ldxDocument, "Shaft0.Car.", "DisplayName")
CheckPromises(ldxDocument, "Shaft0.Car.", "DisplayValue")
' Test v4 replace
System.Diagnostics.Debug.Assert(Not IsNothing(ldxDocument.GetLDXObject("Shaft0.MachineryRoom.VentilationWindow")))
End Sub
' from Samples/Src/LDXAPIExamples/Example_LDXDocument.vb
<APIHelpAttribute(APIHelpModes.FireCalcModel Or APIHelpModes.LoadLD3File, {APIHelpModes.InputParaLDXApp}, "", "LDXDocument~GetLDXObject", "Advanced object patterns (No visible effect, code and checks only)")>
Public Shared Sub AdvancedPatterns(ByRef ldxApplication As DigiPara.LDX.LDXApplication)
Dim ldxDocument = ldxApplication.ActiveDocument
If ldxDocument Is Nothing Then
MsgBox("Active document not found!")
Exit Sub
End If
' The designated document for this sample has three shafts, one in bank 1, two in bank 2.
' The filters apart from Bank* and *Unit work on other arrays of objects; rail brackets, lamps, guides, entries, etc.
Dim ldxShaft As DigiPara.LDX.LDXObject
' After a *, designating pattern matching, additional filters can be passed in curly braces.
' The first filter would be "Last", which will only match the last element, in the case of shafts, the last element of a bank
ldxShaft = ldxDocument.GetFirstLDXObjectByAsterisk("Shaft*{Last}.")
System.Diagnostics.Debug.Assert("Shaft0." = ldxShaft.TreeName)
' Likewise, "First", matches the first element (not really useful in combination with GetFirstLDXObjectByAsterisk, but with LDXObject.GetObjectsByRelativeAsteriskName, or in overwrite patterns)
ldxShaft = ldxDocument.GetFirstLDXObjectByAsterisk("Shaft*{First}.")
System.Diagnostics.Debug.Assert("Shaft0." = ldxShaft.TreeName)
' For shafts, "Bank1" and "Bank2" only match shafts of the respective bank
ldxShaft = ldxDocument.GetFirstLDXObjectByAsterisk("Shaft*{Bank2}.")
System.Diagnostics.Debug.Assert("Shaft1." = ldxShaft.TreeName)
' Different flags can be combined; the order does not matter
ldxShaft = ldxDocument.GetFirstLDXObjectByAsterisk("Shaft*{Bank2, Last}.")
System.Diagnostics.Debug.Assert("Shaft2." = ldxShaft.TreeName)
ldxShaft = ldxDocument.GetFirstLDXObjectByAsterisk("Shaft*{Bank1, Last}.")
System.Diagnostics.Debug.Assert("Shaft0." = ldxShaft.TreeName)
' you can also simply add an index (first object is 0)
ldxShaft = ldxDocument.GetFirstLDXObjectByAsterisk("Shaft*{Bank2, 0}.")
System.Diagnostics.Debug.Assert("Shaft1." = ldxShaft.TreeName)
ldxShaft = ldxDocument.GetFirstLDXObjectByAsterisk("Shaft*{Bank2, 1}.")
System.Diagnostics.Debug.Assert("Shaft2." = ldxShaft.TreeName)
' With "IndexFromEnd", the end gets to be the reference point for indices. Because of weird programmer logic, the last element then is referenced as -1, the next-to-last as -2, and so on.
ldxShaft = ldxDocument.GetFirstLDXObjectByAsterisk("Shaft*{Bank2, IndexFromEnd, -1}.")
System.Diagnostics.Debug.Assert("Shaft2." = ldxShaft.TreeName)
ldxShaft = ldxDocument.GetFirstLDXObjectByAsterisk("Shaft*{Bank2, IndexFromEnd, -2}.")
System.Diagnostics.Debug.Assert("Shaft1." = ldxShaft.TreeName)
' With "Solitary", only elements that are one of their kind are matched.
' Conversely, "OfMany" only matches elements that are in a group of two or more.
ldxShaft = ldxDocument.GetFirstLDXObjectByAsterisk("Shaft*{Bank1, Solitary}.")
System.Diagnostics.Debug.Assert("Shaft0." = ldxShaft.TreeName)
ldxShaft = ldxDocument.GetFirstLDXObjectByAsterisk("Shaft*{Bank1, OfMany}.")
System.Diagnostics.Debug.Assert(ldxShaft Is Nothing)
ldxShaft = ldxDocument.GetFirstLDXObjectByAsterisk("Shaft*{Bank2, Solitary}.")
System.Diagnostics.Debug.Assert(ldxShaft Is Nothing)
ldxShaft = ldxDocument.GetFirstLDXObjectByAsterisk("Shaft*{Bank2, OfMany}.")
System.Diagnostics.Debug.Assert("Shaft1." = ldxShaft.TreeName)
' only relevant for special, rare projects (not in this sample): With the smTwinShaft, a shaft can be marked to share space with the previous shaft,
' for the purpose of making the two shafts' cars move independently in the same physical shaft. In that case, the filter "UpperUnit" only
' matches the shafts with the smTwinShaft flag, while "LowerUnit" only matches the shafts directly before one with smTwinShaft.
' Here, both filters match nothing.
ldxShaft = ldxDocument.GetFirstLDXObjectByAsterisk("Shaft*{UpperUnit}.")
System.Diagnostics.Debug.Assert(ldxShaft Is Nothing)
ldxShaft = ldxDocument.GetFirstLDXObjectByAsterisk("Shaft*{LowerUnit}.")
System.Diagnostics.Debug.Assert(ldxShaft Is Nothing)
End Sub