+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Forum Newbie
    Using
    AutoCAD 2012
    Join Date
    Dec 2011
    Posts
    5

    Default Set Position of AttributeReference

    Hi there,
    I´m developing a little interface for AUTCOCAD at the moment. I use Visual Studio 2010 and ObjectARX 2012 with C#. The interface should be able to edit specific blockReferences and their attributes. I´ve got two special kinds of blocks which I want to edit. Now I´ve implemented a command to move the position of one kind of the block references`attributes. For one of my two blocks this command works very well. For the other ones I cannot set a new position of the attribute references. And I don´t know why! I´ve compared several properties of the attributes but they are the same for both kind of blocks. The "lockposition" for example is "false" for both. Which property of the attribute references, block references or block should I set to change the position of the attribute references. Curiously to change the height or width of the text attributes makes no problems for both kind of blocks. So what could it be?? Or is there a simple way to set all properties of one block also to another one??

    Thanks for help!!!

    greets robert

  2. #2
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Pietari, Venäjä
    Posts
    1,687

    Default

    See these methods, just an idea sorry

    Code:
     
    attRef.AdjustAlignment(db)
     
    blockref.RecordGraphicsModified(True)
    The soul is healed by being with children. - Fyodor Dostoyevsky, novelist (1821-1881)

  3. #3
    Forum Newbie
    Using
    AutoCAD 2012
    Join Date
    Dec 2011
    Posts
    5

    Default

    Hello fixo,

    first of all, happy new year! Thanks for your answer. Unfortunately after setting the properties you mentioned the positions still remain the same. Do you have another ideas which can be the reason for this??

    greets robert

  4. #4
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Pietari, Venäjä
    Posts
    1,687

    Default

    Thanks Robert,
    Happy New Year too
    Unfortunatelly I can't 2010 release on my machine
    Just an idea, sorry, perhaps in the block table record this attribute properties:
    Lock position was set to true?

    Best wishes,

    Oleg
    The soul is healed by being with children. - Fyodor Dostoyevsky, novelist (1821-1881)

  5. #5
    Forum Newbie
    Using
    AutoCAD 2012
    Join Date
    Dec 2011
    Posts
    5

    Default Attribute Position

    Hallo Oleg,

    I came through with small steps. I've find out, that it works, when I sync the BlockReferences with the origin block.
    Now I`ve the problem, that the visible Attributes also get all the Textproperties like Textheight, width and so on... of the origin Block. But the Textproperties of the visible Attributes of every BlockReference need to remain the same independent from the origin Block.
    Do you have an idea to realize that??

    greets robert

  6. #6
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Pietari, Venäjä
    Posts
    1,687

    Default

    Hi Robert, I could not generate the same issue on my machine
    I've used this simple code written years ago:
    Code:
     
           public void ApplyAttributes(Database db, Transaction tr, BlockReference bref)
            {
                BlockTableRecord btrec = tr.GetObject(bref.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
                if (btrec.HasAttributeDefinitions)
                {
                    Autodesk.AutoCAD.DatabaseServices.AttributeCollection atcoll = bref.AttributeCollection;
                    foreach (ObjectId subid in btrec)
                    {
                        Entity ent = (Entity)subid.GetObject(OpenMode.ForRead);
                        AttributeDefinition attDef = ent as AttributeDefinition;
                        if (attDef != null)
                        {
                            AttributeReference attRef = new AttributeReference();
                            attRef.SetDatabaseDefaults();// optional or wrong maybe
                            attRef.SetAttributeFromBlock(attDef, bref.BlockTransform);
                            attRef.Position = attDef.Position.TransformBy(bref.BlockTransform);
                            attRef.Tag = attDef.Tag;
                           // you may want to swap other properties
                           // between AttributeDefinition and AttributeReference here
                            attRef.AdjustAlignment(db);
                            atcoll.AppendAttribute(attRef);
                            tr.AddNewlyCreatedDBObject(attRef, true);
                        }
                    }
                }
            }
    Try it too, perhaps it will be working for you, who knows?
    Or stay arriving of the heavy artillery
    The soul is healed by being with children. - Fyodor Dostoyevsky, novelist (1821-1881)

  7. #7
    Forum Newbie
    Using
    AutoCAD 2012
    Join Date
    Dec 2011
    Posts
    5

    Default

    Hi Oleg,

    could you please explain your code a little bit. When I integrate the method I `ve got the little problem, that all blockReferences has their Attributes twice times. So I have to delete the old ones but store the values to set them to the new ones.

    But as I say on parts I don´t know exactly what your method did.

    Thanks for help!

    greets robert

  8. #8
    Forum Newbie
    Using
    AutoCAD 2012
    Join Date
    Dec 2011
    Posts
    5

    Default

    Hi Oleg,

    it´s me again and I´ve solved the problem. The difference between the blocks were the alignment of the text attributes. If they have the default-LEFT-alingment you can simply use the "Position" property to move them. If they have other alignment in my case right, you have to set the "AlingmentPoint" property of the attribute references.
    So now my method works fine for all blocks and I´m very happy!

    Again thanks for your help and have a good time!

    greets robert

  9. #9
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Pietari, Venäjä
    Posts
    1,687

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by Boortsneggor View Post
    Hi Oleg,

    it´s me again and I´ve solved the problem. The difference between the blocks were the alignment of the text attributes. If they have the default-LEFT-alingment you can simply use the "Position" property to move them. If they have other alignment in my case right, you have to set the "AlingmentPoint" property of the attribute references.
    So now my method works fine for all blocks and I´m very happy!

    Again thanks for your help and have a good time!

    greets robert
    Hi Robert,
    Glad you've solved it by yorself
    Sorry for the belating,
    and yes, it's right way to set all properties
    for attribute references by its parent attribute definition
    one by one
    I was lazy to write them all separately
    Cheers, mate

    Oleg
    Last edited by fixo; 6th Jan 2012 at 04:37 pm. Reason: spell check
    The soul is healed by being with children. - Fyodor Dostoyevsky, novelist (1821-1881)

Similar Threads

  1. Set Z Position of all Blocks to Zero
    By harilalmn in forum AutoLISP, Visual LISP & DCL
    Replies: 24
    Last Post: 6th Sep 2011, 08:55 am
  2. sun position
    By rookie37 in forum AutoCAD 3D Modelling & Rendering
    Replies: 1
    Last Post: 22nd Nov 2009, 03:47 pm
  3. From dtext to a z-position
    By Veryname in forum AutoLISP, Visual LISP & DCL
    Replies: 11
    Last Post: 23rd Jan 2009, 07:21 pm

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts