|
DigiPara Liftdesigner LDX API
|
API method: ILDXObject5.RemoveMe
Treename: Shaft0.
' from Samples/Src/LDXAPIExamples/Example_LDXObject.vb
Private Shared Sub RemoveMeRecursive(ldxObject As DigiPara.LDX.LDXObject, objectIdsLeft As System.Collections.Generic.HashSet(Of DigiPara.LDX.ObjectId))
' collect subobjects
' this is our new iteration; it is faster than just 'in ldxObject', can be customized and the items are never null
' also, we can just keep the return value, it is a regular array that does not expire even when ldxObject gets destroyed
Dim list() As DigiPara.LDX.LDXObject = ldxObject.GetChildren(DigiPara.LDX.ObjectGetChildrenModes.ogcmNullForEmpty)
If IsNothing(list) Then ' if we use ogcmNullForEmpty, we need to check for null (but it's overall a bit faster than letting GetChildren allocate an empty array, at least here where we deal with ALL objects)
Return
End If
' depth recursion first
For Each subObject In list
RemoveMeRecursive(subObject, objectIdsLeft)
Next
' don't remove the first object of anything
If Not ldxObject.Comp Is Nothing AndAlso ldxObject.Comp.IX <= 0 Then
Return
End If
' remove current object if it is has not been removed yet
If objectIdsLeft.Contains(ldxObject.ObjectId) Then
objectIdsLeft.Remove(ldxObject.ObjectId)
' some objects need preparation in their parents. RemoveMe only works if they're set to manual management
Dim ldxParent = ldxObject.ParentObject
If ldxParent IsNot Nothing Then
Select Case ldxParent.ObjectId
Case DigiPara.LDX.ObjectId.idRailBrackets
With DirectCast(ldxParent.LDXType, DigiPara.LDX.LDXRailBrackets)
.RBL_MODE = .RBL_MODE Or DigiPara.LDX.RailBracketsModes.rbmDZManual
End With
Case DigiPara.LDX.ObjectId.idLamps
With DirectCast(ldxParent.LDXType, DigiPara.LDX.LDXLamps)
.LPL_MODE = .LPL_MODE Or DigiPara.LDX.LampsModes.lsmManually
End With
Case DigiPara.LDX.ObjectId.idGuides
With DirectCast(ldxParent.LDXType, DigiPara.LDX.LDXGuides)
.GL_MODE = .GL_MODE Or DigiPara.LDX.GuidesGLModes.glmDZManual
End With
Case DigiPara.LDX.ObjectId.idScaffoldingBoards
With DirectCast(ldxParent.LDXType, DigiPara.LDX.LDXScaffoldingBoards)
.Mode = .Mode And Not DigiPara.LDX.ScaffoldingBoardsModes.scbmNumberAutomatically
End With
End Select
End If
If (ldxObject.RemoveMe) Then
' after a successful remove, inform parent of change
If ldxParent IsNot Nothing Then
ldxParent.SendChangeNotification("", "")
End If
Else
' if RemoveMe fails, you may want to just deactivate the object instead
ldxObject.Active = False
System.Diagnostics.Debug.Assert(False, String.Format("RemoveMe of {0} failed.", ldxObject.ObjectName))
End If
End If
End Sub
<APIHelpAttribute(APIHelpModes.FireCalcModel Or APIHelpModes.LoadLD3File, {APIHelpModes.InputParaLDXDoc}, "Shaft0.", "LDXObject~RemoveMe", "Removing objects via Object.RemoveMe")>
Public Shared Sub RemoveMe(ByRef ldxDocument As DigiPara.LDX.LDXDocument)
If ldxDocument Is Nothing Then
MsgBox("Not a valid document.")
Exit Sub
End If
' this function tries to remove one of each of the objects where removal is supported.
Dim objectIdsLeft As System.Collections.Generic.HashSet(Of DigiPara.LDX.ObjectId) = New HashSet(Of DigiPara.LDX.ObjectId)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idBeam)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idUserComp)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idConnectionPoint)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idDrawingLanguageLine)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idEntry)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idFloorLevel)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idForce)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idLamp)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idForce)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idGuide)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idHole)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idWallSegment)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idLandingDoorFixingPoint)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idObjectStorageDim)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idObjectStorageText)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idProfile)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idProfilePoint)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idRailBracket)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idReportLine)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idScaffoldingBoard)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idSheetFrameOverwrite)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idSheetFrameSection)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idShaftMaterial)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idSheetFrameText)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idSheetFrame)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idSheet)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idRenderViewOverwrite)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idVisualSceneLight)
objectIdsLeft.Add(DigiPara.LDX.ObjectId.idRule)
' these two would work, too, but then we would have nothing left.
' objectIdsLeft.Add(DigiPara.LDX.ObjectId.idDocument)
' objectIdsLeft.Add(DigiPara.LDX.ObjectId.idShaft)
' recurse through data tree
RemoveMeRecursive(ldxDocument.ShaftMaterials.Object, objectIdsLeft) ' do these first, section shaft materials can't be removed
RemoveMeRecursive(ldxDocument.Object, objectIdsLeft)
RemoveMeRecursive(ldxDocument.Application.RenderView.Object, objectIdsLeft)
End Sub