Get and Set 3D Solid Position and Path

ahmedshawkey95
Advocate

Get and Set 3D Solid Position and Path

ahmedshawkey95
Advocate
Advocate

Greetings,
I'm trying to create a plugin that automates the insertion of 3D steel bent bars based on user-defined variable dimensions but I couldn't find any exposed methods in the .NET API that can get and set the 3D Solid Geometry properties (such as radius, position, and extrusion path segments). Is there any way to complete the following code? Is there a better way to do this?

ahmedshawkey95_1-1639325225288.png

 

 

 

 [CommandMethod("CustomBar", CommandFlags.Modal)]
        public void InsertCustomBar()
        {                
          //OverrulingManager.EnableOverruling();
           Document doc = Application.DocumentManager.MdiActiveDocument;
           var db = doc.Database;
           var element = new ElementBL();//ElementBL is a local class contains user defined values
                using (var tr = db.TransactionManager.StartTransaction())
                {
                    Solid3d bar = new Solid3d();
                    bar.RecordHistory = true;
                    bar.CreateFrustum(element.Height, element.Diameter * .5, element.Diameter * .5, element.Diameter * .5);
                    var currentSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
bar.TransformBy(Matrix3d.Displacement(element.InitialPosition.ToAcadPoint()- Point3d.Origin);
                    currentSpace.AppendEntity(bar);
                    tr.AddNewlyCreatedDBObject(bar, true);

                    bar.SetXDataAsGuid("Dummy Text To Enable Overrulling");
                    bar.SetElementInXDictionaryXrecord(element);//User can modify this element properties from a custom propertygrid and it will be stored as XRecord in the 3D Solid
                    tr.Commit();
                }
      }


 public class Solid3DDrawingOverrule : DrawableOverrule
    {
        public Solid3DDrawingOverrule()
        {
            SetXDataFilter(XDataExtensions.RegAppName);
        }
        public override bool WorldDraw(Drawable drawable, WorldDraw wd)
        {
            var bar = (AcDb.Solid3d)drawable;
           
            using (var tr = bar.Database.TransactionManager.StartTransaction())
            {
                ElementBL element = bar.GetElementFromXDictionaryXrecord();
                if (element == null)
                    return base.WorldDraw(drawable, wd);
               //Point3d oldPosition = bar.GetPosition();//TODO: How to get current 3D Solid position
                bar.CreateFrustum(element.Height, element.Diameter * .5, element.Diameter * .5, element.Diameter * .5);//Modified successfully but at origin(0,0,0)
                //bar.SetPosition(oldPosition);//TODO: How to set 3D Solid position
                //bar.SetExtrusionPath(element.GetExtrusionPolyline());//TODO: How to set 3D Solid path
                base.WorldDraw(bar, wd);
                tr.Commit();
            }
            return true;
        }
    }

 

 

 

Reply
599 Views
4 Replies
Replies (4)

ahmedshawkey95
Advocate
Advocate

Any ideas on this?

0 Likes

marcin.sachs
Advocate
Advocate

Please see below code to get properties from Solid 3D.

public static string PropertyValueFrom3dSolid(ObjectId objectId, string PropertyName)
        {
            string result = "";

            IntPtr pUnk = Autodesk.AutoCAD.Internal.PropertyInspector.ObjectPropertyManagerPropertyUtility.GetIUnknownFromObjectId(objectId);
            if (pUnk != IntPtr.Zero)
            {
                using (Autodesk.AutoCAD.Internal.PropertyInspector.CollectionVector properties = Autodesk.AutoCAD.Internal.PropertyInspector.ObjectPropertyManagerProperties.GetProperties(objectId, false, false))
                {
                    int cnt = properties.Count();
                    if (cnt != 0)
                    {
                        using (Autodesk.AutoCAD.Internal.PropertyInspector.CategoryCollectable category = properties.Item(0) as Autodesk.AutoCAD.Internal.PropertyInspector.CategoryCollectable)
                        {
                            Autodesk.AutoCAD.Internal.PropertyInspector.CollectionVector props = category.Properties;
                            int propCount = props.Count();
                            for (int j = 0; j < propCount; j++)
                            {
                                using (Autodesk.AutoCAD.Internal.PropertyInspector.PropertyCollectable prop = props.Item(j) as Autodesk.AutoCAD.Internal.PropertyInspector.PropertyCollectable)
                                {
                                    if (prop == null)
                                        continue;
                                    object value = null;
                                    if (prop.GetValue(pUnk, ref value) && value != null)
                                    {
                                        if (prop.Name == PropertyName)
                                        {
                                            if (value.ToString() != "")
                                            {
                                                result = value.ToString();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return result;
        }

artc2
Autodesk
Autodesk
Please be aware that anything in the Autodesk.AutoCAD.Internal namespace is intended for Autodesk internal use only, so it is only tested for the internal uses it has and it can change or even be removed in any release including in updates.
0 Likes

ahmedshawkey95
Advocate
Advocate

Thanks, @marcin.sachs for your reply, it works perfectly with me and I'm able to get only the Properties' palette values but is there a way to set them? is there a way to get the extrusion path? 

0 Likes