Adding TrimPlanes to Structural Members in ACA.NET

By

Jeremy


Tammik
.

Question: How can I add TrimPlanes to structural members using ACA .NET API?

I tried the

code provided in 2012
with little success.

When I try to write to the TrimPlanes property, e.g. like this, it returns a ‘ReadOnly’” error:


member.TrimPlanes = trimPlanes

Any ideas how to fix this?

Answer: Basically, the following sample code skeleton should work:


  trimPlanes= owner.TrimPlanes;
 
  plane1 = new TrimPlane();
  ...
  trimPlanes.Add(plane1);

Here is a complete command implementation sample:



.cf { font-family: Consolas; font-size: 10pt; color: black; background: white; }
.cl { margin: 0px; }
.cb1 { color: #a31515; }
.cb2 { color: blue; }
.cb3 { color: #2b91af; }
.cb4 { color: green; }


    <CommandMethod("testmemberTrim")> _
    Public Sub 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))
        ' 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.SubSetDatabaseDefaults(db)
        tp1.SetToStandard(db)
        tp1.End = TrimPlaneFrom.Start
        tp1.Plane = New Plane(ptOrigin, vec.GetNormal())
        member.TrimPlanes.Add(tp1)
        ' create another trim plane at the end
        Dim tp2 As TrimPlane = New TrimPlane()
        tp2.SubSetDatabaseDefaults(db)
        tp2.SetToStandard(db)
        tp2.End = TrimPlaneFrom.End
        tp2.Plane = New Plane(ptOrigin, vec.GetNormal())
        member.TrimPlanes.Add(tp2)
        Dim blkTbl As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead)
        Dim ms As BlockTableRecord = trans.GetObject(blkTbl(BlockTableRecord.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 Sub

Column trim planes


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading