Below is a sample command to add a body modifier to a wall. To test this, draw a wall and a mass element intersecting each other. Then, pick a wall and a mass element.
<CommandMethod(
"MyTest", "AddWallBodyModifier", CommandFlags.Modal)> _
Public Sub AddWallBodyModifier()
' Get the necessary helper objects up front
Dim db As Database =
HostApplicationServices.WorkingDatabase
Dim tm As TransactionManager = db.TransactionManager
Dim tr As Transaction = tm.StartTransaction()
Dim ed As Editor =
Application.DocumentManager.MdiActiveDocument.Editor
' (1) Select a wall
Dim selOptWall As New PromptEntityOptions(
"Select a wall to add a modifier")
selOptWall.SetRejectMessage("Not a Wall")
selOptWall.AddAllowedClass(GetType(Wall), True)
Dim selResWall As PromptEntityResult = ed.GetEntity(selOptWall)
If selResWall.Status <> PromptStatus.OK Then
Exit Sub
End If
' (2) Select a mass element
Dim selOptMass As New PromptEntityOptions(
"Select a mass element to add as a modifier")
selOptMass.SetRejectMessage("Not a Mass Element")
selOptMass.AddAllowedClass(GetType(MassElement), True)
Dim selResMass As PromptEntityResult = ed.GetEntity(selOptMass)
If selResMass.Status <> PromptStatus.OK Then
Exit Sub
End If
Try
' If we come to this point, we got a wall object. open it.
Dim obj As AcObject =
tr.GetObject(selResWall.ObjectId, AcDb2.OpenMode.ForWrite)
Dim pWall As Wall = CType(obj, Wall)
' And mass element. open it.
Dim objMass As AcObject =
tr.GetObject(selResMass.ObjectId, AcDb2.OpenMode.ForRead)
Dim pMass As MassElement = CType(objMass, MassElement)
' Get the wall style
Dim objStyle As AcObject =
tr.GetObject(pWall.StyleId, AcDb2.OpenMode.ForRead)
Dim pWallStyle As WallStyle = CType(objStyle, WallStyle)
' (3) Get the component id.
' For simplicity, we are hard coding to add the body to the
' first wall component. If you would like to choose a specific
' component, look for a specific component in the wall style.
Dim idComp As Short = pWallStyle.Components(0).ComponentId()
' Get the inverse of ecs. we'll need this to set the right
' location.
Dim wcsToEcs As Matrix3d = pWall.Ecs.Inverse()
' (4) Here is the main part to add a body modifier to the wall.
' Create a custom geometry body from the mass element.
Dim pBody As WallCustomGeometryBody =
New WallCustomGeometryBody
pBody.SetToStandard(db)
pBody.SetBodyFromMassElement(pMass, wcsToEcs)
pBody.Description = "body modifier added by ACA .NET"
pBody.OperationType =
WallCustomGeometryOperationType.AdditiveCutOpenings
pBody.ComponentId = idComp
' Finally add the body to the wall as a custom geometry
' component.
pWall.WallCustomGeometry.Add(pBody)
tr.Commit()
Catch ex As Exception
ed.WriteMessage(
"Error in AddWallBodyModifier: " + ex.Message + vbLf)
tr.Abort()
Finally
tr.Dispose()
End Try
End Sub