.NET

Reply
Mentor
BrentBurgess1980
Posts: 161
Registered: ‎06-16-2008
Message 1 of 3 (268 Views)
Accepted Solution

Attribute Definitions in BlockJig

268 Views, 2 Replies
10-24-2012 06:18 AM

Hey all,

 

I have a tool that inserts blocks using a jig, and it inserts the block, and attributes (if in the block), but the attributes do not go into the correct position.

 

The code below is the jig that I am using.

 

public class CBlockJig : EntityJig
        {
        private Point3d pos;
        private Dictionary<string, Point3d> attPos;
        private Transaction tr;

        public CBlockJig(Transaction transaction, BlockReference br)
            : base(br)
            {
            pos = br.Position;

            tr = transaction;

            // Initialize our dictionary with the tag /
            // AttributeDefinition position

            attPos = new Dictionary<string, Point3d>();

            BlockTableRecord btr = (BlockTableRecord)tr.GetObject(br.BlockTableRecord, OpenMode.ForRead);

            if (btr.HasAttributeDefinitions)
                {
                foreach (ObjectId id in btr)
                    {
                    DBObject obj = tr.GetObject(id, OpenMode.ForRead);
                    AttributeDefinition ad = obj as AttributeDefinition;

                    if (ad != null)
                        {
                        attPos.Add(ad.Tag, ad.Position);
                        }
                    }
                }
            }

        protected override bool Update()
            {
            BlockReference br = Entity as BlockReference;

            br.Position = pos;

            if (br.AttributeCollection.Count != 0)
                {
                foreach (ObjectId id in br.AttributeCollection)
                    {
                    DBObject obj = tr.GetObject(id, OpenMode.ForRead);
                    AttributeReference ar = obj as AttributeReference;

                    // Apply block transform to att def position

                    if (ar != null)
                        {
                        ar.UpgradeOpen();
                        ar.Position = attPos[ar.Tag].TransformBy(br.BlockTransform);
                        Point3d bpos = br.Position;
                        }
                    }
                }
            return true;
            }

        protected override SamplerStatus Sampler(JigPrompts prompts)
            {
            JigPromptPointOptions opts = new JigPromptPointOptions("\nSelect insertion point: ");
            opts.BasePoint = new Point3d(0, 0, 0);
            opts.UserInputControls = UserInputControls.NoZeroResponseAccepted;

            PromptPointResult ppr = prompts.AcquirePoint(opts);

            if (pos == ppr.Value)
                {
                return SamplerStatus.NoChange;
                }

            pos = ppr.Value;

            return SamplerStatus.OK;
            }

        public PromptStatus Run()
            {
            Document doc =
              Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;

            PromptResult promptResult = ed.Drag(this);
            return promptResult.Status;
            }
        }

 The Attributes appear in the right place while dragging, but once accepted and placed, the attribute is located as if the block were inserted at 0,0.

 

Does anyone have any clue on how to fix this?

 

Thanks

Valued Mentor
gasty1001
Posts: 448
Registered: ‎04-11-2010
Message 2 of 3 (249 Views)

Re: Attribute Definitions in BlockJig

10-24-2012 11:56 AM in reply to: BrentBurgess1980
Mentor
BrentBurgess1980
Posts: 161
Registered: ‎06-16-2008
Message 3 of 3 (209 Views)

Re: Attribute Definitions in BlockJig

10-29-2012 06:57 PM in reply to: gasty1001

Thanks Gasty1001.

 

The code I was using was from Kean's site, which did the funny thing with the attribute.

 

I modified the spiderinnet1 one and it works well

 

Thanks

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community