Jump to content

Problem with Solid3d cylinder placement after CreateFrustum + TransformBy (AutoCAD .NET / C#)


Recommended Posts

Posted (edited)

I’m working on an AutoCAD .NET (C#) command that creates two Solid3d cylinders (one in +Z and one in –Z direction) starting from a selected point on an insulator line. Each cylinder is created with CreateFrustum, then moved into place using TransformBy(Matrix3d.Displacement) and optionally rotated around the point.

However, I’ve run into a strange issue: sometimes the cylinders appear exactly in the correct place, but sometimes they shift several meters away from the point. In some cases both cylinders stack on each other, even though they should be separated along the Z-axis. The LIST command occasionally shows bounding boxes like:

X = [-3500, 3500]
Y = [-3500, 3500]
Z = [-5000, 5000]

which means the cylinder was never displaced at all, even though I definitely applied the transform.

Here is the code that draws the cylinders:

private void DrawClearanceCylinders(Database db, Editor ed,
                                    IEnumerable<Point3d> centers,
                                    double radius, double angleDeg)
{
    if (centers == null) return;

    double h = CYL_LENGTH;
    double angRad = angleDeg * Math.PI / 180.0;

    using (var tr = db.TransactionManager.StartTransaction())
    {
        var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
        var btr = (BlockTableRecord)tr.GetObject(
            bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

        foreach (var c in centers)
        {
            Solid3d cylUp = new Solid3d();
            cylUp.SetDatabaseDefaults();
            cylUp.CreateFrustum(h, radius, radius, radius);
            cylUp.TransformBy(Matrix3d.Displacement(
                new Vector3d(c.X, c.Y, c.Z)));

            if (Math.Abs(angleDeg) > 1e-6)
                cylUp.TransformBy(Matrix3d.Rotation(angRad, Vector3d.XAxis, c));

            btr.AppendEntity(cylUp);
            tr.AddNewlyCreatedDBObject(cylUp, true);

            Solid3d cylDown = new Solid3d();
            cylDown.SetDatabaseDefaults();
            cylDown.CreateFrustum(h, radius, radius, radius);
            cylDown.TransformBy(Matrix3d.Displacement(
                new Vector3d(c.X, c.Y, c.Z - h)));

            if (Math.Abs(angleDeg) > 1e-6)
                cylDown.TransformBy(Matrix3d.Rotation(angRad, Vector3d.XAxis, c));

            btr.AppendEntity(cylDown);
            tr.AddNewlyCreatedDBObject(cylDown, true);
        }

        tr.Commit();
    }
}

The logic seems correct: create → displace → rotate → add to model space. But the result is inconsistent, and sometimes the displacement appears to be ignored. I’m trying to understand whether:

CreateFrustum has an internal origin/transform I’m not accounting for

the rotation around point c is interfering with the placement

Solid3d requires a different transform order

or if there’s a known issue with Solid3d placement after creation

If anyone has experience with placing Solid3d cylinders precisely at a specific point, or knows what could cause the transforms to behave inconsistently, I’d really appreciate your insight.

 

image.thumb.png.b924228783090b258c98aa6b0c09773d.png

 

Command: LIST
6 found
                  3DSOLID   Layer: "clerance_zone"
                            Space: Model space
                   Color: 4 (cyan)    Linetype: "CONTINUOUS"
                   Handle = 1000070
         History = None
    Show History = No
   Bounding Box: Lower Bound X = 16294.5100, Y = 28025.7321, Z = -20484.5100
                 Upper Bound X = 24294.5100, Y = 36025.7321, Z = -10484.5100
                  3DSOLID   Layer: "clerance_zone"
                            Space: Model space
                   Color: 4 (cyan)    Linetype: "CONTINUOUS"
                   Handle = 100006f
         History = None
    Show History = No
   Bounding Box: Lower Bound X = 16294.5100, Y = 28025.7321, Z = -10484.5100
                 Upper Bound X = 24294.5100, Y = 36025.7321, Z = -484.5100
                  3DSOLID   Layer: "clerance_zone"
                            Space: Model space
Press ENTER to continue:
                   Color: 4 (cyan)    Linetype: "CONTINUOUS"
                   Handle = 100006e
         History = None
    Show History = No
   Bounding Box: Lower Bound X = 1484.5100, Y = 32991.0000, Z = -20484.5100
                 Upper Bound X = 9484.5100, Y = 40991.0000, Z = -10484.5100
                  3DSOLID   Layer: "clerance_zone"
                            Space: Model space
                   Color: 4 (cyan)    Linetype: "CONTINUOUS"
                   Handle = 100006d
         History = None
    Show History = No
   Bounding Box: Lower Bound X = 1484.5100, Y = 32991.0000, Z = -10484.5100
                 Upper Bound X = 9484.5100, Y = 40991.0000, Z = -484.5100
                  3DSOLID   Layer: "clerance_zone"
                            Space: Model space
                   Color: 4 (cyan)    Linetype: "CONTINUOUS"
                   Handle = 100006c
         History = None
    Show History = No

 

Thanks!

Edited by DeEng
I forgat the objects point

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...