How can we add TrimPlanes to Structural members using ACA .NET API?
The workflow for creating TrimPlanes and adding them to a Structural member is quite straightforward. The first step is to create an instance of TrimPlane object and assigning the End and Plane property. The code snippet included below creates a TrimPlane for the Start and End point of a column and eventually, sets the newly created TrimPlanes using the member.TrimPlanes property by passing in the collection of the TrimPlanes.
Imports System
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.Aec.DatabaseServices
Imports Autodesk.Aec.PropertyData.DatabaseServices
Imports Autodesk.Aec.Structural.DatabaseServices
Public Class Class1
<CommandMethod("testmemberTrim")> _
Public Function testmemberTrim()
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = db.TransactionManager
Dim trans As Transaction = tm.StartTransaction()
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Try
Dim member As Member = New Member()
member.MemberType = MemberType.Column
member.SetDatabaseDefaults(db)
member.SetToStandard(db)
' Set the start and end point of Member in WCS
member.Set(New Point3d(0.0, 0.0, 0.0), New Point3d(5000.0, 0.0, 0.0))
'either get the existing trim planes,
'Autodesk.Aec.DatabaseServices.ImpObjectCollection trimPlanes = member.TrimPlanes;
'or create a new collection
Dim trimPlanes As Autodesk.Aec.DatabaseServices.ImpObjectCollection = New Autodesk.Aec.DatabaseServices.ImpObjectCollection()
' create a trim plane at the start
Dim ptOrigin As Point3d = New Point3d(1.0, 1.0, 1.0)
Dim vec As Vector3d = New Vector3d(1, 0, 0)
Dim tp1 As TrimPlane = New TrimPlane()
tp1.End = TrimPlaneFrom.Start
tp1.Plane = New Plane(ptOrigin, vec.GetNormal())
trimPlanes.Add(tp1)
' create another trim plane at the end
Dim tp2 As TrimPlane = New TrimPlane()
tp2.End = TrimPlaneFrom.End
tp2.Plane = New Plane(ptOrigin, vec.GetNormal())
trimPlanes.Add(tp2)
' replaces the collection of trim planes on the member
member.TrimPlanes = trimPlanes
Dim blkTbl As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead)
Dim ms As BlockTableRecord = trans.GetObject(blkTbl(ms.ModelSpace), OpenMode.ForWrite)
ms.AppendEntity(member)
trans.AddNewlyCreatedDBObject(member, True)
trans.Commit()
Catch
MsgBox("\nMember creation failed")
trans.Abort()
Finally
MsgBox("\nMember created!")
trans.Dispose()
End Try
End Function
End Class